Skip to content

Commit

Permalink
separate settle topic/payload, get_blockheight
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jun 3, 2024
1 parent 998602c commit af89787
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 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 = "74c77c88788d75377c252d8b64a22e267a1ee796", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "25f7deb6f8006a9f58287351835b2d2a955f6616", features = [
"msg",
"bindings",
] }
Expand Down
14 changes: 14 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct RunReturn {
pub msgs_total: Option<u64>,
pub msgs_counts: Option<String>,
pub subscription_topics: Vec<String>,
pub settle_topic: Option<String>,
pub settle_payload: Option<Vec<u8>>,
pub topics: Vec<String>,
pub payloads: Vec<Vec<u8>>,
pub state_mp: Option<Vec<u8>>,
Expand Down Expand Up @@ -72,6 +74,16 @@ pub fn set_blockheight(bh: u32) -> Result<RunReturn> {
.into())
}

pub fn get_blockheight(
seed: String,
unique_time: String,
full_state: Vec<u8>,
) -> Result<RunReturn> {
Ok(bindings::get_blockheight(&seed, &unique_time, &full_state)
.map_err(|e| SphinxError::SetBlockheightFailed { r: e.to_string() })?
.into())
}

pub fn get_default_tribe_server(full_state: Vec<u8>) -> Result<String> {
let ns = bindings::get_default_tribe_server(&full_state)
.map_err(|e| SphinxError::ParseStateFailed { r: e.to_string() })?;
Expand Down Expand Up @@ -687,6 +699,8 @@ impl From<bindings::RunReturn> for RunReturn {
msgs_total: rr.msgs_total,
msgs_counts: rr.msgs_counts,
subscription_topics: rr.subscription_topics,
settle_topic: rr.settle_topic,
settle_payload: rr.settle_payload,
topics: rr.topics,
payloads: rr.payloads,
state_mp: rr.state_mp,
Expand Down
32 changes: 31 additions & 1 deletion sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ public struct RunReturn {
public var `msgsTotal`: UInt64?
public var `msgsCounts`: String?
public var `subscriptionTopics`: [String]
public var `settleTopic`: String?
public var `settlePayload`: Data?
public var `topics`: [String]
public var `payloads`: [Data]
public var `stateMp`: Data?
Expand All @@ -712,11 +714,13 @@ public struct RunReturn {

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `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?) {
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?) {
self.`msgs` = `msgs`
self.`msgsTotal` = `msgsTotal`
self.`msgsCounts` = `msgsCounts`
self.`subscriptionTopics` = `subscriptionTopics`
self.`settleTopic` = `settleTopic`
self.`settlePayload` = `settlePayload`
self.`topics` = `topics`
self.`payloads` = `payloads`
self.`stateMp` = `stateMp`
Expand Down Expand Up @@ -758,6 +762,12 @@ extension RunReturn: Equatable, Hashable {
if lhs.`subscriptionTopics` != rhs.`subscriptionTopics` {
return false
}
if lhs.`settleTopic` != rhs.`settleTopic` {
return false
}
if lhs.`settlePayload` != rhs.`settlePayload` {
return false
}
if lhs.`topics` != rhs.`topics` {
return false
}
Expand Down Expand Up @@ -835,6 +845,8 @@ extension RunReturn: Equatable, Hashable {
hasher.combine(`msgsTotal`)
hasher.combine(`msgsCounts`)
hasher.combine(`subscriptionTopics`)
hasher.combine(`settleTopic`)
hasher.combine(`settlePayload`)
hasher.combine(`topics`)
hasher.combine(`payloads`)
hasher.combine(`stateMp`)
Expand Down Expand Up @@ -869,6 +881,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
`msgsTotal`: FfiConverterOptionUInt64.read(from: &buf),
`msgsCounts`: FfiConverterOptionString.read(from: &buf),
`subscriptionTopics`: FfiConverterSequenceString.read(from: &buf),
`settleTopic`: FfiConverterOptionString.read(from: &buf),
`settlePayload`: FfiConverterOptionData.read(from: &buf),
`topics`: FfiConverterSequenceString.read(from: &buf),
`payloads`: FfiConverterSequenceData.read(from: &buf),
`stateMp`: FfiConverterOptionData.read(from: &buf),
Expand Down Expand Up @@ -900,6 +914,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
FfiConverterOptionUInt64.write(value.`msgsTotal`, into: &buf)
FfiConverterOptionString.write(value.`msgsCounts`, into: &buf)
FfiConverterSequenceString.write(value.`subscriptionTopics`, into: &buf)
FfiConverterOptionString.write(value.`settleTopic`, into: &buf)
FfiConverterOptionData.write(value.`settlePayload`, into: &buf)
FfiConverterSequenceString.write(value.`topics`, into: &buf)
FfiConverterSequenceData.write(value.`payloads`, into: &buf)
FfiConverterOptionData.write(value.`stateMp`, into: &buf)
Expand Down Expand Up @@ -1866,6 +1882,17 @@ public func `setBlockheight`(`blockheight`: UInt32) throws -> RunReturn {
)
}

public func `getBlockheight`(`seed`: String, `uniqueTime`: String, `state`: Data) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_get_blockheight(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),$0)
}
)
}

public func `addContact`(`seed`: String, `uniqueTime`: String, `state`: Data, `toPubkey`: String, `routeHint`: String, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64, `inviteCode`: String?, `theirAlias`: String?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
Expand Down Expand Up @@ -2446,6 +2473,9 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_set_blockheight() != 43943) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_get_blockheight() != 25615) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_add_contact() != 30931) {
return InitializationResult.apiChecksumMismatch
}
Expand Down
4 changes: 4 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ dictionary RunReturn {
u64? msgs_total;
string? msgs_counts;
sequence<string> subscription_topics;
string? settle_topic;
bytes? settle_payload;
sequence<string> topics;
sequence<bytes> payloads;
bytes? state_mp;
Expand Down Expand Up @@ -156,6 +158,8 @@ namespace sphinxrs {
[Throws=SphinxError]
RunReturn set_blockheight(u32 blockheight);
[Throws=SphinxError]
RunReturn get_blockheight(string seed, string unique_time, bytes state);
[Throws=SphinxError]
RunReturn add_contact(string seed, string unique_time, bytes state, string to_pubkey, string route_hint, string my_alias, string my_img, u64 amt_msat, string? invite_code, string? their_alias);
[Throws=SphinxError]
string get_contact(bytes state, string pubkey);
Expand Down
5 changes: 5 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ RustBuffer uniffi_sphinxrs_fn_func_set_device(RustBuffer device, RustCallStatus
);
RustBuffer uniffi_sphinxrs_fn_func_set_blockheight(uint32_t blockheight, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_get_blockheight(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_add_contact(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer to_pubkey, RustBuffer route_hint, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, RustBuffer invite_code, RustBuffer their_alias, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_get_contact(RustBuffer state, RustBuffer pubkey, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -294,6 +296,9 @@ uint16_t uniffi_sphinxrs_checksum_func_set_device(void
);
uint16_t uniffi_sphinxrs_checksum_func_set_blockheight(void

);
uint16_t uniffi_sphinxrs_checksum_func_get_blockheight(void

);
uint16_t uniffi_sphinxrs_checksum_func_add_contact(void

Expand Down
24 changes: 24 additions & 0 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_set_blockheight(`blockheight`: Int,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_get_blockheight(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_add_contact(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`toPubkey`: RustBuffer.ByValue,`routeHint`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,`inviteCode`: RustBuffer.ByValue,`theirAlias`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_get_contact(`state`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -566,6 +568,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_set_blockheight(
): Short
fun uniffi_sphinxrs_checksum_func_get_blockheight(
): Short
fun uniffi_sphinxrs_checksum_func_add_contact(
): Short
fun uniffi_sphinxrs_checksum_func_get_contact(
Expand Down Expand Up @@ -747,6 +751,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_set_blockheight() != 43943.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_get_blockheight() != 25615.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_add_contact() != 30931.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -1168,6 +1175,8 @@ data class RunReturn (
var `msgsTotal`: ULong?,
var `msgsCounts`: String?,
var `subscriptionTopics`: List<String>,
var `settleTopic`: String?,
var `settlePayload`: ByteArray?,
var `topics`: List<String>,
var `payloads`: List<ByteArray>,
var `stateMp`: ByteArray?,
Expand Down Expand Up @@ -1202,6 +1211,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalULong.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterSequenceString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalByteArray.read(buf),
FfiConverterSequenceString.read(buf),
FfiConverterSequenceByteArray.read(buf),
FfiConverterOptionalByteArray.read(buf),
Expand Down Expand Up @@ -1233,6 +1244,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalULong.allocationSize(value.`msgsTotal`) +
FfiConverterOptionalString.allocationSize(value.`msgsCounts`) +
FfiConverterSequenceString.allocationSize(value.`subscriptionTopics`) +
FfiConverterOptionalString.allocationSize(value.`settleTopic`) +
FfiConverterOptionalByteArray.allocationSize(value.`settlePayload`) +
FfiConverterSequenceString.allocationSize(value.`topics`) +
FfiConverterSequenceByteArray.allocationSize(value.`payloads`) +
FfiConverterOptionalByteArray.allocationSize(value.`stateMp`) +
Expand Down Expand Up @@ -1263,6 +1276,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalULong.write(value.`msgsTotal`, buf)
FfiConverterOptionalString.write(value.`msgsCounts`, buf)
FfiConverterSequenceString.write(value.`subscriptionTopics`, buf)
FfiConverterOptionalString.write(value.`settleTopic`, buf)
FfiConverterOptionalByteArray.write(value.`settlePayload`, buf)
FfiConverterSequenceString.write(value.`topics`, buf)
FfiConverterSequenceByteArray.write(value.`payloads`, buf)
FfiConverterOptionalByteArray.write(value.`stateMp`, buf)
Expand Down Expand Up @@ -2474,6 +2489,15 @@ fun `setBlockheight`(`blockheight`: UInt): RunReturn {

@Throws(SphinxException::class)

fun `getBlockheight`(`seed`: String, `uniqueTime`: String, `state`: ByteArray): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_get_blockheight(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),_status)
})
}

@Throws(SphinxException::class)

fun `addContact`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `toPubkey`: String, `routeHint`: String, `myAlias`: String, `myImg`: String, `amtMsat`: ULong, `inviteCode`: String?, `theirAlias`: String?): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
Expand Down

0 comments on commit af89787

Please sign in to comment.