@@ -28,7 +28,7 @@ use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef
2828use crate :: offers:: offer:: { OfferTlvStream , OfferTlvStreamRef } ;
2929use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
3030use crate :: offers:: payer:: { PayerTlvStream , PayerTlvStreamRef } ;
31- use crate :: offers:: refund:: RefundContents ;
31+ use crate :: offers:: refund:: { Refund , RefundContents } ;
3232use crate :: onion_message:: BlindedPath ;
3333use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
3434
@@ -60,6 +60,39 @@ impl<'a> InvoiceBuilder<'a> {
6060 invoice_request : & ' a InvoiceRequest , paths : Vec < BlindedPath > , payinfo : Vec < BlindedPayInfo > ,
6161 created_at : Duration , payment_hash : PaymentHash
6262 ) -> Result < Self , SemanticError > {
63+ let contents = InvoiceContents :: ForOffer {
64+ invoice_request : invoice_request. contents . clone ( ) ,
65+ fields : InvoiceFields {
66+ paths, payinfo, created_at, relative_expiry : None , payment_hash,
67+ amount_msats : invoice_request. amount_msats ( ) , fallbacks : None ,
68+ features : Bolt12InvoiceFeatures :: empty ( ) ,
69+ signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
70+ } ,
71+ } ;
72+
73+ Self :: new ( & invoice_request. bytes , contents)
74+ }
75+
76+ pub ( super ) fn for_refund (
77+ refund : & ' a Refund , paths : Vec < BlindedPath > , payinfo : Vec < BlindedPayInfo > ,
78+ created_at : Duration , payment_hash : PaymentHash , signing_pubkey : PublicKey
79+ ) -> Result < Self , SemanticError > {
80+ let contents = InvoiceContents :: ForRefund {
81+ refund : refund. contents . clone ( ) ,
82+ fields : InvoiceFields {
83+ paths, payinfo, created_at, relative_expiry : None , payment_hash,
84+ amount_msats : refund. amount_msats ( ) , fallbacks : None ,
85+ features : Bolt12InvoiceFeatures :: empty ( ) , signing_pubkey,
86+ } ,
87+ } ;
88+
89+ Self :: new ( & refund. bytes , contents)
90+ }
91+
92+ fn new ( bytes : & ' a Vec < u8 > , contents : InvoiceContents ) -> Result < Self , SemanticError > {
93+ let paths = & contents. fields ( ) . paths ;
94+ let payinfo = & contents. fields ( ) . payinfo ;
95+
6396 if paths. is_empty ( ) {
6497 return Err ( SemanticError :: MissingPaths ) ;
6598 }
@@ -68,18 +101,7 @@ impl<'a> InvoiceBuilder<'a> {
68101 return Err ( SemanticError :: InvalidPayInfo ) ;
69102 }
70103
71- Ok ( Self {
72- bytes : & invoice_request. bytes ,
73- invoice : InvoiceContents :: ForOffer {
74- invoice_request : invoice_request. contents . clone ( ) ,
75- fields : InvoiceFields {
76- paths, payinfo, created_at, relative_expiry : None , payment_hash,
77- amount_msats : invoice_request. amount_msats ( ) , fallbacks : None ,
78- features : Bolt12InvoiceFeatures :: empty ( ) ,
79- signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
80- } ,
81- } ,
82- } )
104+ Ok ( Self { bytes, invoice : contents } )
83105 }
84106
85107 /// Sets the [`Invoice::relative_expiry`] as seconds since [`Invoice::created_at`]. Any expiry
0 commit comments