diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index 50e334d..c63d329 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 = "6933a714d2fa3a281cdd6344b007a33effee8a41", features = [ +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "c300c753f5ee9f5381b0246b8df5f78b7241d460", features = [ "msg", "bindings", ] } diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs index 1a38b5a..e4ae1e5 100644 --- a/sphinx-ffi/src/auto.rs +++ b/sphinx-ffi/src/auto.rs @@ -26,6 +26,9 @@ pub struct RunReturn { pub error: Option, pub new_tribe: Option, pub tribe_members: Option, + pub new_invite: Option, + pub inviter_contact_info: Option, + pub lsp_host: Option, } pub fn set_network(net: String) -> Result { @@ -316,6 +319,33 @@ pub fn list_tribe_members( .into()) } +pub fn make_invite( + seed: String, + unique_time: String, + full_state: Vec, + host: String, + amt_msat: u64, +) -> Result { + Ok( + bindings::make_invite(&seed, &unique_time, &full_state, &host, amt_msat) + .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? + .into(), + ) +} + +pub fn process_invite( + seed: String, + unique_time: String, + full_state: Vec, + invite_qr: String, +) -> Result { + Ok( + bindings::process_invite(&seed, &unique_time, &full_state, &invite_qr) + .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? + .into(), + ) +} + impl From for RunReturn { fn from(rr: bindings::RunReturn) -> Self { RunReturn { @@ -342,6 +372,9 @@ impl From for RunReturn { error: rr.error, new_tribe: rr.new_tribe, tribe_members: rr.tribe_members, + new_invite: rr.new_invite, + inviter_contact_info: rr.inviter_contact_info, + lsp_host: rr.lsp_host, } } } diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index de3a4a8..a567d14 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -499,10 +499,13 @@ public struct RunReturn { public var `error`: String? public var `newTribe`: String? public var `tribeMembers`: String? + public var `newInvite`: String? + public var `inviterContactInfo`: String? + public var `lspHost`: String? // Default memberwise initializers are never public by default, so we // declare one manually. - public init(`newSubscription`: String?, `topic0`: String?, `payload0`: Data?, `topic1`: String?, `payload1`: Data?, `topic2`: String?, `payload2`: Data?, `stateMp`: Data?, `msg`: String?, `msgType`: UInt8?, `msgUuid`: String?, `msgIndex`: String?, `msgSender`: String?, `msgMsat`: UInt64?, `msgTimestamp`: UInt64?, `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `sentTo`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?) { + public init(`newSubscription`: String?, `topic0`: String?, `payload0`: Data?, `topic1`: String?, `payload1`: Data?, `topic2`: String?, `payload2`: Data?, `stateMp`: Data?, `msg`: String?, `msgType`: UInt8?, `msgUuid`: String?, `msgIndex`: String?, `msgSender`: String?, `msgMsat`: UInt64?, `msgTimestamp`: UInt64?, `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `sentTo`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `lspHost`: String?) { self.`newSubscription` = `newSubscription` self.`topic0` = `topic0` self.`payload0` = `payload0` @@ -526,6 +529,9 @@ public struct RunReturn { self.`error` = `error` self.`newTribe` = `newTribe` self.`tribeMembers` = `tribeMembers` + self.`newInvite` = `newInvite` + self.`inviterContactInfo` = `inviterContactInfo` + self.`lspHost` = `lspHost` } } @@ -601,6 +607,15 @@ extension RunReturn: Equatable, Hashable { if lhs.`tribeMembers` != rhs.`tribeMembers` { return false } + if lhs.`newInvite` != rhs.`newInvite` { + return false + } + if lhs.`inviterContactInfo` != rhs.`inviterContactInfo` { + return false + } + if lhs.`lspHost` != rhs.`lspHost` { + return false + } return true } @@ -628,6 +643,9 @@ extension RunReturn: Equatable, Hashable { hasher.combine(`error`) hasher.combine(`newTribe`) hasher.combine(`tribeMembers`) + hasher.combine(`newInvite`) + hasher.combine(`inviterContactInfo`) + hasher.combine(`lspHost`) } } @@ -657,7 +675,10 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer { `settledStatus`: FfiConverterOptionString.read(from: &buf), `error`: FfiConverterOptionString.read(from: &buf), `newTribe`: FfiConverterOptionString.read(from: &buf), - `tribeMembers`: FfiConverterOptionString.read(from: &buf) + `tribeMembers`: FfiConverterOptionString.read(from: &buf), + `newInvite`: FfiConverterOptionString.read(from: &buf), + `inviterContactInfo`: FfiConverterOptionString.read(from: &buf), + `lspHost`: FfiConverterOptionString.read(from: &buf) ) } @@ -685,6 +706,9 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionString.write(value.`error`, into: &buf) FfiConverterOptionString.write(value.`newTribe`, into: &buf) FfiConverterOptionString.write(value.`tribeMembers`, into: &buf) + FfiConverterOptionString.write(value.`newInvite`, into: &buf) + FfiConverterOptionString.write(value.`inviterContactInfo`, into: &buf) + FfiConverterOptionString.write(value.`lspHost`, into: &buf) } } @@ -1728,6 +1752,31 @@ public func `listTribeMembers`(`seed`: String, `uniqueTime`: String, `state`: Da ) } +public func `makeInvite`(`seed`: String, `uniqueTime`: String, `state`: Data, `host`: String, `amtMsat`: UInt64) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_make_invite( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterString.lower(`host`), + FfiConverterUInt64.lower(`amtMsat`),$0) +} + ) +} + +public func `processInvite`(`seed`: String, `uniqueTime`: String, `state`: Data, `inviteQr`: String) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_process_invite( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterString.lower(`inviteQr`),$0) +} + ) +} + private enum InitializationResult { case ok case contractVersionMismatch @@ -1875,6 +1924,12 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_list_tribe_members() != 48922) { return InitializationResult.apiChecksumMismatch } + if (uniffi_sphinxrs_checksum_func_make_invite() != 48075) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_process_invite() != 52237) { + return InitializationResult.apiChecksumMismatch + } return InitializationResult.ok } diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index d5b4e8b..bf1446e 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -66,6 +66,9 @@ dictionary RunReturn { string? error; string? new_tribe; string? tribe_members; + string? new_invite; + string? inviter_contact_info; + string? lsp_host; }; namespace sphinxrs { @@ -156,4 +159,8 @@ namespace sphinxrs { RunReturn join_tribe(string seed, string unique_time, bytes state, string tribe_pubkey, string tribe_route_hint, string alias, u64 amt_msat); [Throws=SphinxError] RunReturn list_tribe_members(string seed, string unique_time, bytes state, string tribe_server_pubkey, string tribe_pubkey); + [Throws=SphinxError] + RunReturn make_invite(string seed, string unique_time, bytes state, string host, u64 amt_msat); + [Throws=SphinxError] + RunReturn process_invite(string seed, string unique_time, bytes state, string invite_qr); }; \ No newline at end of file diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index bb0549a..a37e95f 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -151,6 +151,10 @@ RustBuffer uniffi_sphinxrs_fn_func_join_tribe(RustBuffer seed, RustBuffer unique ); RustBuffer uniffi_sphinxrs_fn_func_list_tribe_members(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tribe_server_pubkey, RustBuffer tribe_pubkey, RustCallStatus *_Nonnull out_status ); +RustBuffer uniffi_sphinxrs_fn_func_make_invite(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, uint64_t amt_msat, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_process_invite(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer invite_qr, 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 @@ -290,6 +294,12 @@ uint16_t uniffi_sphinxrs_checksum_func_join_tribe(void ); uint16_t uniffi_sphinxrs_checksum_func_list_tribe_members(void +); +uint16_t uniffi_sphinxrs_checksum_func_make_invite(void + +); +uint16_t uniffi_sphinxrs_checksum_func_process_invite(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 669e6ce..97a4eae 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -452,6 +452,10 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_list_tribe_members(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`tribeServerPubkey`: RustBuffer.ByValue,`tribePubkey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_make_invite(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`host`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_process_invite(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`inviteQr`: 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, @@ -548,6 +552,10 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_sphinxrs_checksum_func_list_tribe_members( ): Short + fun uniffi_sphinxrs_checksum_func_make_invite( + ): Short + fun uniffi_sphinxrs_checksum_func_process_invite( + ): Short fun ffi_sphinxrs_uniffi_contract_version( ): Int @@ -697,6 +705,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_list_tribe_members() != 48922.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_sphinxrs_checksum_func_make_invite() != 48075.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_process_invite() != 52237.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } } // Public interface members begin here. @@ -919,7 +933,10 @@ data class RunReturn ( var `settledStatus`: String?, var `error`: String?, var `newTribe`: String?, - var `tribeMembers`: String? + var `tribeMembers`: String?, + var `newInvite`: String?, + var `inviterContactInfo`: String?, + var `lspHost`: String? ) { } @@ -950,6 +967,9 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.read(buf), FfiConverterOptionalString.read(buf), FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), ) } @@ -976,7 +996,10 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.allocationSize(value.`settledStatus`) + FfiConverterOptionalString.allocationSize(value.`error`) + FfiConverterOptionalString.allocationSize(value.`newTribe`) + - FfiConverterOptionalString.allocationSize(value.`tribeMembers`) + FfiConverterOptionalString.allocationSize(value.`tribeMembers`) + + FfiConverterOptionalString.allocationSize(value.`newInvite`) + + FfiConverterOptionalString.allocationSize(value.`inviterContactInfo`) + + FfiConverterOptionalString.allocationSize(value.`lspHost`) ) override fun write(value: RunReturn, buf: ByteBuffer) { @@ -1003,6 +1026,9 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { FfiConverterOptionalString.write(value.`error`, buf) FfiConverterOptionalString.write(value.`newTribe`, buf) FfiConverterOptionalString.write(value.`tribeMembers`, buf) + FfiConverterOptionalString.write(value.`newInvite`, buf) + FfiConverterOptionalString.write(value.`inviterContactInfo`, buf) + FfiConverterOptionalString.write(value.`lspHost`, buf) } } @@ -2191,4 +2217,22 @@ fun `listTribeMembers`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, }) } +@Throws(SphinxException::class) + +fun `makeInvite`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `host`: String, `amtMsat`: ULong): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_make_invite(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`host`),FfiConverterULong.lower(`amtMsat`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `processInvite`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `inviteQr`: String): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_process_invite(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`inviteQr`),_status) +}) +} +