Skip to content

Commit b7f00f7

Browse files
TheBlueMattandozw
authored andcommitted
Support reading the new payment_metadata field in invoices
1 parent ed6f061 commit b7f00f7

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
@@ -459,6 +459,8 @@ impl FromBase32 for TaggedField {
459459
Ok(TaggedField::PrivateRoute(PrivateRoute::from_base32(field_data)?)),
460460
constants::TAG_PAYMENT_SECRET =>
461461
Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
462+
constants::TAG_PAYMENT_METADATA =>
463+
Ok(TaggedField::PaymentMetadata(Vec::<u8>::from_base32(field_data)?)),
462464
constants::TAG_FEATURES =>
463465
Ok(TaggedField::Features(InvoiceFeatures::from_base32(field_data)?)),
464466
_ => {

lightning-invoice/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ pub enum TaggedField {
404404
Fallback(Fallback),
405405
PrivateRoute(PrivateRoute),
406406
PaymentSecret(PaymentSecret),
407+
PaymentMetadata(Vec<u8>),
407408
Features(InvoiceFeatures),
408409
}
409410

@@ -469,6 +470,7 @@ pub mod constants {
469470
pub const TAG_FALLBACK: u8 = 9;
470471
pub const TAG_PRIVATE_ROUTE: u8 = 3;
471472
pub const TAG_PAYMENT_SECRET: u8 = 16;
473+
pub const TAG_PAYMENT_METADATA: u8 = 27;
472474
pub const TAG_FEATURES: u8 = 5;
473475
}
474476

@@ -926,6 +928,10 @@ impl RawInvoice {
926928
find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
927929
}
928930

931+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
932+
find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
933+
}
934+
929935
pub fn features(&self) -> Option<&InvoiceFeatures> {
930936
find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
931937
}
@@ -1188,6 +1194,11 @@ impl Invoice {
11881194
self.signed_invoice.payment_secret().expect("was checked by constructor")
11891195
}
11901196

1197+
/// Get the payment metadata blob if one was included in the invoice
1198+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
1199+
self.signed_invoice.payment_metadata()
1200+
}
1201+
11911202
/// Get the invoice features if they were included in the invoice
11921203
pub fn features(&self) -> Option<&InvoiceFeatures> {
11931204
self.signed_invoice.features()
@@ -1290,6 +1301,7 @@ impl TaggedField {
12901301
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
12911302
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
12921303
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
1304+
TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
12931305
TaggedField::Features(_) => constants::TAG_FEATURES,
12941306
};
12951307

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)