Skip to content

Commit ea7af69

Browse files
committed
Introduce amount check in pay_for_offer
We introduce this check in pay_for_offer, to ensure that if the offer amount is specified in currency, a corresponding amount to be used in invoice request must be provided. **Reasoning:** When responding to an offer with currency, we enforce that the invoice request must always include an amount. This ensures we never receive an invoice tied to a currency-denominated offer without a corresponding request amount. By moving currency conversion upfront into the invoice request creation where the user can supply their own conversion logic — we avoid pushing conversion concerns into invoice parsing. This significantly reduces complexity during invoice verification.
1 parent a2569d8 commit ea7af69

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use crate::offers::invoice_request::{
9999
DefaultCurrencyConversion, InvoiceRequest, InvoiceRequestVerifiedFromOffer,
100100
};
101101
use crate::offers::nonce::Nonce;
102-
use crate::offers::offer::{Offer, OfferFromHrn};
102+
use crate::offers::offer::{Amount, Offer, OfferFromHrn};
103103
use crate::offers::parse::Bolt12SemanticError;
104104
use crate::offers::refund::Refund;
105105
use crate::offers::signer;
@@ -13030,6 +13030,13 @@ where
1303013030
let entropy = &*self.entropy_source;
1303113031
let nonce = Nonce::from_entropy_source(entropy);
1303213032

13033+
// If the offer is for a specific currency, ensure the amount is provided.
13034+
if let Some(Amount::Currency { iso4217_code: _, amount: _ }) = offer.amount() {
13035+
if amount_msats.is_none() {
13036+
return Err(Bolt12SemanticError::MissingAmount);
13037+
}
13038+
}
13039+
1303313040
let builder = self.flow.create_invoice_request_builder(
1303413041
offer, nonce, payment_id,
1303513042
)?;

0 commit comments

Comments
 (0)