]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Support reading the new `payment_metadata` field in invoices
authorMatt Corallo <git@bluematt.me>
Tue, 21 Dec 2021 05:25:18 +0000 (05:25 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Jan 2022 19:08:58 +0000 (19:08 +0000)
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/ser.rs

index 9e96849a274c24d9ba1a08845b8d69622c75a4ff..28b901d8384ec678149ee434610129d3c30140ac 100644 (file)
@@ -459,6 +459,8 @@ impl FromBase32 for TaggedField {
                                Ok(TaggedField::PrivateRoute(PrivateRoute::from_base32(field_data)?)),
                        constants::TAG_PAYMENT_SECRET =>
                                Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
+                       constants::TAG_PAYMENT_METADATA =>
+                               Ok(TaggedField::PaymentMetadata(Vec::<u8>::from_base32(field_data)?)),
                        constants::TAG_FEATURES =>
                                Ok(TaggedField::Features(InvoiceFeatures::from_base32(field_data)?)),
                        _ => {
index 6987fdeb14309f543f830e3de98cabc339eaccf2..73965211004a228324c73ad33144e6a0f1814cac 100644 (file)
@@ -362,6 +362,7 @@ pub enum TaggedField {
        Fallback(Fallback),
        PrivateRoute(PrivateRoute),
        PaymentSecret(PaymentSecret),
+       PaymentMetadata(Vec<u8>),
        Features(InvoiceFeatures),
 }
 
@@ -427,6 +428,7 @@ pub mod constants {
        pub const TAG_FALLBACK: u8 = 9;
        pub const TAG_PRIVATE_ROUTE: u8 = 3;
        pub const TAG_PAYMENT_SECRET: u8 = 16;
+       pub const TAG_PAYMENT_METADATA: u8 = 27;
        pub const TAG_FEATURES: u8 = 5;
 }
 
@@ -886,6 +888,10 @@ impl RawInvoice {
                find_extract!(self.known_tagged_fields(), TaggedField::PaymentSecret(ref x), x)
        }
 
+       pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
+               find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
+       }
+
        pub fn features(&self) -> Option<&InvoiceFeatures> {
                find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
        }
@@ -1148,6 +1154,11 @@ impl Invoice {
                self.signed_invoice.payment_secret().expect("was checked by constructor")
        }
 
+       /// Get the payment metadata blob if one was included in the invoice
+       pub fn payment_metadata(&self) -> Option<&Vec<u8>> {
+               self.signed_invoice.payment_metadata()
+       }
+
        /// Get the invoice features if they were included in the invoice
        pub fn features(&self) -> Option<&InvoiceFeatures> {
                self.signed_invoice.features()
@@ -1250,6 +1261,7 @@ impl TaggedField {
                        TaggedField::Fallback(_) => constants::TAG_FALLBACK,
                        TaggedField::PrivateRoute(_) => constants::TAG_PRIVATE_ROUTE,
                        TaggedField::PaymentSecret(_) => constants::TAG_PAYMENT_SECRET,
+                       TaggedField::PaymentMetadata(_) => constants::TAG_PAYMENT_METADATA,
                        TaggedField::Features(_) => constants::TAG_FEATURES,
                };
 
index f921a5b0f6959a832c0eea01c915635ba1820859..24ec882f25a7d10419e730f4ee3d3b56c00a9d60 100644 (file)
@@ -446,6 +446,9 @@ impl ToBase32 for TaggedField {
                        TaggedField::PaymentSecret(ref payment_secret) => {
                                  write_tagged_field(writer, constants::TAG_PAYMENT_SECRET, payment_secret)
                        },
+                       TaggedField::PaymentMetadata(ref payment_metadata) => {
+                                 write_tagged_field(writer, constants::TAG_PAYMENT_METADATA, payment_metadata)
+                       },
                        TaggedField::Features(ref features) => {
                                write_tagged_field(writer, constants::TAG_FEATURES, features)
                        },