@@ -23,7 +23,9 @@ use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_me
23
23
use crate :: offers:: merkle:: {
24
24
self , SignError , SignFn , SignatureTlvStream , SignatureTlvStreamRef , TaggedHash ,
25
25
} ;
26
- use crate :: offers:: offer:: { Amount , Offer , OfferContents , OfferTlvStream , Quantity } ;
26
+ use crate :: offers:: offer:: {
27
+ Amount , Offer , OfferContents , OfferTlvStream , OfferTlvStreamRef , Quantity ,
28
+ } ;
27
29
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
28
30
use crate :: util:: ser:: {
29
31
HighZeroBytesDroppedBigSize , Iterable , SeekReadable , WithoutLength , Writeable , Writer ,
@@ -243,11 +245,15 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => {
243
245
244
246
impl UnsignedStaticInvoice {
245
247
fn new ( offer_bytes : & Vec < u8 > , contents : InvoiceContents ) -> Self {
248
+ let ( _, invoice_tlv_stream) = contents. as_tlv_stream ( ) ;
249
+ let offer_bytes = WithoutLength ( offer_bytes) ;
250
+ let unsigned_tlv_stream = ( offer_bytes, invoice_tlv_stream) ;
251
+
246
252
let mut bytes = Vec :: new ( ) ;
247
- WithoutLength ( offer_bytes) . write ( & mut bytes) . unwrap ( ) ;
248
- contents. as_invoice_fields_tlv_stream ( ) . write ( & mut bytes) . unwrap ( ) ;
253
+ unsigned_tlv_stream. write ( & mut bytes) . unwrap ( ) ;
249
254
250
255
let tagged_hash = TaggedHash :: from_valid_tlv_stream_bytes ( SIGNATURE_TAG , & bytes) ;
256
+
251
257
Self { contents, tagged_hash, bytes }
252
258
}
253
259
@@ -336,7 +342,7 @@ impl InvoiceContents {
336
342
}
337
343
}
338
344
339
- fn as_invoice_fields_tlv_stream ( & self ) -> InvoiceTlvStreamRef {
345
+ fn as_tlv_stream ( & self ) -> PartialInvoiceTlvStreamRef {
340
346
let features = {
341
347
if self . features == Bolt12InvoiceFeatures :: empty ( ) {
342
348
None
@@ -345,7 +351,7 @@ impl InvoiceContents {
345
351
}
346
352
} ;
347
353
348
- InvoiceTlvStreamRef {
354
+ let invoice = InvoiceTlvStreamRef {
349
355
paths : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |( _, path) | path) ) ) ,
350
356
message_paths : Some ( self . message_paths . as_ref ( ) ) ,
351
357
blindedpay : Some ( Iterable ( self . payment_paths . iter ( ) . map ( |( payinfo, _) | payinfo) ) ) ,
@@ -356,7 +362,9 @@ impl InvoiceContents {
356
362
node_id : Some ( & self . signing_pubkey ) ,
357
363
amount : None ,
358
364
payment_hash : None ,
359
- }
365
+ } ;
366
+
367
+ ( self . offer . as_tlv_stream ( ) , invoice)
360
368
}
361
369
362
370
fn chain ( & self ) -> ChainHash {
@@ -464,6 +472,8 @@ impl SeekReadable for FullInvoiceTlvStream {
464
472
465
473
type PartialInvoiceTlvStream = ( OfferTlvStream , InvoiceTlvStream ) ;
466
474
475
+ type PartialInvoiceTlvStreamRef < ' a > = ( OfferTlvStreamRef < ' a > , InvoiceTlvStreamRef < ' a > ) ;
476
+
467
477
impl TryFrom < ParsedMessage < FullInvoiceTlvStream > > for StaticInvoice {
468
478
type Error = Bolt12ParseError ;
469
479
0 commit comments