Skip to content

Commit 928c9b8

Browse files
committed
Support reading the new payment_metadata field in invoices
This adds support for reading the new `PaymentMetadata` BOLT11 invoice field, giving us access to the `Vec<u8>` storing arbitrary bytes we have to send to the recipient.
1 parent 1b29a55 commit 928c9b8

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lightning-invoice/src/de.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ impl FromBase32 for TaggedField {
460460
Ok(TaggedField::PrivateRoute(PrivateRoute::from_base32(field_data)?)),
461461
constants::TAG_PAYMENT_SECRET =>
462462
Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
463+
constants::TAG_PAYMENT_METADATA =>
464+
Ok(TaggedField::PaymentMetadata(Vec::<u8>::from_base32(field_data)?)),
463465
constants::TAG_FEATURES =>
464466
Ok(TaggedField::Features(InvoiceFeatures::from_base32(field_data)?)),
465467
_ => {

lightning-invoice/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ pub enum TaggedField {
419419
Fallback(Fallback),
420420
PrivateRoute(PrivateRoute),
421421
PaymentSecret(PaymentSecret),
422+
PaymentMetadata(Vec<u8>),
422423
Features(InvoiceFeatures),
423424
}
424425

@@ -483,6 +484,7 @@ pub mod constants {
483484
pub const TAG_FALLBACK: u8 = 9;
484485
pub const TAG_PRIVATE_ROUTE: u8 = 3;
485486
pub const TAG_PAYMENT_SECRET: u8 = 16;
487+
pub const TAG_PAYMENT_METADATA: u8 = 27;
486488
pub const TAG_FEATURES: u8 = 5;
487489
}
488490

@@ -954,6 +956,10 @@ impl RawInvoice {
954956
find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
955957
}
956958

959+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
960+
find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
961+
}
962+
957963
pub fn features(&self) -> Option<&InvoiceFeatures> {
958964
find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
959965
}
@@ -1225,6 +1231,11 @@ impl Invoice {
12251231
self.signed_invoice.payment_secret().expect("was checked by constructor")
12261232
}
12271233

1234+
/// Get the payment metadata blob if one was included in the invoice
1235+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
1236+
self.signed_invoice.payment_metadata()
1237+
}
1238+
12281239
/// Get the invoice features if they were included in the invoice
12291240
pub fn features(&self) -> Option<&InvoiceFeatures> {
12301241
self.signed_invoice.features()
@@ -1374,6 +1385,7 @@ impl TaggedField {
13741385
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
13751386
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
13761387
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
1388+
TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
13771389
TaggedField::Features(_) => constants::TAG_FEATURES,
13781390
};
13791391

lightning-invoice/src/ser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ impl ToBase32 for TaggedField {
446446
TaggedField::PaymentSecret(ref payment_secret) => {
447447
write_tagged_field(writer, constants::TAG_PAYMENT_SECRET, payment_secret)
448448
},
449+
TaggedField::PaymentMetadata(ref payment_metadata) => {
450+
write_tagged_field(writer, constants::TAG_PAYMENT_METADATA, payment_metadata)
451+
},
449452
TaggedField::Features(ref features) => {
450453
write_tagged_field(writer, constants::TAG_FEATURES, features)
451454
},

0 commit comments

Comments
 (0)