Skip to content

Commit

Permalink
custom routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Jun 9, 2024
1 parent 7f72827 commit d540123
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,25 @@ pub fn delete_msgs(
)
}

pub fn add_node(node: String) -> Result<RunReturn> {
Ok(bindings::add_node(&node)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into())
}

pub fn concat_route(
full_state: Vec<u8>,
end_hops: String,
router_pubkey: String,
amt_msat: u64,
) -> Result<RunReturn> {
Ok(
bindings::concat_route(&full_state, &end_hops, &router_pubkey, amt_msat)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into(),
)
}

impl From<bindings::Msg> for Msg {
fn from(rr: bindings::Msg) -> Self {
Msg {
Expand Down
27 changes: 27 additions & 0 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,27 @@ public func `deleteTribe`(`seed`: String, `uniqueTime`: String, `state`: Data, `
)
}

public func `addNode`(`node`: String) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_add_node(
FfiConverterString.lower(`node`),$0)
}
)
}

public func `concatRoute`(`state`: Data, `endHops`: String, `routerPubkey`: String, `amtMsat`: UInt64) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_concat_route(
FfiConverterData.lower(`state`),
FfiConverterString.lower(`endHops`),
FfiConverterString.lower(`routerPubkey`),
FfiConverterUInt64.lower(`amtMsat`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2710,6 +2731,12 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_delete_tribe() != 11926) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_add_node() != 49737) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_concat_route() != 19565) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
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 @@ -243,4 +243,8 @@ namespace sphinxrs {
RunReturn update_tribe(string seed, string unique_time, bytes state, string tribe_server_pubkey, string tribe_json);
[Throws=SphinxError]
RunReturn delete_tribe(string seed, string unique_time, bytes state, string tribe_server_pubkey, string tribe_pubkey);
[Throws=SphinxError]
RunReturn add_node(string node);
[Throws=SphinxError]
RunReturn concat_route(bytes state, string end_hops, string router_pubkey, u64 amt_msat);
};
10 changes: 10 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ RustBuffer uniffi_sphinxrs_fn_func_update_tribe(RustBuffer seed, RustBuffer uniq
);
RustBuffer uniffi_sphinxrs_fn_func_delete_tribe(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tribe_server_pubkey, RustBuffer tribe_pubkey, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_add_node(RustBuffer node, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_concat_route(RustBuffer state, RustBuffer end_hops, RustBuffer router_pubkey, uint64_t amt_msat, 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 @@ -430,6 +434,12 @@ uint16_t uniffi_sphinxrs_checksum_func_update_tribe(void
);
uint16_t uniffi_sphinxrs_checksum_func_delete_tribe(void

);
uint16_t uniffi_sphinxrs_checksum_func_add_node(void

);
uint16_t uniffi_sphinxrs_checksum_func_concat_route(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
32 changes: 32 additions & 0 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_delete_tribe(`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_add_node(`node`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): 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 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 @@ -660,6 +664,10 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_delete_tribe(
): Short
fun uniffi_sphinxrs_checksum_func_add_node(
): Short
fun uniffi_sphinxrs_checksum_func_concat_route(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

Expand Down Expand Up @@ -893,6 +901,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_delete_tribe() != 11926.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_add_node() != 49737.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_concat_route() != 19565.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Public interface members begin here.
Expand Down Expand Up @@ -2955,4 +2969,22 @@ fun `deleteTribe`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `tri
})
}

@Throws(SphinxException::class)

fun `addNode`(`node`: String): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_add_node(FfiConverterString.lower(`node`),_status)
})
}

@Throws(SphinxException::class)

fun `concatRoute`(`state`: ByteArray, `endHops`: String, `routerPubkey`: String, `amtMsat`: ULong): RunReturn {
return FfiConverterTypeRunReturn.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_concat_route(FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`endHops`),FfiConverterString.lower(`routerPubkey`),FfiConverterULong.lower(`amtMsat`),_status)
})
}


0 comments on commit d540123

Please sign in to comment.