@@ -25,7 +25,7 @@ use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
25
25
use crate :: ln:: msgs:: DecodeError ;
26
26
use crate :: offers:: invoice_request:: { InvoiceRequest , InvoiceRequestContents , InvoiceRequestTlvStream , InvoiceRequestTlvStreamRef } ;
27
27
use crate :: offers:: merkle:: { SignError , SignatureTlvStream , SignatureTlvStreamRef , WithoutSignatures , self } ;
28
- use crate :: offers:: offer:: { OfferTlvStream , OfferTlvStreamRef } ;
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
31
use crate :: offers:: refund:: RefundContents ;
@@ -68,14 +68,24 @@ impl<'a> InvoiceBuilder<'a> {
68
68
return Err ( SemanticError :: InvalidPayInfo ) ;
69
69
}
70
70
71
+ let amount_msats = match invoice_request. amount_msats ( ) {
72
+ Some ( amount_msats) => amount_msats,
73
+ None => match invoice_request. contents . offer . amount ( ) {
74
+ Some ( Amount :: Bitcoin { amount_msats } ) => {
75
+ amount_msats * invoice_request. quantity ( ) . unwrap_or ( 1 )
76
+ } ,
77
+ Some ( Amount :: Currency { .. } ) => return Err ( SemanticError :: UnsupportedCurrency ) ,
78
+ None => return Err ( SemanticError :: MissingAmount ) ,
79
+ } ,
80
+ } ;
81
+
71
82
Ok ( Self {
72
83
bytes : & invoice_request. bytes ,
73
84
invoice : InvoiceContents :: ForOffer {
74
85
invoice_request : invoice_request. contents . clone ( ) ,
75
86
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 ( ) , code : None ,
87
+ paths, payinfo, created_at, relative_expiry : None , payment_hash, amount_msats,
88
+ fallbacks : None , features : Bolt12InvoiceFeatures :: empty ( ) , code : None ,
79
89
} ,
80
90
} ,
81
91
} )
0 commit comments