Skip to content

Commit 457d57a

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 fa7c04a commit 457d57a

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
@@ -97,7 +97,7 @@ use crate::offers::invoice_request::{
9797
DefaultCurrencyConversion, InvoiceRequest, InvoiceRequestVerifiedFromOffer,
9898
};
9999
use crate::offers::nonce::Nonce;
100-
use crate::offers::offer::{Offer, OfferFromHrn};
100+
use crate::offers::offer::{Amount, Offer, OfferFromHrn};
101101
use crate::offers::parse::Bolt12SemanticError;
102102
use crate::offers::refund::Refund;
103103
use crate::offers::static_invoice::StaticInvoice;
@@ -13081,6 +13081,13 @@ where
1308113081
let entropy = &*self.entropy_source;
1308213082
let nonce = Nonce::from_entropy_source(entropy);
1308313083

13084+
// If the offer is for a specific currency, ensure the amount is provided.
13085+
if let Some(Amount::Currency { iso4217_code: _, amount: _ }) = offer.amount() {
13086+
if amount_msats.is_none() {
13087+
return Err(Bolt12SemanticError::MissingAmount);
13088+
}
13089+
}
13090+
1308413091
let builder = self.flow.create_invoice_request_builder(
1308513092
offer, nonce, payment_id,
1308613093
)?;

0 commit comments

Comments
 (0)