Skip to content

Commit

Permalink
invoice::pay
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 15, 2024
1 parent ff73fd5 commit 25e6977
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
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 = "371cf9c1eb08b208ea6ce88917829dd098a168cc", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "7c2d861062a3bedacb4f8081b31de980f34fafdb", features = [
"msg",
"bindings",
"macaroon",
Expand Down
11 changes: 11 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ pub fn keysend(
.into())
}

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

fn my_img_opt(my_img: &str) -> Option<&str> {
match my_img {
"" => None,
Expand Down
15 changes: 15 additions & 0 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,18 @@ public func `keysend`(`seed`: String, `uniqueTime`: String, `to`: String, `state
)
}

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

public func `makeMediaToken`(`seed`: String, `uniqueTime`: String, `state`: Data, `host`: String, `muid`: String, `to`: String, `expiry`: UInt32) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
Expand Down Expand Up @@ -2812,6 +2824,9 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_keysend() != 58116) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_pay() != 1388) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_make_media_token() != 53931) {
return InitializationResult.apiChecksumMismatch
}
Expand Down
2 changes: 2 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ namespace sphinxrs {
[Throws=SphinxError]
RunReturn keysend(string seed, string unique_time, string to, bytes state, u64 amt_msat, bytes? data, string? route_hint);
[Throws=SphinxError]
RunReturn pay(string seed, string unique_time, bytes state, string bolt11);
[Throws=SphinxError]
string make_media_token(string seed, string unique_time, bytes state, string host, string muid, string to, u32 expiry);
[Throws=SphinxError]
string make_media_token_with_meta(string seed, string unique_time, bytes state, string host, string muid, string to, u32 expiry, string meta);
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 @@ -152,6 +152,8 @@ RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time,
);
RustBuffer uniffi_sphinxrs_fn_func_keysend(RustBuffer seed, RustBuffer unique_time, RustBuffer to, RustBuffer state, uint64_t amt_msat, RustBuffer data, RustBuffer route_hint, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_pay(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer bolt11, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_make_media_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, RustBuffer muid, RustBuffer to, uint32_t expiry, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_make_media_token_with_meta(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, RustBuffer muid, RustBuffer to, uint32_t expiry, RustBuffer meta, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -367,6 +369,9 @@ uint16_t uniffi_sphinxrs_checksum_func_send(void
);
uint16_t uniffi_sphinxrs_checksum_func_keysend(void

);
uint16_t uniffi_sphinxrs_checksum_func_pay(void

);
uint16_t uniffi_sphinxrs_checksum_func_make_media_token(void

Expand Down
16 changes: 16 additions & 0 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_keysend(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`amtMsat`: Long,`data`: RustBuffer.ByValue,`routeHint`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_pay(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`bolt11`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_make_media_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`host`: RustBuffer.ByValue,`muid`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`expiry`: Int,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_make_media_token_with_meta(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`host`: RustBuffer.ByValue,`muid`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`expiry`: Int,`meta`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -624,6 +626,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_keysend(
): Short
fun uniffi_sphinxrs_checksum_func_pay(
): Short
fun uniffi_sphinxrs_checksum_func_make_media_token(
): Short
fun uniffi_sphinxrs_checksum_func_make_media_token_with_meta(
Expand Down Expand Up @@ -849,6 +853,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_keysend() != 58116.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_pay() != 1388.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_make_media_token() != 53931.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -2811,6 +2818,15 @@ fun `keysend`(`seed`: String, `uniqueTime`: String, `to`: String, `state`: ByteA

@Throws(SphinxException::class)

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

@Throws(SphinxException::class)

fun `makeMediaToken`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `host`: String, `muid`: String, `to`: String, `expiry`: UInt): String {
return FfiConverterString.lift(
rustCallWithError(SphinxException) { _status ->
Expand Down

0 comments on commit 25e6977

Please sign in to comment.