Skip to content

Commit 7809799

Browse files
committed
feat: add bolt11 field to PaymentDetails
Store the full BOLT11 invoice string in `PaymentKind` variants to allow retrieval of the original invoice after payment creation. - Add optional `bolt11: Option<String>` field to `PaymentKind::Bolt11` and `PaymentKind::Bolt11Jit` - Update all payment creation flows to persist the original BOLT11 invoice string - Expose `bolt11` field in FFI/uniffi bindings - Maintain backward compatibility by defaulting to `None` for older/legacy payments
1 parent 794b209 commit 7809799

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

bindings/ldk_node.udl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ interface ClosureReason {
429429
[Enum]
430430
interface PaymentKind {
431431
Onchain(Txid txid, ConfirmationStatus status);
432-
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, string? description);
433-
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, u64? counterparty_skimmed_fee_msat, LSPFeeLimits lsp_fee_limits, string? description);
432+
Bolt11(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, string? description, string? bolt11);
433+
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, u64? counterparty_skimmed_fee_msat, LSPFeeLimits lsp_fee_limits, string? description, string? bolt11);
434434
Bolt12Offer(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, OfferId offer_id, UntrustedString? payer_note, u64? quantity);
435435
Bolt12Refund(PaymentHash? hash, PaymentPreimage? preimage, PaymentSecret? secret, UntrustedString? payer_note, u64? quantity);
436436
Spontaneous(PaymentHash hash, PaymentPreimage? preimage);

src/payment/bolt11.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl Bolt11Payment {
189189
preimage: None,
190190
secret: payment_secret,
191191
description,
192+
bolt11: Some(invoice.to_string()),
192193
};
193194
let payment = PaymentDetails::new(
194195
payment_id,
@@ -221,6 +222,7 @@ impl Bolt11Payment {
221222
preimage: None,
222223
secret: payment_secret,
223224
description,
225+
bolt11: Some(invoice.to_string()),
224226
};
225227
let payment = PaymentDetails::new(
226228
payment_id,
@@ -342,6 +344,7 @@ impl Bolt11Payment {
342344
preimage: None,
343345
secret: Some(*payment_secret),
344346
description,
347+
bolt11: Some(invoice.to_string()),
345348
};
346349

347350
let payment = PaymentDetails::new(
@@ -375,6 +378,7 @@ impl Bolt11Payment {
375378
preimage: None,
376379
secret: Some(*payment_secret),
377380
description,
381+
bolt11: Some(invoice.to_string()),
378382
};
379383
let payment = PaymentDetails::new(
380384
payment_id,
@@ -619,6 +623,7 @@ impl Bolt11Payment {
619623
preimage,
620624
secret: Some(payment_secret.clone()),
621625
description,
626+
bolt11: Some(invoice.to_string()),
622627
};
623628
let payment = PaymentDetails::new(
624629
id,
@@ -767,6 +772,7 @@ impl Bolt11Payment {
767772
counterparty_skimmed_fee_msat: None,
768773
lsp_fee_limits,
769774
description,
775+
bolt11: Some(invoice.to_string()),
770776
};
771777
let payment = PaymentDetails::new(
772778
id,

src/payment/store.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ impl Readable for PaymentDetails {
139139
counterparty_skimmed_fee_msat,
140140
lsp_fee_limits,
141141
description: None,
142+
bolt11: None,
142143
}
143144
} else {
144-
PaymentKind::Bolt11 { hash, preimage, secret, description: None }
145+
PaymentKind::Bolt11 { hash, preimage, secret, description: None, bolt11: None }
145146
}
146147
} else {
147148
PaymentKind::Spontaneous { hash, preimage }
@@ -367,6 +368,8 @@ pub enum PaymentKind {
367368
secret: Option<PaymentSecret>,
368369
/// The description from the BOLT 11 invoice.
369370
description: Option<String>,
371+
/// The BOLT 11 invoice string.
372+
bolt11: Option<String>,
370373
},
371374
/// A [BOLT 11] payment intended to open an [bLIP-52 / LSPS 2] just-in-time channel.
372375
///
@@ -396,6 +399,8 @@ pub enum PaymentKind {
396399
lsp_fee_limits: LSPFeeLimits,
397400
/// The description from the BOLT 11 invoice.
398401
description: Option<String>,
402+
/// The BOLT 11 invoice string.
403+
bolt11: Option<String>,
399404
},
400405
/// A [BOLT 12] 'offer' payment, i.e., a payment for an [`Offer`].
401406
///
@@ -462,6 +467,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
462467
(2, preimage, option),
463468
(4, secret, option),
464469
(6, description, option),
470+
(8, bolt11, option),
465471
},
466472
(4, Bolt11Jit) => {
467473
(0, hash, required),
@@ -470,6 +476,7 @@ impl_writeable_tlv_based_enum!(PaymentKind,
470476
(4, secret, option),
471477
(6, lsp_fee_limits, required),
472478
(8, description, option),
479+
(10, bolt11, option),
473480
},
474481
(6, Bolt12Offer) => {
475482
(0, hash, option),
@@ -677,7 +684,7 @@ mod tests {
677684
);
678685

679686
match bolt11_decoded.kind {
680-
PaymentKind::Bolt11 { hash: h, preimage: p, secret: s, description: _ } => {
687+
PaymentKind::Bolt11 { hash: h, preimage: p, secret: s, description: _, bolt11: _ } => {
681688
assert_eq!(hash, h);
682689
assert_eq!(preimage, p);
683690
assert_eq!(secret, s);
@@ -727,6 +734,7 @@ mod tests {
727734
counterparty_skimmed_fee_msat: c,
728735
lsp_fee_limits: l,
729736
description: _,
737+
bolt11: _,
730738
} => {
731739
assert_eq!(hash, h);
732740
assert_eq!(preimage, p);

0 commit comments

Comments
 (0)