Skip to content

Commit 92d5d83

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 78a006b commit 92d5d83

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

@@ -937,6 +939,10 @@ impl RawInvoice {
937939
find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
938940
}
939941

942+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
943+
find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
944+
}
945+
940946
pub fn features(&self) -> Option<&InvoiceFeatures> {
941947
find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
942948
}
@@ -1203,6 +1209,11 @@ impl Invoice {
12031209
self.signed_invoice.payment_secret().expect("was checked by constructor")
12041210
}
12051211

1212+
/// Get the payment metadata blob if one was included in the invoice
1213+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
1214+
self.signed_invoice.payment_metadata()
1215+
}
1216+
12061217
/// Get the invoice features if they were included in the invoice
12071218
pub fn features(&self) -> Option<&InvoiceFeatures> {
12081219
self.signed_invoice.features()
@@ -1305,6 +1316,7 @@ impl TaggedField {
13051316
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
13061317
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
13071318
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
1319+
TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
13081320
TaggedField::Features(_) => constants::TAG_FEATURES,
13091321
};
13101322

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)