@@ -122,7 +122,7 @@ use crate::prelude::*;
122
122
#[ cfg( feature = "std" ) ]
123
123
use std:: time:: SystemTime ;
124
124
125
- const DEFAULT_RELATIVE_EXPIRY : Duration = Duration :: from_secs ( 7200 ) ;
125
+ pub ( crate ) const DEFAULT_RELATIVE_EXPIRY : Duration = Duration :: from_secs ( 7200 ) ;
126
126
127
127
pub ( super ) const SIGNATURE_TAG : & ' static str = concat ! ( "lightning" , "invoice" , "signature" ) ;
128
128
@@ -145,18 +145,7 @@ impl<'a> InvoiceBuilder<'a> {
145
145
invoice_request : & ' a InvoiceRequest , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > ,
146
146
created_at : Duration , payment_hash : PaymentHash
147
147
) -> Result < Self , SemanticError > {
148
- let amount_msats = match invoice_request. amount_msats ( ) {
149
- Some ( amount_msats) => amount_msats,
150
- None => match invoice_request. contents . offer . amount ( ) {
151
- Some ( Amount :: Bitcoin { amount_msats } ) => {
152
- amount_msats. checked_mul ( invoice_request. quantity ( ) . unwrap_or ( 1 ) )
153
- . ok_or ( SemanticError :: InvalidAmount ) ?
154
- } ,
155
- Some ( Amount :: Currency { .. } ) => return Err ( SemanticError :: UnsupportedCurrency ) ,
156
- None => return Err ( SemanticError :: MissingAmount ) ,
157
- } ,
158
- } ;
159
-
148
+ let amount_msats = Self :: amount_msats ( invoice_request) ?;
160
149
let contents = InvoiceContents :: ForOffer {
161
150
invoice_request : invoice_request. contents . clone ( ) ,
162
151
fields : InvoiceFields {
@@ -185,6 +174,20 @@ impl<'a> InvoiceBuilder<'a> {
185
174
Self :: new ( & refund. bytes , contents)
186
175
}
187
176
177
+ pub ( crate ) fn amount_msats ( invoice_request : & InvoiceRequest ) -> Result < u64 , SemanticError > {
178
+ match invoice_request. amount_msats ( ) {
179
+ Some ( amount_msats) => Ok ( amount_msats) ,
180
+ None => match invoice_request. contents . offer . amount ( ) {
181
+ Some ( Amount :: Bitcoin { amount_msats } ) => {
182
+ amount_msats. checked_mul ( invoice_request. quantity ( ) . unwrap_or ( 1 ) )
183
+ . ok_or ( SemanticError :: InvalidAmount )
184
+ } ,
185
+ Some ( Amount :: Currency { .. } ) => Err ( SemanticError :: UnsupportedCurrency ) ,
186
+ None => Err ( SemanticError :: MissingAmount ) ,
187
+ } ,
188
+ }
189
+ }
190
+
188
191
fn new ( invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents ) -> Result < Self , SemanticError > {
189
192
if contents. fields ( ) . payment_paths . is_empty ( ) {
190
193
return Err ( SemanticError :: MissingPaths ) ;
0 commit comments