@@ -29,7 +29,7 @@ use crate::offers::merkle::{
29
29
use crate :: offers:: nonce:: Nonce ;
30
30
use crate :: offers:: offer:: {
31
31
Amount , ExperimentalOfferTlvStream , ExperimentalOfferTlvStreamRef , Offer , OfferContents ,
32
- OfferTlvStream , OfferTlvStreamRef , Quantity , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES ,
32
+ OfferId , OfferTlvStream , OfferTlvStreamRef , Quantity , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES ,
33
33
} ;
34
34
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
35
35
use crate :: types:: features:: { Bolt12InvoiceFeatures , OfferFeatures } ;
@@ -70,6 +70,7 @@ pub struct StaticInvoice {
70
70
bytes : Vec < u8 > ,
71
71
contents : InvoiceContents ,
72
72
signature : Signature ,
73
+ offer_id : Option < OfferId > ,
73
74
}
74
75
75
76
impl PartialEq for StaticInvoice {
@@ -198,6 +199,7 @@ pub struct UnsignedStaticInvoice {
198
199
experimental_bytes : Vec < u8 > ,
199
200
contents : InvoiceContents ,
200
201
tagged_hash : TaggedHash ,
202
+ offer_id : Option < OfferId > ,
201
203
}
202
204
203
205
macro_rules! invoice_accessors { ( $self: ident, $contents: expr) => {
@@ -330,7 +332,9 @@ impl UnsignedStaticInvoice {
330
332
let tlv_stream = TlvStream :: new ( & bytes) . chain ( TlvStream :: new ( & experimental_bytes) ) ;
331
333
let tagged_hash = TaggedHash :: from_tlv_stream ( SIGNATURE_TAG , tlv_stream) ;
332
334
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) }
334
338
}
335
339
336
340
/// Signs the [`TaggedHash`] of the invoice using the given function.
@@ -347,7 +351,13 @@ impl UnsignedStaticInvoice {
347
351
// Append the experimental bytes after the signature.
348
352
self . bytes . extend_from_slice ( & self . experimental_bytes ) ;
349
353
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
+ } )
351
361
}
352
362
353
363
invoice_accessors_common ! ( self , self . contents, UnsignedStaticInvoice ) ;
@@ -627,7 +637,8 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for StaticInvoice {
627
637
let pubkey = contents. signing_pubkey ;
628
638
merkle:: verify_signature ( & signature, & tagged_hash, pubkey) ?;
629
639
630
- Ok ( StaticInvoice { bytes, contents, signature } )
640
+ let offer_id = OfferId :: from_valid_bolt12_tlv_stream ( & bytes) ;
641
+ Ok ( StaticInvoice { bytes, contents, signature, offer_id : Some ( offer_id) } )
631
642
}
632
643
}
633
644
0 commit comments