@@ -28,7 +28,7 @@ use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef
28
28
use crate :: offers:: offer:: { OfferTlvStream , OfferTlvStreamRef } ;
29
29
use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
30
30
use crate :: offers:: payer:: { PayerTlvStream , PayerTlvStreamRef } ;
31
- use crate :: offers:: refund:: RefundContents ;
31
+ use crate :: offers:: refund:: { Refund , RefundContents } ;
32
32
use crate :: onion_message:: BlindedPath ;
33
33
use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , SeekReadable , WithoutLength , Writeable , Writer } ;
34
34
@@ -60,6 +60,39 @@ impl<'a> InvoiceBuilder<'a> {
60
60
invoice_request : & ' a InvoiceRequest , paths : Vec < BlindedPath > , payinfo : Vec < BlindedPayInfo > ,
61
61
created_at : Duration , payment_hash : PaymentHash
62
62
) -> 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
+
63
96
if paths. is_empty ( ) {
64
97
return Err ( SemanticError :: MissingPaths ) ;
65
98
}
@@ -68,18 +101,7 @@ impl<'a> InvoiceBuilder<'a> {
68
101
return Err ( SemanticError :: InvalidPayInfo ) ;
69
102
}
70
103
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 } )
83
105
}
84
106
85
107
/// Sets the [`Invoice::relative_expiry`] as seconds since [`Invoice::created_at`]. Any expiry
0 commit comments