@@ -28,7 +28,7 @@ use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef
28
28
use crate :: offers:: offer:: { Amount , 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,14 +60,6 @@ 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
- if paths. is_empty ( ) {
64
- return Err ( SemanticError :: MissingPaths ) ;
65
- }
66
-
67
- if paths. len ( ) != payinfo. len ( ) {
68
- return Err ( SemanticError :: InvalidPayInfo ) ;
69
- }
70
-
71
63
let amount_msats = match invoice_request. amount_msats ( ) {
72
64
Some ( amount_msats) => amount_msats,
73
65
None => match invoice_request. contents . offer . amount ( ) {
@@ -79,17 +71,47 @@ impl<'a> InvoiceBuilder<'a> {
79
71
} ,
80
72
} ;
81
73
82
- Ok ( Self {
83
- bytes : & invoice_request. bytes ,
84
- invoice : InvoiceContents :: ForOffer {
85
- invoice_request : invoice_request. contents . clone ( ) ,
86
- fields : InvoiceFields {
87
- paths, payinfo, created_at, relative_expiry : None , payment_hash, amount_msats,
88
- fallbacks : None , features : Bolt12InvoiceFeatures :: empty ( ) ,
89
- signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
90
- } ,
74
+ let contents = InvoiceContents :: ForOffer {
75
+ invoice_request : invoice_request. contents . clone ( ) ,
76
+ fields : InvoiceFields {
77
+ paths, payinfo, created_at, relative_expiry : None , payment_hash, amount_msats,
78
+ fallbacks : None , features : Bolt12InvoiceFeatures :: empty ( ) ,
79
+ signing_pubkey : invoice_request. contents . offer . signing_pubkey ( ) ,
91
80
} ,
92
- } )
81
+ } ;
82
+
83
+ Self :: new ( & invoice_request. bytes , contents)
84
+ }
85
+
86
+ pub ( super ) fn for_refund (
87
+ refund : & ' a Refund , paths : Vec < BlindedPath > , payinfo : Vec < BlindedPayInfo > ,
88
+ created_at : Duration , payment_hash : PaymentHash , signing_pubkey : PublicKey
89
+ ) -> Result < Self , SemanticError > {
90
+ let contents = InvoiceContents :: ForRefund {
91
+ refund : refund. contents . clone ( ) ,
92
+ fields : InvoiceFields {
93
+ paths, payinfo, 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 ( bytes : & ' a Vec < u8 > , contents : InvoiceContents ) -> Result < Self , SemanticError > {
103
+ let paths = & contents. fields ( ) . paths ;
104
+ let payinfo = & contents. fields ( ) . payinfo ;
105
+
106
+ if paths. is_empty ( ) {
107
+ return Err ( SemanticError :: MissingPaths ) ;
108
+ }
109
+
110
+ if paths. len ( ) != payinfo. len ( ) {
111
+ return Err ( SemanticError :: InvalidPayInfo ) ;
112
+ }
113
+
114
+ Ok ( Self { bytes, invoice : contents } )
93
115
}
94
116
95
117
/// Sets the [`Invoice::relative_expiry`] as seconds since [`Invoice::created_at`]. Any expiry
0 commit comments