@@ -28,7 +28,7 @@ use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef
2828use crate :: offers:: offer:: { Amount , 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 , Iterable , SeekReadable , WithoutLength , Writeable , Writer } ;
3434
@@ -60,10 +60,6 @@ impl<'a> InvoiceBuilder<'a> {
6060 invoice_request : & ' a InvoiceRequest , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > ,
6161 created_at : Duration , payment_hash : PaymentHash
6262 ) -> Result < Self , SemanticError > {
63- if payment_paths. is_empty ( ) {
64- return Err ( SemanticError :: MissingPaths ) ;
65- }
66-
6763 let amount_msats = match invoice_request. amount_msats ( ) {
6864 Some ( amount_msats) => amount_msats,
6965 None => match invoice_request. contents . offer . amount ( ) {
@@ -75,17 +71,40 @@ impl<'a> InvoiceBuilder<'a> {
7571 } ,
7672 } ;
7773
78- Ok ( Self {
79- invreq_bytes : & invoice_request. bytes ,
80- invoice : InvoiceContents :: ForOffer {
81- invoice_request : invoice_request. contents . clone ( ) ,
82- fields : InvoiceFields {
83- payment_paths, created_at, relative_expiry : None , payment_hash, amount_msats,
84- fallbacks : None , features : Bolt12InvoiceFeatures :: empty ( ) ,
85- signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
86- } ,
74+ let contents = InvoiceContents :: ForOffer {
75+ invoice_request : invoice_request. contents . clone ( ) ,
76+ fields : InvoiceFields {
77+ payment_paths, created_at, relative_expiry : None , payment_hash, amount_msats,
78+ fallbacks : None , features : Bolt12InvoiceFeatures :: empty ( ) ,
79+ signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
8780 } ,
88- } )
81+ } ;
82+
83+ Self :: new ( & invoice_request. bytes , contents)
84+ }
85+
86+ pub ( super ) fn for_refund (
87+ refund : & ' a Refund , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > , created_at : Duration ,
88+ payment_hash : PaymentHash , signing_pubkey : PublicKey
89+ ) -> Result < Self , SemanticError > {
90+ let contents = InvoiceContents :: ForRefund {
91+ refund : refund. contents . clone ( ) ,
92+ fields : InvoiceFields {
93+ payment_paths, created_at, relative_expiry : None , payment_hash,
94+ amount_msats : refund. amount_msats ( ) , fallbacks : None ,
95+ features : Bolt12InvoiceFeatures :: empty ( ) , signing_pubkey,
96+ } ,
97+ } ;
98+
99+ Self :: new ( & refund. bytes , contents)
100+ }
101+
102+ fn new ( invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents ) -> Result < Self , SemanticError > {
103+ if contents. fields ( ) . payment_paths . is_empty ( ) {
104+ return Err ( SemanticError :: MissingPaths ) ;
105+ }
106+
107+ Ok ( Self { invreq_bytes, invoice : contents } )
89108 }
90109
91110 /// Sets the [`Invoice::relative_expiry`] as seconds since [`Invoice::created_at`]. Any expiry
0 commit comments