Skip to content

Commit d11f57b

Browse files
committed
Support reading the new payment_metadata field in invoices
1 parent 6a83450 commit d11f57b

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

lightning-invoice/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ pub enum TaggedField {
374374
Fallback(Fallback),
375375
PrivateRoute(PrivateRoute),
376376
PaymentSecret(PaymentSecret),
377+
PaymentMetadata(Vec<u8>),
377378
Features(InvoiceFeatures),
378379
}
379380

@@ -444,6 +445,7 @@ pub mod constants {
444445
pub const TAG_FALLBACK: u8 = 9;
445446
pub const TAG_PRIVATE_ROUTE: u8 = 3;
446447
pub const TAG_PAYMENT_SECRET: u8 = 16;
448+
pub const TAG_PAYMENT_METADATA: u8 = 27;
447449
pub const TAG_FEATURES: u8 = 5;
448450
}
449451

@@ -917,6 +919,10 @@ impl RawInvoice {
917919
find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
918920
}
919921

922+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
923+
find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
924+
}
925+
920926
pub fn features(&self) -> Option<&InvoiceFeatures> {
921927
find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
922928
}
@@ -1172,6 +1178,11 @@ impl Invoice {
11721178
self.signed_invoice.payment_secret().expect("was checked by constructor")
11731179
}
11741180

1181+
/// Get the payment metadata blob if one was included in the invoice
1182+
pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
1183+
self.signed_invoice.payment_metadata()
1184+
}
1185+
11751186
/// Get the invoice features if they were included in the invoice
11761187
pub fn features(&self) -> Option<&InvoiceFeatures> {
11771188
self.signed_invoice.features()
@@ -1264,6 +1275,7 @@ impl TaggedField {
12641275
TaggedField::Fallback(_) => constants::TAG_FALLBACK,
12651276
TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
12661277
TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
1278+
TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
12671279
TaggedField::Features(_) => constants::TAG_FEATURES,
12681280
};
12691281

lightning-invoice/src/ser.rs

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

0 commit comments

Comments
 (0)