Skip to content

Commit

Permalink
separate ping and register
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jul 11, 2024
1 parent dcaa728 commit dcfe9ca
Show file tree
Hide file tree
Showing 6 changed files with 114 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 = "a6f60cd91c4972ceec9c7e3a86da14aa404255b8", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "98a111cfe83b95724641cdb59a020046aa3e79bf", features = [
"msg",
"bindings",
] }
Expand Down
21 changes: 21 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct RunReturn {
pub tags: Option<String>,
pub deleted_msgs: Option<String>,
pub new_child_idx: Option<u64>,
pub ping: Option<String>,
}

pub fn set_network(net: String) -> Result<RunReturn> {
Expand Down Expand Up @@ -213,6 +214,25 @@ pub fn fetch_msgs(
)
}

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

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

pub fn handle(
topic: String,
payload: Vec<u8>,
Expand Down Expand Up @@ -833,6 +853,7 @@ impl From<bindings::RunReturn> for RunReturn {
tags: rr.tags,
deleted_msgs: rr.deleted_msgs,
new_child_idx: rr.new_child_idx,
ping: rr.ping,
}
}
}
41 changes: 39 additions & 2 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,11 @@ public struct RunReturn {
public var `tags`: String?
public var `deletedMsgs`: String?
public var `newChildIdx`: UInt64?
public var `ping`: 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?, `asyncpayTopic`: String?, `asyncpayPayload`: Data?, `registerTopic`: String?, `registerPayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `registerResponse`: String?, `asyncpayTag`: 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?, `newChildIdx`: UInt64?) {
public init(`msgs`: [Msg], `msgsTotal`: UInt64?, `msgsCounts`: String?, `subscriptionTopics`: [String], `settleTopic`: String?, `settlePayload`: Data?, `asyncpayTopic`: String?, `asyncpayPayload`: Data?, `registerTopic`: String?, `registerPayload`: Data?, `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `stateToDelete`: [String], `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `registerResponse`: String?, `asyncpayTag`: 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?, `newChildIdx`: UInt64?, `ping`: String?) {
self.`msgs` = `msgs`
self.`msgsTotal` = `msgsTotal`
self.`msgsCounts` = `msgsCounts`
Expand Down Expand Up @@ -770,6 +771,7 @@ public struct RunReturn {
self.`tags` = `tags`
self.`deletedMsgs` = `deletedMsgs`
self.`newChildIdx` = `newChildIdx`
self.`ping` = `ping`
}
}

Expand Down Expand Up @@ -890,6 +892,9 @@ extension RunReturn: Equatable, Hashable {
if lhs.`newChildIdx` != rhs.`newChildIdx` {
return false
}
if lhs.`ping` != rhs.`ping` {
return false
}
return true
}

Expand Down Expand Up @@ -932,6 +937,7 @@ extension RunReturn: Equatable, Hashable {
hasher.combine(`tags`)
hasher.combine(`deletedMsgs`)
hasher.combine(`newChildIdx`)
hasher.combine(`ping`)
}
}

Expand Down Expand Up @@ -976,7 +982,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
`paymentsTotal`: FfiConverterOptionUInt64.read(from: &buf),
`tags`: FfiConverterOptionString.read(from: &buf),
`deletedMsgs`: FfiConverterOptionString.read(from: &buf),
`newChildIdx`: FfiConverterOptionUInt64.read(from: &buf)
`newChildIdx`: FfiConverterOptionUInt64.read(from: &buf),
`ping`: FfiConverterOptionString.read(from: &buf)
)
}

Expand Down Expand Up @@ -1019,6 +1026,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
FfiConverterOptionString.write(value.`tags`, into: &buf)
FfiConverterOptionString.write(value.`deletedMsgs`, into: &buf)
FfiConverterOptionUInt64.write(value.`newChildIdx`, into: &buf)
FfiConverterOptionString.write(value.`ping`, into: &buf)
}
}

Expand Down Expand Up @@ -2589,6 +2597,29 @@ public func `concatRoute`(`state`: Data, `endHops`: String, `routerPubkey`: Stri
)
}

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

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

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2832,6 +2863,12 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_concat_route() != 19565) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_ping_done() != 13787) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_fetch_pings() != 13806) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
Expand Down
5 changes: 5 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dictionary RunReturn {
string? tags;
string? deleted_msgs;
u64? new_child_idx;
string? ping;
};

namespace sphinxrs {
Expand Down Expand Up @@ -259,4 +260,8 @@ namespace sphinxrs {
RunReturn add_node(string node);
[Throws=SphinxError]
RunReturn concat_route(bytes state, string end_hops, string router_pubkey, u64 amt_msat);
[Throws=SphinxError]
RunReturn ping_done(string seed, string unique_time, bytes state, u64 ping_ts);
[Throws=SphinxError]
RunReturn fetch_pings(string seed, string unique_time, bytes state);
};
10 changes: 10 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ RustBuffer uniffi_sphinxrs_fn_func_add_node(RustBuffer node, RustCallStatus *_No
);
RustBuffer uniffi_sphinxrs_fn_func_concat_route(RustBuffer state, RustBuffer end_hops, RustBuffer router_pubkey, uint64_t amt_msat, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_ping_done(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t ping_ts, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_fetch_pings(RustBuffer seed, RustBuffer unique_time, RustBuffer state, 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 @@ -450,6 +454,12 @@ uint16_t uniffi_sphinxrs_checksum_func_add_node(void
);
uint16_t uniffi_sphinxrs_checksum_func_concat_route(void

);
uint16_t uniffi_sphinxrs_checksum_func_ping_done(void

);
uint16_t uniffi_sphinxrs_checksum_func_fetch_pings(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
40 changes: 38 additions & 2 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_concat_route(`state`: RustBuffer.ByValue,`endHops`: RustBuffer.ByValue,`routerPubkey`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_ping_done(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pingTs`: Long,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_fetch_pings(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: 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 @@ -676,6 +680,10 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_concat_route(
): Short
fun uniffi_sphinxrs_checksum_func_ping_done(
): Short
fun uniffi_sphinxrs_checksum_func_fetch_pings(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

Expand Down Expand Up @@ -921,6 +929,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_concat_route() != 19565.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_ping_done() != 13787.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_fetch_pings() != 13806.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Public interface members begin here.
Expand Down Expand Up @@ -1268,7 +1282,8 @@ data class RunReturn (
var `paymentsTotal`: ULong?,
var `tags`: String?,
var `deletedMsgs`: String?,
var `newChildIdx`: ULong?
var `newChildIdx`: ULong?,
var `ping`: String?
) {

}
Expand Down Expand Up @@ -1314,6 +1329,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.read(buf),
FfiConverterOptionalString.read(buf),
FfiConverterOptionalULong.read(buf),
FfiConverterOptionalString.read(buf),
)
}

Expand Down Expand Up @@ -1355,7 +1371,8 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalULong.allocationSize(value.`paymentsTotal`) +
FfiConverterOptionalString.allocationSize(value.`tags`) +
FfiConverterOptionalString.allocationSize(value.`deletedMsgs`) +
FfiConverterOptionalULong.allocationSize(value.`newChildIdx`)
FfiConverterOptionalULong.allocationSize(value.`newChildIdx`) +
FfiConverterOptionalString.allocationSize(value.`ping`)
)

override fun write(value: RunReturn, buf: ByteBuffer) {
Expand Down Expand Up @@ -1397,6 +1414,7 @@ public object FfiConverterTypeRunReturn: FfiConverterRustBuffer<RunReturn> {
FfiConverterOptionalString.write(value.`tags`, buf)
FfiConverterOptionalString.write(value.`deletedMsgs`, buf)
FfiConverterOptionalULong.write(value.`newChildIdx`, buf)
FfiConverterOptionalString.write(value.`ping`, buf)
}
}

Expand Down Expand Up @@ -3051,4 +3069,22 @@ fun `concatRoute`(`state`: ByteArray, `endHops`: String, `routerPubkey`: String,
})
}

@Throws(SphinxException::class)

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

@Throws(SphinxException::class)

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


0 comments on commit dcfe9ca

Please sign in to comment.