Skip to content

Commit 5421938

Browse files
committed
Allow setting an HRN in invoice_requests built by pay_for_offer
If a user did their own BIP 353 lookup to fetch an offer from a human readable name, we still want them to be able to use `ChannelManager::pay_for_offer`. Because BIP 353 offer payments require that the `invoice_request` include the human readable name, we need to add an argument to set the `invoice_request` HRN to `pay_for_offer`, which we do here.
1 parent dd12251 commit 5421938

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use crate::offers::invoice::{
9898
use crate::offers::invoice_error::InvoiceError;
9999
use crate::offers::invoice_request::InvoiceRequest;
100100
use crate::offers::nonce::Nonce;
101-
use crate::offers::offer::Offer;
101+
use crate::offers::offer::{Offer, OfferFromHrn};
102102
use crate::offers::parse::Bolt12SemanticError;
103103
use crate::offers::refund::Refund;
104104
use crate::offers::signer;
@@ -12288,6 +12288,9 @@ where
1228812288
/// `amount_msats` allows you to overpay what is required to satisfy the offer, or may be
1228912289
/// required if the offer does not require a specific amount.
1229012290
///
12291+
/// If the [`Offer`] was built from a human readable name resolved using BIP 353, you *must*
12292+
/// instead call [`Self::pay_for_offer_from_hrn`].
12293+
///
1229112294
/// # Payment
1229212295
///
1229312296
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request
@@ -12351,6 +12354,41 @@ where
1235112354
)
1235212355
}
1235312356

12357+
/// Pays for an [`Offer`] which was built by resolving a human readable name. It is otherwise
12358+
/// identical to [`Self::pay_for_offer`].
12359+
pub fn pay_for_offer_from_hrn(
12360+
&self, offer: &OfferFromHrn, amount_msats: u64, payment_id: PaymentId,
12361+
optional_params: OptionalOfferPaymentParams,
12362+
) -> Result<(), Bolt12SemanticError> {
12363+
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12364+
let expiration = StaleExpiration::TimerTicks(1);
12365+
let retryable_invoice_request = RetryableInvoiceRequest {
12366+
invoice_request: invoice_request.clone(),
12367+
nonce,
12368+
needs_retry: true,
12369+
};
12370+
self.pending_outbound_payments
12371+
.add_new_awaiting_invoice(
12372+
payment_id,
12373+
expiration,
12374+
optional_params.retry_strategy,
12375+
optional_params.route_params_config,
12376+
Some(retryable_invoice_request),
12377+
)
12378+
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
12379+
};
12380+
12381+
self.pay_for_offer_intern(
12382+
&offer.offer,
12383+
if offer.offer.expects_quantity() { Some(1) } else { None },
12384+
Some(amount_msats),
12385+
optional_params.payer_note,
12386+
payment_id,
12387+
Some(offer.hrn),
12388+
create_pending_payment_fn,
12389+
)
12390+
}
12391+
1235412392
/// Pays for an [`Offer`] using the given parameters, including a `quantity`, by creating an
1235512393
/// [`InvoiceRequest`] and enqueuing it to be sent via an onion message. [`ChannelManager`] will
1235612394
/// pay the actual [`Bolt12Invoice`] once it is received.

0 commit comments

Comments
 (0)