]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add OffersMessage variant for static invoices.
authorValentine Wallace <vwallace@protonmail.com>
Wed, 29 May 2024 18:48:05 +0000 (14:48 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 20 Jun 2024 18:24:09 +0000 (14:24 -0400)
lightning/src/ln/channelmanager.rs
lightning/src/ln/offers_tests.rs
lightning/src/onion_message/offers.rs

index 274edf6d7b4238495eb87390bb8453ad76ca3a8b..f189aee04cf75b2933a5f1508ec065b4b1356104 100644 (file)
@@ -10337,6 +10337,16 @@ where
                                        },
                                }
                        },
+                       OffersMessage::StaticInvoice(_invoice) => {
+                               match responder {
+                                       Some(responder) => {
+                                               responder.respond(OffersMessage::InvoiceError(
+                                                               InvoiceError::from_string("Static invoices not yet supported".to_string())
+                                               ))
+                                       },
+                                       None => return ResponseInstruction::NoResponse,
+                               }
+                       },
                        OffersMessage::InvoiceError(invoice_error) => {
                                log_trace!(self.logger, "Received invoice_error: {}", invoice_error);
                                ResponseInstruction::NoResponse
index c965ba50e8d3d4345dd6bb891fdf004a33e75a76..10ebd599bde528a1882f2fd975107f088e542ae4 100644 (file)
@@ -192,6 +192,7 @@ fn extract_invoice_request<'a, 'b, 'c>(
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path.unwrap()),
                                OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
+                               OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
                        },
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
@@ -208,6 +209,7 @@ fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage)
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
                                OffersMessage::Invoice(invoice) => invoice,
+                               OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
                        },
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
@@ -226,6 +228,7 @@ fn extract_invoice_error<'a, 'b, 'c>(
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
                                OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
+                               OffersMessage::StaticInvoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => error,
                        },
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
index 42c6914157e74f345ed0d2ad354834262653646a..52dacd84e3d4a9d15dadc881c6dcb18b0e0a8651 100644 (file)
@@ -16,6 +16,7 @@ use crate::offers::invoice_error::InvoiceError;
 use crate::offers::invoice_request::InvoiceRequest;
 use crate::offers::invoice::Bolt12Invoice;
 use crate::offers::parse::Bolt12ParseError;
+use crate::offers::static_invoice::StaticInvoice;
 use crate::onion_message::packet::OnionMessageContents;
 use crate::util::logger::Logger;
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
@@ -29,6 +30,7 @@ use crate::prelude::*;
 const INVOICE_REQUEST_TLV_TYPE: u64 = 64;
 const INVOICE_TLV_TYPE: u64 = 66;
 const INVOICE_ERROR_TLV_TYPE: u64 = 68;
+const STATIC_INVOICE_TLV_TYPE: u64 = 70;
 
 /// A handler for an [`OnionMessage`] containing a BOLT 12 Offers message as its payload.
 ///
@@ -72,6 +74,9 @@ pub enum OffersMessage {
        /// [`Refund`]: crate::offers::refund::Refund
        Invoice(Bolt12Invoice),
 
+       /// A `StaticInvoice` sent in response to an [`InvoiceRequest`].
+       StaticInvoice(StaticInvoice),
+
        /// An error from handling an [`OffersMessage`].
        InvoiceError(InvoiceError),
 }
@@ -80,7 +85,10 @@ impl OffersMessage {
        /// Returns whether `tlv_type` corresponds to a TLV record for Offers.
        pub fn is_known_type(tlv_type: u64) -> bool {
                match tlv_type {
-                       INVOICE_REQUEST_TLV_TYPE | INVOICE_TLV_TYPE | INVOICE_ERROR_TLV_TYPE => true,
+                       INVOICE_REQUEST_TLV_TYPE
+                       | INVOICE_TLV_TYPE
+                       | STATIC_INVOICE_TLV_TYPE
+                       | INVOICE_ERROR_TLV_TYPE => true,
                        _ => false,
                }
        }
@@ -89,6 +97,7 @@ impl OffersMessage {
                match tlv_type {
                        INVOICE_REQUEST_TLV_TYPE => Ok(Self::InvoiceRequest(InvoiceRequest::try_from(bytes)?)),
                        INVOICE_TLV_TYPE => Ok(Self::Invoice(Bolt12Invoice::try_from(bytes)?)),
+                       STATIC_INVOICE_TLV_TYPE => Ok(Self::StaticInvoice(StaticInvoice::try_from(bytes)?)),
                        _ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
@@ -103,6 +112,9 @@ impl fmt::Debug for OffersMessage {
                        OffersMessage::Invoice(message) => {
                                write!(f, "{:?}", message.as_tlv_stream())
                        }
+                       OffersMessage::StaticInvoice(message) => {
+                               write!(f, "{:?}", message)
+                       }
                        OffersMessage::InvoiceError(message) => {
                                write!(f, "{:?}", message)
                        }
@@ -115,6 +127,7 @@ impl OnionMessageContents for OffersMessage {
                match self {
                        OffersMessage::InvoiceRequest(_) => INVOICE_REQUEST_TLV_TYPE,
                        OffersMessage::Invoice(_) => INVOICE_TLV_TYPE,
+                       OffersMessage::StaticInvoice(_) => STATIC_INVOICE_TLV_TYPE,
                        OffersMessage::InvoiceError(_) => INVOICE_ERROR_TLV_TYPE,
                }
        }
@@ -122,6 +135,7 @@ impl OnionMessageContents for OffersMessage {
                match &self {
                        OffersMessage::InvoiceRequest(_) => "Invoice Request",
                        OffersMessage::Invoice(_) => "Invoice",
+                       OffersMessage::StaticInvoice(_) => "Static Invoice",
                        OffersMessage::InvoiceError(_) => "Invoice Error",
                }
        }
@@ -132,6 +146,7 @@ impl Writeable for OffersMessage {
                match self {
                        OffersMessage::InvoiceRequest(message) => message.write(w),
                        OffersMessage::Invoice(message) => message.write(w),
+                       OffersMessage::StaticInvoice(message) => message.write(w),
                        OffersMessage::InvoiceError(message) => message.write(w),
                }
        }