From 0fc08f67da419a91a175baf192740092b100cbcf Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Thu, 25 Jan 2024 14:41:40 -0800 Subject: [PATCH] bump sphinx --- sphinx-ffi/Cargo.toml | 2 +- sphinx-ffi/src/auto.rs | 2 ++ sphinx-ffi/src/sphinxrs.swift | 28 +++++++++++++++++++--- sphinx-ffi/src/sphinxrs.udl | 2 +- sphinx-ffi/src/sphinxrsFFI.h | 2 +- sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt | 28 ++++++++++++++++++---- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index 03a280f..6c72605 100644 --- a/sphinx-ffi/Cargo.toml +++ b/sphinx-ffi/Cargo.toml @@ -25,7 +25,7 @@ sphinx-signer = { path = "../signer", default-features = false, features = [ "no-native", ] } sphinx-glyph = { path = "../glyph", default-features = false } -sphinx = { git = "https://github.com/stakwork/sphinx", rev = "f2a1645ecb8af117f78de9790124173aa4996774", features = [ +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "ca57734079b57a0b66c980fb5874a3ffb96d68a1", features = [ "msg", "bindings", ] } diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs index 5e2dd50..31e585d 100644 --- a/sphinx-ffi/src/auto.rs +++ b/sphinx-ffi/src/auto.rs @@ -147,6 +147,7 @@ pub fn send( my_alias: String, my_img: String, amt_msat: u64, + is_tribe: bool, ) -> Result { Ok(bindings::send( &seed, @@ -158,6 +159,7 @@ pub fn send( &my_alias, &my_img_opt(&my_img), amt_msat, + is_tribe, ) .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? .into()) diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index 337494d..683f911 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -345,6 +345,27 @@ fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { } } +fileprivate struct FfiConverterBool : FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool + + public static func lift(_ value: Int8) throws -> Bool { + return value != 0 + } + + public static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Bool, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + fileprivate struct FfiConverterString: FfiConverter { typealias SwiftType = String typealias FfiType = RustBuffer @@ -1571,7 +1592,7 @@ public func `handle`(`topic`: String, `payload`: Data, `seed`: String, `uniqueTi ) } -public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UInt8, `msgJson`: String, `state`: Data, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64) throws -> RunReturn { +public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UInt8, `msgJson`: String, `state`: Data, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64, `isTribe`: Bool = false) throws -> RunReturn { return try FfiConverterTypeRunReturn.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_send( @@ -1583,7 +1604,8 @@ public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType` FfiConverterData.lower(`state`), FfiConverterString.lower(`myAlias`), FfiConverterString.lower(`myImg`), - FfiConverterUInt64.lower(`amtMsat`),$0) + FfiConverterUInt64.lower(`amtMsat`), + FfiConverterBool.lower(`isTribe`),$0) } ) } @@ -1784,7 +1806,7 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_handle() != 58131) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_send() != 22190) { + if (uniffi_sphinxrs_checksum_func_send() != 56750) { return InitializationResult.apiChecksumMismatch } if (uniffi_sphinxrs_checksum_func_make_media_token() != 53931) { diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index 9574f98..1cc3430 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -139,7 +139,7 @@ namespace sphinxrs { [Throws=SphinxError] RunReturn handle(string topic, bytes payload, string seed, string unique_time, bytes state, string my_alias, string my_img); [Throws=SphinxError] - RunReturn send(string seed, string unique_time, string to, u8 msg_type, string msg_json, bytes state, string my_alias, string my_img, u64 amt_msat); + RunReturn send(string seed, string unique_time, string to, u8 msg_type, string msg_json, bytes state, string my_alias, string my_img, u64 amt_msat, optional boolean is_tribe = false); [Throws=SphinxError] string make_media_token(string seed, string unique_time, bytes state, string host, string muid, string to, u32 expiry); [Throws=SphinxError] diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index d88f13b..088bd47 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -135,7 +135,7 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs(RustBuffer seed, RustBuffer unique ); RustBuffer uniffi_sphinxrs_fn_func_handle(RustBuffer topic, RustBuffer payload, RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time, RustBuffer to, uint8_t msg_type, RustBuffer msg_json, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time, RustBuffer to, uint8_t msg_type, RustBuffer msg_json, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, int8_t is_tribe, RustCallStatus *_Nonnull out_status ); RustBuffer uniffi_sphinxrs_fn_func_make_media_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, RustBuffer muid, RustBuffer to, uint32_t expiry, RustCallStatus *_Nonnull out_status ); diff --git a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt index be17343..5f0a660 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -436,7 +436,7 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_handle(`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_send(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`msgType`: Byte,`msgJson`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_send(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`msgType`: Byte,`msgJson`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,`isTribe`: Byte,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_make_media_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`host`: RustBuffer.ByValue,`muid`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`expiry`: Int,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue @@ -665,7 +665,7 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_handle() != 58131.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_send() != 22190.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_send() != 56750.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_sphinxrs_checksum_func_make_media_token() != 53931.toShort()) { @@ -768,6 +768,26 @@ public object FfiConverterULong: FfiConverter { } } +public object FfiConverterBoolean: FfiConverter { + override fun lift(value: Byte): Boolean { + return value.toInt() != 0 + } + + override fun read(buf: ByteBuffer): Boolean { + return lift(buf.get()) + } + + override fun lower(value: Boolean): Byte { + return if (value) 1.toByte() else 0.toByte() + } + + override fun allocationSize(value: Boolean) = 1 + + override fun write(value: Boolean, buf: ByteBuffer) { + buf.put(lower(value)) + } +} + public object FfiConverterString: FfiConverter { // Note: we don't inherit from FfiConverterRustBuffer, because we use a // special encoding when lowering/lifting. We can use `RustBuffer.len` to @@ -2079,10 +2099,10 @@ fun `handle`(`topic`: String, `payload`: ByteArray, `seed`: String, `uniqueTime` @Throws(SphinxException::class) -fun `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UByte, `msgJson`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String, `amtMsat`: ULong): RunReturn { +fun `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UByte, `msgJson`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String, `amtMsat`: ULong, `isTribe`: Boolean = false): RunReturn { return FfiConverterTypeRunReturn.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_send(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterString.lower(`to`),FfiConverterUByte.lower(`msgType`),FfiConverterString.lower(`msgJson`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_send(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterString.lower(`to`),FfiConverterUByte.lower(`msgType`),FfiConverterString.lower(`msgJson`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),FfiConverterBoolean.lower(`isTribe`),_status) }) }