Skip to content

Commit fd80114

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 11dec5c commit fd80114

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
@@ -457,6 +457,8 @@ impl FromBase32 for TaggedField {
457457
Ok(TaggedField::PrivateRoute(PrivateRoute::from_base32(field_data)?)),
458458
constants::TAG_PAYMENT_SECRET =>
459459
Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
460+
constants::TAG_PAYMENT_METADATA =>
461+
Ok(TaggedField::PaymentMetadata(Vec::<u8>::from_base32(field_data)?)),
460462
constants::TAG_FEATURES =>
461463
Ok(TaggedField::Features(InvoiceFeatures::from_base32(field_data)?)),
462464
_ => {

lightning-invoice/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ pub enum TaggedField {
414414
Fallback(Fallback),
415415
PrivateRoute(PrivateRoute),
416416
PaymentSecret(PaymentSecret),
417+
PaymentMetadata(Vec<u8>),
417418
Features(InvoiceFeatures),
418419
}
419420

@@ -479,6 +480,7 @@ pub mod constants {
479480
pub const TAG_FALLBACK: u8 = 9;
480481
pub const TAG_PRIVATE_ROUTE: u8 = 3;
481482
pub const TAG_PAYMENT_SECRET: u8 = 16;
483+
pub const TAG_PAYMENT_METADATA: u8 = 27;
482484
pub const TAG_FEATURES: u8 = 5;
483485
}
484486

@@ -949,6 +951,10 @@ impl RawInvoice {
949951
find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
950952
}
951953

954+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
955+
find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
956+
}
957+
952958
pub fn features(&self) -> Option<&InvoiceFeatures> {
953959
find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
954960
}
@@ -1215,6 +1221,11 @@ impl Invoice {
12151221
self.signed_invoice.payment_secret().expect("was checked by constructor")
12161222
}
12171223

1224+
/// Get the payment metadata blob if one was included in the invoice
1225+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
1226+
self.signed_invoice.payment_metadata()
1227+
}
1228+
12181229
/// Get the invoice features if they were included in the invoice
12191230
pub fn features(&self) -> Option<&InvoiceFeatures> {
12201231
self.signed_invoice.features()
@@ -1337,6 +1348,7 @@ impl TaggedField {
13371348
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
13381349
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
13391350
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
1351+
TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
13401352
TaggedField::Features(_) => constants::TAG_FEATURES,
13411353
};
13421354

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)