Skip to content

Commit

Permalink
invoices stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Mar 5, 2024
1 parent 4c8fea2 commit 627bde5
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 28 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 = "44c04d19c83b966ea619df326d14047f19d882fe", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "cc96d3467ed5418f441b7e28d50fd65d4ab34c8d", features = [
"msg",
"bindings",
] }
Expand Down
34 changes: 23 additions & 11 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct RunReturn {
pub topics: Vec<String>,
pub payloads: Vec<Vec<u8>>,
pub state_mp: Option<Vec<u8>>,
pub state_to_delete: Vec<String>,
pub new_balance: Option<u64>,
pub my_contact_info: Option<String>,
pub sent_status: Option<String>,
Expand All @@ -30,6 +31,7 @@ pub struct RunReturn {
pub inviter_alias: Option<String>,
pub initial_tribe: Option<String>,
pub lsp_host: Option<String>,
pub invoice: Option<String>,
}

pub fn set_network(net: String) -> Result<RunReturn> {
Expand Down Expand Up @@ -260,19 +262,27 @@ pub fn make_invoice(
unique_time: String,
full_state: Vec<u8>,
amt_msat: u64,
preimage: String,
description: String,
) -> Result<String> {
Ok(bindings::make_invoice(
&seed,
&unique_time,
&full_state,
amt_msat,
&preimage,
&description,
) -> Result<RunReturn> {
Ok(
bindings::make_invoice(&seed, &unique_time, &full_state, amt_msat, &description)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into(),
)
}

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

pub fn create_tribe(
Expand Down Expand Up @@ -399,6 +409,7 @@ impl From<bindings::RunReturn> for RunReturn {
topics: rr.topics,
payloads: rr.payloads,
state_mp: rr.state_mp,
state_to_delete: rr.state_to_delete,
new_balance: rr.new_balance,
my_contact_info: rr.my_contact_info,
sent_status: rr.sent_status,
Expand All @@ -411,6 +422,7 @@ impl From<bindings::RunReturn> for RunReturn {
inviter_alias: rr.inviter_alias,
initial_tribe: rr.initial_tribe,
lsp_host: rr.lsp_host,
invoice: rr.invoice,
}
}
}
2 changes: 1 addition & 1 deletion sphinx-ffi/src/onion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ fn run_peel_received_payment_to_bytes(
rhash: [u8; 32],
cur_height: u32,
cltv_expiry: u32,
) -> Result<(u64, String, Vec<u8>)> {
) -> Result<(u64, Option<String>, Vec<u8>)> {
Ok(
sphinx::peel_received_payment(km, pld, rhash, cur_height, cltv_expiry).map_err(|e| {
SphinxError::Decrypt {
Expand Down
43 changes: 37 additions & 6 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ public struct RunReturn {
public var `topics`: [String]
public var `payloads`: [Data]
public var `stateMp`: Data?
public var `stateToDelete`: [String]
public var `newBalance`: UInt64?
public var `myContactInfo`: String?
public var `sentStatus`: String?
Expand All @@ -595,14 +596,16 @@ public struct RunReturn {
public var `inviterAlias`: String?
public var `initialTribe`: String?
public var `lspHost`: String?
public var `invoice`: String?

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(`msgs`: [Msg], `topics`: [String], `payloads`: [Data], `stateMp`: Data?, `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?, `newTribe`: String?, `tribeMembers`: String?, `newInvite`: String?, `inviterContactInfo`: String?, `inviterAlias`: String?, `initialTribe`: String?, `lspHost`: String?) {
public init(`msgs`: [Msg], `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?) {
self.`msgs` = `msgs`
self.`topics` = `topics`
self.`payloads` = `payloads`
self.`stateMp` = `stateMp`
self.`stateToDelete` = `stateToDelete`
self.`newBalance` = `newBalance`
self.`myContactInfo` = `myContactInfo`
self.`sentStatus` = `sentStatus`
Expand All @@ -615,6 +618,7 @@ public struct RunReturn {
self.`inviterAlias` = `inviterAlias`
self.`initialTribe` = `initialTribe`
self.`lspHost` = `lspHost`
self.`invoice` = `invoice`
}
}

Expand All @@ -633,6 +637,9 @@ extension RunReturn: Equatable, Hashable {
if lhs.`stateMp` != rhs.`stateMp` {
return false
}
if lhs.`stateToDelete` != rhs.`stateToDelete` {
return false
}
if lhs.`newBalance` != rhs.`newBalance` {
return false
}
Expand Down Expand Up @@ -669,6 +676,9 @@ extension RunReturn: Equatable, Hashable {
if lhs.`lspHost` != rhs.`lspHost` {
return false
}
if lhs.`invoice` != rhs.`invoice` {
return false
}
return true
}

Expand All @@ -677,6 +687,7 @@ extension RunReturn: Equatable, Hashable {
hasher.combine(`topics`)
hasher.combine(`payloads`)
hasher.combine(`stateMp`)
hasher.combine(`stateToDelete`)
hasher.combine(`newBalance`)
hasher.combine(`myContactInfo`)
hasher.combine(`sentStatus`)
Expand All @@ -689,6 +700,7 @@ extension RunReturn: Equatable, Hashable {
hasher.combine(`inviterAlias`)
hasher.combine(`initialTribe`)
hasher.combine(`lspHost`)
hasher.combine(`invoice`)
}
}

Expand All @@ -700,6 +712,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
`topics`: FfiConverterSequenceString.read(from: &buf),
`payloads`: FfiConverterSequenceData.read(from: &buf),
`stateMp`: FfiConverterOptionData.read(from: &buf),
`stateToDelete`: FfiConverterSequenceString.read(from: &buf),
`newBalance`: FfiConverterOptionUInt64.read(from: &buf),
`myContactInfo`: FfiConverterOptionString.read(from: &buf),
`sentStatus`: FfiConverterOptionString.read(from: &buf),
Expand All @@ -711,7 +724,8 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
`inviterContactInfo`: FfiConverterOptionString.read(from: &buf),
`inviterAlias`: FfiConverterOptionString.read(from: &buf),
`initialTribe`: FfiConverterOptionString.read(from: &buf),
`lspHost`: FfiConverterOptionString.read(from: &buf)
`lspHost`: FfiConverterOptionString.read(from: &buf),
`invoice`: FfiConverterOptionString.read(from: &buf)
)
}

Expand All @@ -720,6 +734,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
FfiConverterSequenceString.write(value.`topics`, into: &buf)
FfiConverterSequenceData.write(value.`payloads`, into: &buf)
FfiConverterOptionData.write(value.`stateMp`, into: &buf)
FfiConverterSequenceString.write(value.`stateToDelete`, into: &buf)
FfiConverterOptionUInt64.write(value.`newBalance`, into: &buf)
FfiConverterOptionString.write(value.`myContactInfo`, into: &buf)
FfiConverterOptionString.write(value.`sentStatus`, into: &buf)
Expand All @@ -732,6 +747,7 @@ public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer {
FfiConverterOptionString.write(value.`inviterAlias`, into: &buf)
FfiConverterOptionString.write(value.`initialTribe`, into: &buf)
FfiConverterOptionString.write(value.`lspHost`, into: &buf)
FfiConverterOptionString.write(value.`invoice`, into: &buf)
}
}

Expand Down Expand Up @@ -1798,20 +1814,32 @@ public func `makeMediaTokenWithPrice`(`seed`: String, `uniqueTime`: String, `sta
)
}

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

public func `payInvoice`(`seed`: String, `uniqueTime`: String, `state`: Data, `bolt11`: String, `overpayMsat`: UInt64?) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_pay_invoice(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterString.lower(`bolt11`),
FfiConverterOptionUInt64.lower(`overpayMsat`),$0)
}
)
}

public func `createTribe`(`seed`: String, `uniqueTime`: String, `state`: Data, `tribeServerPubkey`: String, `tribeJson`: String) throws -> RunReturn {
return try FfiConverterTypeRunReturn.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
Expand Down Expand Up @@ -2029,7 +2057,10 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_make_media_token_with_price() != 53555) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_make_invoice() != 41170) {
if (uniffi_sphinxrs_checksum_func_make_invoice() != 12949) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_pay_invoice() != 40951) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_create_tribe() != 28873) {
Expand Down
6 changes: 5 additions & 1 deletion sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dictionary RunReturn {
sequence<string> topics;
sequence<bytes> payloads;
bytes? state_mp;
sequence<string> state_to_delete;
u64? new_balance;
string? my_contact_info;
string? sent_status;
Expand All @@ -70,6 +71,7 @@ dictionary RunReturn {
string? inviter_alias;
string? initial_tribe;
string? lsp_host;
string? invoice;
};

namespace sphinxrs {
Expand Down Expand Up @@ -155,7 +157,9 @@ namespace sphinxrs {
[Throws=SphinxError]
string make_media_token_with_price(string seed, string unique_time, bytes state, string host, string muid, string to, u32 expiry, u64 price);
[Throws=SphinxError]
string make_invoice(string seed, string unique_time, bytes state, u64 amt_msat, string preimage, string description);
RunReturn make_invoice(string seed, string unique_time, bytes state, u64 amt_msat, string description);
[Throws=SphinxError]
RunReturn pay_invoice(string seed, string unique_time, bytes state, string bolt11, u64? overpay_msat);
[Throws=SphinxError]
RunReturn create_tribe(string seed, string unique_time, bytes state, string tribe_server_pubkey, string tribe_json);
[Throws=SphinxError]
Expand Down
7 changes: 6 additions & 1 deletion sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ RustBuffer uniffi_sphinxrs_fn_func_make_media_token_with_meta(RustBuffer seed, R
);
RustBuffer uniffi_sphinxrs_fn_func_make_media_token_with_price(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer host, RustBuffer muid, RustBuffer to, uint32_t expiry, uint64_t price, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_make_invoice(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t amt_msat, RustBuffer preimage, RustBuffer description, RustCallStatus *_Nonnull out_status
RustBuffer uniffi_sphinxrs_fn_func_make_invoice(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t amt_msat, RustBuffer description, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_pay_invoice(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer bolt11, RustBuffer overpay_msat, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_create_tribe(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer tribe_server_pubkey, RustBuffer tribe_json, RustCallStatus *_Nonnull out_status
);
Expand Down Expand Up @@ -292,6 +294,9 @@ uint16_t uniffi_sphinxrs_checksum_func_make_media_token_with_price(void
);
uint16_t uniffi_sphinxrs_checksum_func_make_invoice(void

);
uint16_t uniffi_sphinxrs_checksum_func_pay_invoice(void

);
uint16_t uniffi_sphinxrs_checksum_func_create_tribe(void

Expand Down
Loading

0 comments on commit 627bde5

Please sign in to comment.