From 61d0edf1bab72c648cf3ef1ebe046502676c5cb2 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Thu, 6 Jun 2024 19:33:42 -0700 Subject: [PATCH] delete bindings --- sphinx-ffi/Cargo.toml | 2 +- sphinx-ffi/src/auto.rs | 16 +++++ sphinx-ffi/src/sphinxrs.swift | 71 +++++++++++++++++++- sphinx-ffi/src/sphinxrs.udl | 3 + sphinx-ffi/src/sphinxrsFFI.h | 5 ++ sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt | 78 +++++++++++++++++++++- 6 files changed, 170 insertions(+), 5 deletions(-) diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index 142d658..49995d4 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 = "70ba0bd885818b2313dad13aedda8de941c2aba7", features = [ +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "0d40771c9a5efcdbd7fe9357bfdc77a44e8ade0a", features = [ "msg", "bindings", ] } diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs index 5bf98c9..36ef2ac 100644 --- a/sphinx-ffi/src/auto.rs +++ b/sphinx-ffi/src/auto.rs @@ -55,6 +55,7 @@ pub struct RunReturn { pub payments: Option, pub payments_total: Option, pub tags: Option, + pub deleted_msgs: Option, } pub fn set_network(net: String) -> Result { @@ -677,6 +678,20 @@ pub fn get_tags( ) } +pub fn delete_msgs( + seed: String, + unique_time: String, + full_state: Vec, + pubkey: Option, + msg_idxs: Option>, +) -> Result { + Ok( + bindings::delete_msgs(&seed, &unique_time, &full_state, pubkey, msg_idxs) + .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? + .into(), + ) +} + impl From for Msg { fn from(rr: bindings::Msg) -> Self { Msg { @@ -740,6 +755,7 @@ impl From for RunReturn { payments: rr.payments, payments_total: rr.payments_total, tags: rr.tags, + deleted_msgs: rr.deleted_msgs, } } } diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index f34b6b4..1e57f12 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -712,10 +712,11 @@ public struct RunReturn { public var `payments`: String? public var `paymentsTotal`: UInt64? public var `tags`: String? + public var `deletedMsgs`: String? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `settleTopic`: String?, `settlePayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `inviterAlias`: String?, `initialTribe`: String?, `lspHost`: String?, `invoice`: String?, `route`: String?, `node`: String?, `lastRead`: String?, `muteLevels`: String?, `payments`: String?, `paymentsTotal`: UInt64?, `tags`: String?) { + public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `settleTopic`: String?, `settlePayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `inviterAlias`: String?, `initialTribe`: String?, `lspHost`: String?, `invoice`: String?, `route`: String?, `node`: String?, `lastRead`: String?, `muteLevels`: String?, `payments`: String?, `paymentsTotal`: UInt64?, `tags`: String?, `deletedMsgs`: String?) { self.`msgs` = `msgs` self.`msgsTotal` = `msgsTotal` self.`msgsCounts` = `msgsCounts` @@ -746,6 +747,7 @@ public struct RunReturn { self.`payments` = `payments` self.`paymentsTotal` = `paymentsTotal` self.`tags` = `tags` + self.`deletedMsgs` = `deletedMsgs` } } @@ -842,6 +844,9 @@ extension RunReturn: Equatable, Hashable { if lhs.`tags` != rhs.`tags` { return false } + if lhs.`deletedMsgs` != rhs.`deletedMsgs` { + return false + } return true } @@ -876,6 +881,7 @@ extension RunReturn: Equatable, Hashable { hasher.combine(`payments`) hasher.combine(`paymentsTotal`) hasher.combine(`tags`) + hasher.combine(`deletedMsgs`) } } @@ -912,7 +918,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer { `muteLevels`: FfiConverterOptionString.read(from: &buf), `payments`: FfiConverterOptionString.read(from: &buf), `paymentsTotal`: FfiConverterOptionUInt64.read(from: &buf), - `tags`: FfiConverterOptionString.read(from: &buf) + `tags`: FfiConverterOptionString.read(from: &buf), + `deletedMsgs`: FfiConverterOptionString.read(from: &buf) ) } @@ -947,6 +954,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionString.write(value.`payments`, into: &buf) FfiConverterOptionUInt64.write(value.`paymentsTotal`, into: &buf) FfiConverterOptionString.write(value.`tags`, into: &buf) + FfiConverterOptionString.write(value.`deletedMsgs`, into: &buf) } } @@ -1478,6 +1486,49 @@ fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer { } } +fileprivate struct FfiConverterOptionSequenceUInt64: FfiConverterRustBuffer { + typealias SwiftType = [UInt64]? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterSequenceUInt64.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 FfiConverterSequenceUInt64.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterSequenceUInt64: FfiConverterRustBuffer { + typealias SwiftType = [UInt64] + + public static func write(_ value: [UInt64], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterUInt64.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt64] { + let len: Int32 = try readInt(&buf) + var seq = [UInt64]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterUInt64.read(from: &buf)) + } + return seq + } +} + fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { typealias SwiftType = [String] @@ -2389,6 +2440,19 @@ public func `getTags`(`seed`: String, `uniqueTime`: String, `state`: Data, `tags ) } +public func `deleteMsgs`(`seed`: String, `uniqueTime`: String, `state`: Data, `pubkey`: String?, `msgIdxs`: [UInt64]?) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_delete_msgs( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterOptionString.lower(`pubkey`), + FfiConverterOptionSequenceUInt64.lower(`msgIdxs`),$0) +} + ) +} + private enum InitializationResult { case ok case contractVersionMismatch @@ -2611,6 +2675,9 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_get_tags() != 42493) { return InitializationResult.apiChecksumMismatch } + if (uniffi_sphinxrs_checksum_func_delete_msgs() != 39403) { + return InitializationResult.apiChecksumMismatch + } return InitializationResult.ok } diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index 6b21045..f520250 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -96,6 +96,7 @@ dictionary RunReturn { string? payments; u64? payments_total; string? tags; + string? deleted_msgs; }; namespace sphinxrs { @@ -236,4 +237,6 @@ namespace sphinxrs { RunReturn fetch_payments(string seed, string unique_time, bytes state, u64? since, u32? limit, u64? scid, boolean? remote_only, u64? min_msat, boolean? reverse); [Throws=SphinxError] RunReturn get_tags(string seed, string unique_time, bytes state, sequence tags, string? pubkey); + [Throws=SphinxError] + RunReturn delete_msgs(string seed, string unique_time, bytes state, string? pubkey, sequence? msg_idxs); }; \ No newline at end of file diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index fd2522d..8f4648a 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -201,6 +201,8 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_payments(RustBuffer seed, RustBuffer un ); RustBuffer uniffi_sphinxrs_fn_func_get_tags(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tags, RustBuffer pubkey, RustCallStatus *_Nonnull out_status ); +RustBuffer uniffi_sphinxrs_fn_func_delete_msgs(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer pubkey, RustBuffer msg_idxs, 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 @@ -415,6 +417,9 @@ uint16_t uniffi_sphinxrs_checksum_func_fetch_payments(void ); uint16_t uniffi_sphinxrs_checksum_func_get_tags(void +); +uint16_t uniffi_sphinxrs_checksum_func_delete_msgs(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 ee851f1..79f3895 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -502,6 +502,8 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_get_tags(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`tags`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_delete_msgs(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,`msgIdxs`: 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, @@ -648,6 +650,8 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_sphinxrs_checksum_func_get_tags( ): Short + fun uniffi_sphinxrs_checksum_func_delete_msgs( + ): Short fun ffi_sphinxrs_uniffi_contract_version( ): Int @@ -872,6 +876,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_get_tags() != 42493.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_sphinxrs_checksum_func_delete_msgs() != 39403.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } } // Public interface members begin here. @@ -1207,7 +1214,8 @@ data class RunReturn ( var `muteLevels`: String?, var `payments`: String?, var `paymentsTotal`: ULong?, - var `tags`: String? + var `tags`: String?, + var `deletedMsgs`: String? ) { } @@ -1245,6 +1253,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.read(buf), FfiConverterOptionalULong.read(buf), FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), ) } @@ -1278,7 +1287,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.allocationSize(value.`muteLevels`) + FfiConverterOptionalString.allocationSize(value.`payments`) + FfiConverterOptionalULong.allocationSize(value.`paymentsTotal`) + - FfiConverterOptionalString.allocationSize(value.`tags`) + FfiConverterOptionalString.allocationSize(value.`tags`) + + FfiConverterOptionalString.allocationSize(value.`deletedMsgs`) ) override fun write(value: RunReturn, buf: ByteBuffer) { @@ -1312,6 +1322,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.write(value.`payments`, buf) FfiConverterOptionalULong.write(value.`paymentsTotal`, buf) FfiConverterOptionalString.write(value.`tags`, buf) + FfiConverterOptionalString.write(value.`deletedMsgs`, buf) } } @@ -2158,6 +2169,60 @@ public object FfiConverterOptionalByteArray: FfiConverterRustBuffer +public object FfiConverterOptionalSequenceULong: FfiConverterRustBuffer?> { + override fun read(buf: ByteBuffer): List? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterSequenceULong.read(buf) + } + + override fun allocationSize(value: List?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterSequenceULong.allocationSize(value) + } + } + + override fun write(value: List?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterSequenceULong.write(value, buf) + } + } +} + + + + +public object FfiConverterSequenceULong: FfiConverterRustBuffer> { + override fun read(buf: ByteBuffer): List { + val len = buf.getInt() + return List(len) { + FfiConverterULong.read(buf) + } + } + + override fun allocationSize(value: List): Int { + val sizeForLength = 4 + val sizeForItems = value.map { FfiConverterULong.allocationSize(it) }.sum() + return sizeForLength + sizeForItems + } + + override fun write(value: List, buf: ByteBuffer) { + buf.putInt(value.size) + value.forEach { + FfiConverterULong.write(it, buf) + } + } +} + + + + public object FfiConverterSequenceString: FfiConverterRustBuffer> { override fun read(buf: ByteBuffer): List { val len = buf.getInt() @@ -2849,4 +2914,13 @@ fun `getTags`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `tags`: }) } +@Throws(SphinxException::class) + +fun `deleteMsgs`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pubkey`: String?, `msgIdxs`: List?): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_delete_msgs(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterOptionalString.lower(`pubkey`),FfiConverterOptionalSequenceULong.lower(`msgIdxs`),_status) +}) +} +