@@ -122,7 +122,7 @@ use crate::prelude::*;
122122#[ cfg( feature = "std" ) ]
123123use std:: time:: SystemTime ;
124124
125- const DEFAULT_RELATIVE_EXPIRY : Duration = Duration :: from_secs ( 7200 ) ;
125+ pub ( crate ) const DEFAULT_RELATIVE_EXPIRY : Duration = Duration :: from_secs ( 7200 ) ;
126126
127127pub ( super ) const SIGNATURE_TAG : & ' static str = concat ! ( "lightning" , "invoice" , "signature" ) ;
128128
@@ -145,18 +145,7 @@ impl<'a> InvoiceBuilder<'a> {
145145 invoice_request : & ' a InvoiceRequest , payment_paths : Vec < ( BlindedPath , BlindedPayInfo ) > ,
146146 created_at : Duration , payment_hash : PaymentHash
147147 ) -> 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) ?;
160149 let contents = InvoiceContents :: ForOffer {
161150 invoice_request : invoice_request. contents . clone ( ) ,
162151 fields : InvoiceFields {
@@ -185,6 +174,20 @@ impl<'a> InvoiceBuilder<'a> {
185174 Self :: new ( & refund. bytes , contents)
186175 }
187176
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+
188191 fn new ( invreq_bytes : & ' a Vec < u8 > , contents : InvoiceContents ) -> Result < Self , SemanticError > {
189192 if contents. fields ( ) . payment_paths . is_empty ( ) {
190193 return Err ( SemanticError :: MissingPaths ) ;
0 commit comments