Skip to content

Commit f9a7ccc

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 d4e2745 commit f9a7ccc

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
@@ -99,7 +99,7 @@ use crate::offers::invoice::{
9999
use crate::offers::invoice_error::InvoiceError;
100100
use crate::offers::invoice_request::InvoiceRequest;
101101
use crate::offers::nonce::Nonce;
102-
use crate::offers::offer::Offer;
102+
use crate::offers::offer::{Offer, OfferFromHrn};
103103
use crate::offers::parse::Bolt12SemanticError;
104104
use crate::offers::refund::Refund;
105105
use crate::offers::signer;
@@ -12258,6 +12258,9 @@ where
1225812258
/// `amount_msats` allows you to overpay what is required to satisfy the offer, or may be
1225912259
/// required if the offer does not require a specific amount.
1226012260
///
12261+
/// If the [`Offer`] was built from a human readable name resolved using BIP 353, you *must*
12262+
/// instead call [`Self::pay_for_offer_from_hrn`].
12263+
///
1226112264
/// # Payment
1226212265
///
1226312266
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request
@@ -12321,6 +12324,41 @@ where
1232112324
)
1232212325
}
1232312326

12327+
/// Pays for an [`Offer`] which was built by resolving a human readable name. It is otherwise
12328+
/// identical to [`Self::pay_for_offer`].
12329+
pub fn pay_for_offer_from_hrn(
12330+
&self, offer: &OfferFromHrn, amount_msats: u64, payment_id: PaymentId,
12331+
optional_params: OptionalOfferPaymentParams,
12332+
) -> Result<(), Bolt12SemanticError> {
12333+
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| {
12334+
let expiration = StaleExpiration::TimerTicks(1);
12335+
let retryable_invoice_request = RetryableInvoiceRequest {
12336+
invoice_request: invoice_request.clone(),
12337+
nonce,
12338+
needs_retry: true,
12339+
};
12340+
self.pending_outbound_payments
12341+
.add_new_awaiting_invoice(
12342+
payment_id,
12343+
expiration,
12344+
optional_params.retry_strategy,
12345+
optional_params.route_params_config,
12346+
Some(retryable_invoice_request),
12347+
)
12348+
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
12349+
};
12350+
12351+
self.pay_for_offer_intern(
12352+
&offer.offer,
12353+
if offer.offer.expects_quantity() { Some(1) } else { None },
12354+
Some(amount_msats),
12355+
optional_params.payer_note,
12356+
payment_id,
12357+
Some(offer.hrn.clone()),
12358+
create_pending_payment_fn,
12359+
)
12360+
}
12361+
1232412362
/// Pays for an [`Offer`] using the given parameters, including a `quantity`, by creating an
1232512363
/// [`InvoiceRequest`] and enqueuing it to be sent via an onion message. [`ChannelManager`] will
1232612364
/// pay the actual [`Bolt12Invoice`] once it is received.

0 commit comments

Comments
 (0)