diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index d14e195..f8534c9 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 = "d70cfd194044d792409f5e44e86ea7ece3b60c36", features = [ +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "6d1c12cf971549494b0595dd08a53b9f94fceb53", features = [ "msg", "bindings", ] } diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs index d3a1527..8388225 100644 --- a/sphinx-ffi/src/auto.rs +++ b/sphinx-ffi/src/auto.rs @@ -455,6 +455,50 @@ pub fn set_push_token( ) } +pub fn fetch_msgs_batch( + seed: String, + unique_time: String, + full_state: Vec, + last_msg_idx: u64, + limit: Option, + reverse: Option, + is_restore: Option, +) -> Result { + Ok(bindings::fetch_msgs_batch( + &seed, + &unique_time, + &full_state, + last_msg_idx, + limit, + reverse, + is_restore, + ) + .map_err(|e| SphinxError::FetchMsgsFailed { r: e.to_string() })? + .into()) +} + +pub fn fetch_msgs_batch_okkey( + seed: String, + unique_time: String, + full_state: Vec, + last_msg_idx: u64, + limit: Option, + reverse: Option, + is_restore: Option, +) -> Result { + Ok(bindings::fetch_msgs_batch_okkey( + &seed, + &unique_time, + &full_state, + last_msg_idx, + limit, + reverse, + is_restore, + ) + .map_err(|e| SphinxError::FetchMsgsFailed { r: e.to_string() })? + .into()) +} + impl From for Msg { fn from(rr: bindings::Msg) -> Self { Msg { diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index 1c0c461..e0916e3 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -1248,6 +1248,27 @@ fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer { } } +fileprivate struct FfiConverterOptionBool: FfiConverterRustBuffer { + typealias SwiftType = Bool? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterBool.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterBool.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { typealias SwiftType = String? @@ -2038,6 +2059,36 @@ public func `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: Data, ) } +public func `fetchMsgsBatch`(`seed`: String, `uniqueTime`: String, `state`: Data, `lastMsgIdx`: UInt64, `limit`: UInt32?, `reverse`: Bool?, `isRestore`: Bool?) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_fetch_msgs_batch( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterUInt64.lower(`lastMsgIdx`), + FfiConverterOptionUInt32.lower(`limit`), + FfiConverterOptionBool.lower(`reverse`), + FfiConverterOptionBool.lower(`isRestore`),$0) +} + ) +} + +public func `fetchMsgsBatchOkkey`(`seed`: String, `uniqueTime`: String, `state`: Data, `lastMsgIdx`: UInt64, `limit`: UInt32?, `reverse`: Bool?, `isRestore`: Bool?) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterUInt64.lower(`lastMsgIdx`), + FfiConverterOptionUInt32.lower(`limit`), + FfiConverterOptionBool.lower(`reverse`), + FfiConverterOptionBool.lower(`isRestore`),$0) +} + ) +} + private enum InitializationResult { case ok case contractVersionMismatch @@ -2221,6 +2272,12 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_set_push_token() != 7668) { return InitializationResult.apiChecksumMismatch } + if (uniffi_sphinxrs_checksum_func_fetch_msgs_batch() != 65179) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey() != 11004) { + return InitializationResult.apiChecksumMismatch + } return InitializationResult.ok } diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index 34fe190..db43bff 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -191,4 +191,8 @@ namespace sphinxrs { RunReturn get_mutes(string seed, string unique_time, bytes state); [Throws=SphinxError] RunReturn set_push_token(string seed, string unique_time, bytes state, string push_token); + [Throws=SphinxError] + RunReturn fetch_msgs_batch(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit, boolean? reverse, boolean? is_restore); + [Throws=SphinxError] + RunReturn fetch_msgs_batch_okkey(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit, boolean? reverse, boolean? is_restore); }; \ No newline at end of file diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index c83e25c..5d9df1e 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -175,6 +175,10 @@ RustBuffer uniffi_sphinxrs_fn_func_get_mutes(RustBuffer seed, RustBuffer unique_ ); RustBuffer uniffi_sphinxrs_fn_func_set_push_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer push_token, RustCallStatus *_Nonnull out_status ); +RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs_batch(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t last_msg_idx, RustBuffer limit, RustBuffer reverse, RustBuffer is_restore, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t last_msg_idx, RustBuffer limit, RustBuffer reverse, RustBuffer is_restore, RustCallStatus *_Nonnull out_status +); RustBuffer ffi_sphinxrs_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status ); RustBuffer ffi_sphinxrs_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status @@ -350,6 +354,12 @@ uint16_t uniffi_sphinxrs_checksum_func_get_mutes(void ); uint16_t uniffi_sphinxrs_checksum_func_set_push_token(void +); +uint16_t uniffi_sphinxrs_checksum_func_fetch_msgs_batch(void + +); +uint16_t uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey(void + ); uint32_t ffi_sphinxrs_uniffi_contract_version(void diff --git a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt index 13776a7..5074502 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -476,6 +476,10 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_set_push_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pushToken`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_fetch_msgs_batch(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,`isRestore`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,`isRestore`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue fun ffi_sphinxrs_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun ffi_sphinxrs_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus, @@ -596,6 +600,10 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_sphinxrs_checksum_func_set_push_token( ): Short + fun uniffi_sphinxrs_checksum_func_fetch_msgs_batch( + ): Short + fun uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey( + ): Short fun ffi_sphinxrs_uniffi_contract_version( ): Int @@ -781,6 +789,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_set_push_token() != 7668.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_sphinxrs_checksum_func_fetch_msgs_batch() != 65179.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_fetch_msgs_batch_okkey() != 11004.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } } // Public interface members begin here. @@ -1895,6 +1909,35 @@ public object FfiConverterOptionalULong: FfiConverterRustBuffer { +public object FfiConverterOptionalBoolean: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): Boolean? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterBoolean.read(buf) + } + + override fun allocationSize(value: Boolean?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterBoolean.allocationSize(value) + } + } + + override fun write(value: Boolean?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterBoolean.write(value, buf) + } + } +} + + + + public object FfiConverterOptionalString: FfiConverterRustBuffer { override fun read(buf: ByteBuffer): String? { if (buf.get().toInt() == 0) { @@ -2527,4 +2570,22 @@ fun `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pu }) } +@Throws(SphinxException::class) + +fun `fetchMsgsBatch`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `lastMsgIdx`: ULong, `limit`: UInt?, `reverse`: Boolean?, `isRestore`: Boolean?): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_fetch_msgs_batch(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterULong.lower(`lastMsgIdx`),FfiConverterOptionalUInt.lower(`limit`),FfiConverterOptionalBoolean.lower(`reverse`),FfiConverterOptionalBoolean.lower(`isRestore`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `fetchMsgsBatchOkkey`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `lastMsgIdx`: ULong, `limit`: UInt?, `reverse`: Boolean?, `isRestore`: Boolean?): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_fetch_msgs_batch_okkey(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterULong.lower(`lastMsgIdx`),FfiConverterOptionalUInt.lower(`limit`),FfiConverterOptionalBoolean.lower(`reverse`),FfiConverterOptionalBoolean.lower(`isRestore`),_status) +}) +} +