Skip to content

Commit 61308c4

Browse files
committed
f switch to a dedicated pay_for_offer_with_quantity method
1 parent 4c4f167 commit 61308c4

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,6 @@ impl Readable for InterceptId {
696696
///
697697
/// These fields will often not need to be set, and the provided [`Self::default`] can be used.
698698
pub struct OptionalOfferPaymentInfo {
699-
/// The quantity of the offer which we wish to pay for. This is communicated to the recipient
700-
/// and determines the minimum value which we must pay.
701-
///
702-
/// This must be set if we're paying for an offer that has [`Offer::expects_quantity`].
703-
///
704-
#[cfg_attr(
705-
feature = "dnssec",
706-
doc = "Note that setting this will cause [`ChannelManager::pay_for_offer_from_human_readable_name`] to fail."
707-
)]
708-
pub quantity: Option<u64>,
709699
/// A note which is communicated to the recipient about this payment via
710700
/// [`InvoiceRequest::payer_note`].
711701
pub payer_note: Option<String>,
@@ -723,7 +713,6 @@ pub struct OptionalOfferPaymentInfo {
723713
impl Default for OptionalOfferPaymentInfo {
724714
fn default() -> Self {
725715
Self {
726-
quantity: None,
727716
payer_note: None,
728717
route_params_config: Default::default(),
729718
#[cfg(feature = "std")]
@@ -11212,8 +11201,6 @@ where
1121211201
/// request.
1121311202
///
1121411203
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
11215-
/// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
11216-
/// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
1121711204
/// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
1121811205
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
1121911206
/// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath
@@ -11243,7 +11230,55 @@ where
1124311230

1124411231
self.pay_for_offer_intern(
1124511232
offer,
11246-
optional_info.quantity,
11233+
if offer.expects_quantity() { Some(1) } else { None },
11234+
amount_msats,
11235+
optional_info.payer_note,
11236+
payment_id,
11237+
None,
11238+
create_pending_payment_fn,
11239+
)
11240+
}
11241+
11242+
/// Pays for an [`Offer`] using the given parameters, including a `quantity`, by creating an
11243+
/// [`InvoiceRequest`] and enqueuing it to be sent via an onion message. [`ChannelManager`] will
11244+
/// pay the actual [`Bolt12Invoice`] once it is received.
11245+
///
11246+
/// This method is identical to [`Self::pay_for_offer`] with the one exception that it allows
11247+
/// you to specify the [`InvoiceRequest::quantity`]. We expect this to be rather seldom used,
11248+
/// as the "quantity" feature of offers doesn't line up with common payment flows today.
11249+
///
11250+
/// This method is otherwise identical to [`Self::pay_for_offer`] but will additionally fail if
11251+
/// the provided `quantity` does not meet the requirements described by
11252+
/// [`Offer::supported_quantity`].
11253+
///
11254+
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
11255+
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
11256+
/// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
11257+
pub fn pay_for_offer_with_quantity(
11258+
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId,
11259+
optional_info: OptionalOfferPaymentInfo, quantity: u64,
11260+
) -> Result<(), Bolt12SemanticError> {
11261+
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
11262+
let expiration = StaleExpiration::TimerTicks(1);
11263+
let retryable_invoice_request = RetryableInvoiceRequest {
11264+
invoice_request: invoice_request.clone(),
11265+
nonce,
11266+
needs_retry: true,
11267+
};
11268+
self.pending_outbound_payments
11269+
.add_new_awaiting_invoice(
11270+
payment_id,
11271+
expiration,
11272+
optional_info.retry_strategy,
11273+
optional_info.route_params_config,
11274+
Some(retryable_invoice_request),
11275+
)
11276+
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
11277+
};
11278+
11279+
self.pay_for_offer_intern(
11280+
offer,
11281+
Some(quantity),
1124711282
amount_msats,
1124811283
optional_info.payer_note,
1124911284
payment_id,
@@ -11378,9 +11413,7 @@ where
1137811413
///
1137911414
/// # Errors
1138011415
///
11381-
/// Errors if:
11382-
/// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
11383-
/// - [`OptionalOfferPaymentInfo.quantity`] is set.
11416+
/// Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link.
1138411417
///
1138511418
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki
1138611419
/// [bLIP 32]: https://github.com/lightning/blips/blob/master/blip-0032.md
@@ -11396,10 +11429,6 @@ where
1139611429
&self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
1139711430
optional_info: OptionalOfferPaymentInfo, dns_resolvers: Vec<Destination>,
1139811431
) -> Result<(), ()> {
11399-
if optional_info.quantity.is_some() {
11400-
return Err(());
11401-
}
11402-
1140311432
let (onion_message, context) =
1140411433
self.flow.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?;
1140511434

0 commit comments

Comments
 (0)