Skip to content

Commit

Permalink
invite bindigs
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Feb 5, 2024
1 parent 6a94e68 commit 5a94bf9
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sphinx-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
Expand Down
33 changes: 33 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct RunReturn {
pub error: Option<String>,
pub new_tribe: Option<String>,
pub tribe_members: Option<String>,
pub new_invite: Option<String>,
pub inviter_contact_info: Option<String>,
pub lsp_host: Option<String>,
}

pub fn set_network(net: String) -> Result<RunReturn> {
Expand Down Expand Up @@ -316,6 +319,33 @@ pub fn list_tribe_members(
.into())
}

pub fn make_invite(
seed: String,
unique_time: String,
full_state: Vec<u8>,
host: String,
amt_msat: u64,
) -> Result<RunReturn> {
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<u8>,
invite_qr: String,
) -> Result<RunReturn> {
Ok(
bindings::process_invite(&seed, &unique_time, &full_state, &invite_qr)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into(),
)
}

impl From<bindings::RunReturn> for RunReturn {
fn from(rr: bindings::RunReturn) -> Self {
RunReturn {
Expand All @@ -342,6 +372,9 @@ impl From<bindings::RunReturn> 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,
}
}
}
59 changes: 57 additions & 2 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
}
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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`)
}
}

Expand Down Expand Up @@ -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)
)
}

Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
};
10 changes: 10 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
48 changes: 46 additions & 2 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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?
) {

}
Expand Down Expand Up @@ -950,6 +967,9 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
)
}

Expand All @@ -976,7 +996,10 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
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) {
Expand All @@ -1003,6 +1026,9 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
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)
}
}

Expand Down Expand Up @@ -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)
})
}


0 comments on commit 5a94bf9

Please sign in to comment.