Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export declare class MdkNode {
description: string,
expirySecs: number,
): PaymentMetadata
payLnurl(lnurl: string, amountMsat: number, waitForPaymentSecs?: number): string
payLnurl(lnurl: string, amountMsat: number, waitForPaymentSecs?: number | undefined | null): string
payBolt11(bolt11Invoice: string): string
payBolt12Offer(bolt12OfferString: string, amountMsat: number): string
payBolt12Offer(bolt12OfferString: string, amountMsat: number, waitForPaymentSecs?: number | undefined | null): string
}
2 changes: 1 addition & 1 deletion npm/android-arm-eabi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-android-arm-eabi",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-android-arm64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-darwin-arm64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-darwin-x64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/freebsd-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-freebsd-x64",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"freebsd"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-linux-arm-gnueabihf",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-linux-arm64-gnu",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-linux-arm64-musl",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-linux-x64-gnu",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-linux-x64-musl",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-win32-arm64-msvc",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-win32-ia32-msvc",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js-win32-x64-msvc",
"version": "0.1.54",
"version": "0.1.55",
"os": [
"win32"
],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moneydevkit/lightning-js",
"version": "0.1.54",
"version": "0.1.55",
"main": "index.js",
"files": [
"index.d.ts",
Expand Down
89 changes: 77 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,17 @@ impl MdkNode {
&self,
bolt12_offer_string: String,
amount_msat: i64,
wait_for_payment_secs: Option<i64>,
Comment on lines 934 to +937

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update TypeScript definition for new wait param

The N-API signature now accepts wait_for_payment_secs, but the shipped TypeScript declarations still expose payBolt12Offer(bolt12OfferString, amountMsat) only (see index.d.ts). That means TS consumers cannot pass the new wait value without type errors, so the new behavior is effectively unusable for typed callers and will break builds that add the third argument. Please regenerate or update index.d.ts to include an optional waitForPaymentSecs?: number for this method.

Useful? React with 👍 / 👎.

) -> napi::Result<String> {
eprintln!(
"[lightning-js] pay_bolt12_offer called amount_msat={} wait_for_payment_secs={:?}",
amount_msat, wait_for_payment_secs
);
eprintln!(
"[lightning-js] pay_bolt12_offer bolt12_offer={}",
bolt12_offer_string
);

if amount_msat <= 0 {
return Err(napi::Error::new(
Status::InvalidArg,
Expand All @@ -949,29 +959,59 @@ impl MdkNode {
)
})?;

let wait_for_payment_secs = wait_for_payment_secs.unwrap_or(0);
let wait_for_payment_secs = if wait_for_payment_secs > 0 {
Some(wait_for_payment_secs as u64)
} else {
None
};
eprintln!(
"[lightning-js] pay_bolt12_offer wait_for_payment_secs_normalized={wait_for_payment_secs:?}"
);

let bolt12_offer = Offer::from_str(&bolt12_offer_string)
.map_err(|_| napi::Error::new(Status::InvalidArg, "invalid bolt12 offer".to_string()))?;

eprintln!(
"[lightning-js] pay_bolt12_offer parsed offer: id={} issuer_pubkey={:?} description={:?} amount={:?}",
bolt12_offer.id(),
bolt12_offer.issuer_signing_pubkey(),
bolt12_offer.description(),
bolt12_offer.amount()
);

eprintln!("[lightning-js] pay_bolt12_offer starting node");
self.node.start().map_err(|error| {
napi::Error::new(
Status::GenericFailure,
format!("failed to start node prior to paying offer: {error}"),
)
})?;

eprintln!("[lightning-js] pay_bolt12_offer syncing wallets");
if let Err(err) = self.node.sync_wallets() {
eprintln!("[lightning-js] Failed to sync wallets: {err}");
panic!("failed to sync wallets: {err}");
}
eprintln!("[lightning-js] pay_bolt12_offer wallet sync complete");

let available_balance_msat: u64 = self
.node
.list_channels()
.into_iter()
let channels = self.node.list_channels();
let ready_channels: Vec<_> = channels
.iter()
.filter(|channel| channel.is_channel_ready)
.collect();
let available_balance_msat: u64 = ready_channels
.iter()
.map(|channel| channel.outbound_capacity_msat)
.sum();

eprintln!(
"[lightning-js] pay_bolt12_offer channels: total={} ready={} available_balance_msat={}",
channels.len(),
ready_channels.len(),
available_balance_msat
);

if available_balance_msat == 0 {
if let Err(err) = self.node.stop() {
eprintln!(
Expand All @@ -998,6 +1038,11 @@ impl MdkNode {
None => amount_msat_u64,
};

eprintln!(
"[lightning-js] pay_bolt12_offer amount_to_send_msat={}",
amount_to_send_msat
);

if amount_to_send_msat == 0 {
if let Err(err) = self.node.stop() {
eprintln!("[lightning-js] Failed to stop node after zero-amount bolt12 offer: {err}");
Expand All @@ -1021,6 +1066,12 @@ impl MdkNode {
));
}

eprintln!(
"[lightning-js] pay_bolt12_offer sending payment: offer_id={} amount_msat={}",
bolt12_offer.id(),
amount_to_send_msat
);

let payment_id = match self.node.bolt12_payment().send_using_amount(
&bolt12_offer,
amount_to_send_msat,
Expand All @@ -1029,6 +1080,7 @@ impl MdkNode {
) {
Ok(payment_id) => payment_id,
Err(error) => {
eprintln!("[lightning-js] pay_bolt12_offer send error: {error}");
if let Err(stop_error) = self.node.stop() {
eprintln!("[lightning-js] Failed to stop node after bolt12 send error: {stop_error}");
}
Expand All @@ -1038,18 +1090,31 @@ impl MdkNode {
));
}
};
eprintln!(
"[lightning-js] pay_bolt12_offer send ok payment_id={}",
bytes_to_hex(&payment_id.0)
);

if let Err(err) = self.node.stop() {
eprintln!("[lightning-js] Failed to stop node after successful bolt12 payment: {err}");
}
if let Some(wait_secs) = wait_for_payment_secs {
eprintln!(
"[lightning-js] pay_bolt12_offer waiting for payment outcome wait_secs={wait_secs}"
);
let wait_result = self.wait_for_payment_outcome(&payment_id, wait_secs);

let payment_id_bytes = payment_id.0;
let mut payment_id_hex = String::with_capacity(payment_id_bytes.len() * 2);
for byte in payment_id_bytes {
write!(&mut payment_id_hex, "{:02x}", byte).unwrap();
if let Err(err) = self.node.stop() {
eprintln!("[lightning-js] Failed to stop node after bolt12 payment wait: {err}");
}

wait_result?;
} else if let Err(err) = self.node.stop() {
eprintln!("[lightning-js] Failed to stop node after successful bolt12 payment: {err}");
}

Ok(payment_id_hex)
eprintln!(
"[lightning-js] pay_bolt12_offer returning payment_id={}",
bytes_to_hex(&payment_id.0)
);
Ok(bytes_to_hex(&payment_id.0))
}
}

Expand Down
Loading