Skip to content

Commit 49b0fe4

Browse files
committed
feat: add description field to BOLT11 payments
- Extract and store description from BOLT11 invoices in PaymentKind::Bolt11 and PaymentKind::Bolt11Jit variants.
1 parent 4131285 commit 49b0fe4

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-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);
433-
Bolt11Jit(PaymentHash hash, PaymentPreimage? preimage, PaymentSecret? secret, u64? counterparty_skimmed_fee_msat, LSPFeeLimits lsp_fee_limits);
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);
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,19 @@ impl Bolt11Payment {
176176
let amt_msat = invoice.amount_milli_satoshis().unwrap();
177177
log_info!(self.logger, "Initiated sending {}msat to {}", amt_msat, payee_pubkey);
178178

179+
// Extract description from the invoice
180+
let description = match invoice.description() {
181+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
182+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
183+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
184+
},
185+
};
186+
179187
let kind = PaymentKind::Bolt11 {
180188
hash: payment_hash,
181189
preimage: None,
182190
secret: payment_secret,
191+
description,
183192
};
184193
let payment = PaymentDetails::new(
185194
payment_id,
@@ -199,10 +208,19 @@ impl Bolt11Payment {
199208
match e {
200209
RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment),
201210
_ => {
211+
// Extract description from the invoice
212+
let description = match invoice.description() {
213+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
214+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
215+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
216+
},
217+
};
218+
202219
let kind = PaymentKind::Bolt11 {
203220
hash: payment_hash,
204221
preimage: None,
205222
secret: payment_secret,
223+
description,
206224
};
207225
let payment = PaymentDetails::new(
208226
payment_id,
@@ -311,10 +329,19 @@ impl Bolt11Payment {
311329
payee_pubkey
312330
);
313331

332+
// Extract description from the invoice
333+
let description = match invoice.description() {
334+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
335+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
336+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
337+
},
338+
};
339+
314340
let kind = PaymentKind::Bolt11 {
315341
hash: payment_hash,
316342
preimage: None,
317343
secret: Some(*payment_secret),
344+
description,
318345
};
319346

320347
let payment = PaymentDetails::new(
@@ -335,10 +362,19 @@ impl Bolt11Payment {
335362
match e {
336363
RetryableSendFailure::DuplicatePayment => Err(Error::DuplicatePayment),
337364
_ => {
365+
// Extract description from the invoice
366+
let description = match invoice.description() {
367+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
368+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
369+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
370+
},
371+
};
372+
338373
let kind = PaymentKind::Bolt11 {
339374
hash: payment_hash,
340375
preimage: None,
341376
secret: Some(*payment_secret),
377+
description,
342378
};
343379
let payment = PaymentDetails::new(
344380
payment_id,
@@ -569,10 +605,20 @@ impl Bolt11Payment {
569605
} else {
570606
None
571607
};
608+
609+
// Extract description from the invoice
610+
let description = match invoice.description() {
611+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
612+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
613+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
614+
},
615+
};
616+
572617
let kind = PaymentKind::Bolt11 {
573618
hash: payment_hash,
574619
preimage,
575620
secret: Some(payment_secret.clone()),
621+
description,
576622
};
577623
let payment = PaymentDetails::new(
578624
id,
@@ -705,12 +751,22 @@ impl Bolt11Payment {
705751
let id = PaymentId(payment_hash.0);
706752
let preimage =
707753
self.channel_manager.get_payment_preimage(payment_hash, payment_secret.clone()).ok();
754+
755+
// Extract description from the invoice
756+
let description = match invoice.description() {
757+
lightning_invoice::Bolt11InvoiceDescriptionRef::Direct(desc) => Some(desc.to_string()),
758+
lightning_invoice::Bolt11InvoiceDescriptionRef::Hash(hash) => {
759+
Some(crate::hex_utils::to_string(hash.0.as_ref()))
760+
},
761+
};
762+
708763
let kind = PaymentKind::Bolt11Jit {
709764
hash: payment_hash,
710765
preimage,
711766
secret: Some(payment_secret.clone()),
712767
counterparty_skimmed_fee_msat: None,
713768
lsp_fee_limits,
769+
description,
714770
};
715771
let payment = PaymentDetails::new(
716772
id,

src/payment/store.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ impl Readable for PaymentDetails {
138138
secret,
139139
counterparty_skimmed_fee_msat,
140140
lsp_fee_limits,
141+
description: None,
141142
}
142143
} else {
143-
PaymentKind::Bolt11 { hash, preimage, secret }
144+
PaymentKind::Bolt11 { hash, preimage, secret, description: None }
144145
}
145146
} else {
146147
PaymentKind::Spontaneous { hash, preimage }
@@ -364,6 +365,8 @@ pub enum PaymentKind {
364365
preimage: Option<PaymentPreimage>,
365366
/// The secret used by the payment.
366367
secret: Option<PaymentSecret>,
368+
/// The description from the BOLT 11 invoice.
369+
description: Option<String>,
367370
},
368371
/// A [BOLT 11] payment intended to open an [bLIP-52 / LSPS 2] just-in-time channel.
369372
///
@@ -391,6 +394,8 @@ pub enum PaymentKind {
391394
///
392395
/// [`LdkChannelConfig::accept_underpaying_htlcs`]: lightning::util::config::ChannelConfig::accept_underpaying_htlcs
393396
lsp_fee_limits: LSPFeeLimits,
397+
/// The description from the BOLT 11 invoice.
398+
description: Option<String>,
394399
},
395400
/// A [BOLT 12] 'offer' payment, i.e., a payment for an [`Offer`].
396401
///
@@ -456,13 +461,15 @@ impl_writeable_tlv_based_enum!(PaymentKind,
456461
(0, hash, required),
457462
(2, preimage, option),
458463
(4, secret, option),
464+
(6, description, option),
459465
},
460466
(4, Bolt11Jit) => {
461467
(0, hash, required),
462468
(1, counterparty_skimmed_fee_msat, option),
463469
(2, preimage, option),
464470
(4, secret, option),
465471
(6, lsp_fee_limits, required),
472+
(8, description, option),
466473
},
467474
(6, Bolt12Offer) => {
468475
(0, hash, option),
@@ -670,7 +677,7 @@ mod tests {
670677
);
671678

672679
match bolt11_decoded.kind {
673-
PaymentKind::Bolt11 { hash: h, preimage: p, secret: s } => {
680+
PaymentKind::Bolt11 { hash: h, preimage: p, secret: s, description: _ } => {
674681
assert_eq!(hash, h);
675682
assert_eq!(preimage, p);
676683
assert_eq!(secret, s);
@@ -719,6 +726,7 @@ mod tests {
719726
secret: s,
720727
counterparty_skimmed_fee_msat: c,
721728
lsp_fee_limits: l,
729+
description: _,
722730
} => {
723731
assert_eq!(hash, h);
724732
assert_eq!(preimage, p);

0 commit comments

Comments
 (0)