@@ -29,7 +29,7 @@ use crate::offers::merkle::{
2929use crate :: offers:: nonce:: Nonce ;
3030use crate :: offers:: offer:: {
3131 Amount , ExperimentalOfferTlvStream , ExperimentalOfferTlvStreamRef , Offer , OfferContents ,
32- OfferTlvStream , OfferTlvStreamRef , Quantity , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES ,
32+ OfferId , OfferTlvStream , OfferTlvStreamRef , Quantity , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES ,
3333} ;
3434use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
3535use crate :: types:: features:: { Bolt12InvoiceFeatures , OfferFeatures } ;
@@ -70,6 +70,7 @@ pub struct StaticInvoice {
7070 bytes : Vec < u8 > ,
7171 contents : InvoiceContents ,
7272 signature : Signature ,
73+ offer_id : Option < OfferId > ,
7374}
7475
7576impl PartialEq for StaticInvoice {
@@ -198,6 +199,7 @@ pub struct UnsignedStaticInvoice {
198199 experimental_bytes : Vec < u8 > ,
199200 contents : InvoiceContents ,
200201 tagged_hash : TaggedHash ,
202+ offer_id : Option < OfferId > ,
201203}
202204
203205macro_rules! invoice_accessors { ( $self: ident, $contents: expr) => {
@@ -330,7 +332,9 @@ impl UnsignedStaticInvoice {
330332 let tlv_stream = TlvStream :: new ( & bytes) . chain ( TlvStream :: new ( & experimental_bytes) ) ;
331333 let tagged_hash = TaggedHash :: from_tlv_stream ( SIGNATURE_TAG , tlv_stream) ;
332334
333- Self { bytes, experimental_bytes, contents, tagged_hash }
335+ // FIXME: we can have a static invoice for a Refund? if yes this should be optional
336+ let offer_id = OfferId :: from_valid_bolt12_tlv_stream ( & bytes) ;
337+ Self { bytes, experimental_bytes, contents, tagged_hash, offer_id : Some ( offer_id) }
334338 }
335339
336340 /// Signs the [`TaggedHash`] of the invoice using the given function.
@@ -347,7 +351,13 @@ impl UnsignedStaticInvoice {
347351 // Append the experimental bytes after the signature.
348352 self . bytes . extend_from_slice ( & self . experimental_bytes ) ;
349353
350- Ok ( StaticInvoice { bytes : self . bytes , contents : self . contents , signature } )
354+ let offer_id = OfferId :: from_valid_bolt12_tlv_stream ( & self . bytes ) ;
355+ Ok ( StaticInvoice {
356+ bytes : self . bytes ,
357+ contents : self . contents ,
358+ signature,
359+ offer_id : Some ( offer_id) ,
360+ } )
351361 }
352362
353363 invoice_accessors_common ! ( self , self . contents, UnsignedStaticInvoice ) ;
@@ -627,7 +637,9 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for StaticInvoice {
627637 let pubkey = contents. signing_pubkey ;
628638 merkle:: verify_signature ( & signature, & tagged_hash, pubkey) ?;
629639
630- Ok ( StaticInvoice { bytes, contents, signature } )
640+ // this is coming always from an offer, so this is always Some.
641+ let offer_id = OfferId :: from_valid_bolt12_tlv_stream ( & bytes) ;
642+ Ok ( StaticInvoice { bytes, contents, signature, offer_id : Some ( offer_id) } )
631643 }
632644}
633645
0 commit comments