-
Notifications
You must be signed in to change notification settings - Fork 418
Allow setting an HRN in invoice_requests built by pay_for_offer
#3903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheBlueMatt
wants to merge
9
commits into
lightningdevkit:main
Choose a base branch
from
TheBlueMatt:2025-07-bpi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c4f167
Move reasonable-default arguments out of `pay_for_offer`.
TheBlueMatt 61308c4
f switch to a dedicated `pay_for_offer_with_quantity` method
TheBlueMatt 37b04b1
f s/OptionalOfferPaymentInfo/OptionalOfferPaymentParams/g
TheBlueMatt 4d5da56
f sp
TheBlueMatt 49c59cf
Drop spurious limitations section on `pay_for_offer`
TheBlueMatt e589d91
Allow setting an HRN in invoice_requests built by `pay_for_offer`
TheBlueMatt b97b58f
f rebase derived_from_hrn
TheBlueMatt 03cb4a1
Mention the `bitcoin-payment-instructions` crate in docs
TheBlueMatt a2daa01
f slightly better docs
TheBlueMatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -696,16 +696,6 @@ impl Readable for InterceptId { | |
/// | ||
/// These fields will often not need to be set, and the provided [`Self::default`] can be used. | ||
pub struct OptionalOfferPaymentInfo { | ||
/// The quantity of the offer which we wish to pay for. This is communicated to the recipient | ||
/// and determines the minimum value which we must pay. | ||
/// | ||
/// This must be set if we're paying for an offer that has [`Offer::expects_quantity`]. | ||
/// | ||
#[cfg_attr( | ||
feature = "dnssec", | ||
doc = "Note that setting this will cause [`ChannelManager::pay_for_offer_from_human_readable_name`] to fail." | ||
)] | ||
pub quantity: Option<u64>, | ||
/// A note which is communicated to the recipient about this payment via | ||
/// [`InvoiceRequest::payer_note`]. | ||
pub payer_note: Option<String>, | ||
|
@@ -723,7 +713,6 @@ pub struct OptionalOfferPaymentInfo { | |
impl Default for OptionalOfferPaymentInfo { | ||
fn default() -> Self { | ||
Self { | ||
quantity: None, | ||
payer_note: None, | ||
route_params_config: Default::default(), | ||
#[cfg(feature = "std")] | ||
|
@@ -11212,8 +11201,6 @@ where | |
/// request. | ||
/// | ||
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest | ||
/// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity | ||
/// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note | ||
/// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder | ||
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice | ||
/// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath | ||
|
@@ -11243,7 +11230,55 @@ where | |
|
||
self.pay_for_offer_intern( | ||
offer, | ||
optional_info.quantity, | ||
if offer.expects_quantity() { Some(1) } else { None }, | ||
amount_msats, | ||
optional_info.payer_note, | ||
payment_id, | ||
None, | ||
create_pending_payment_fn, | ||
) | ||
} | ||
|
||
/// Pays for an [`Offer`] using the given parameters, including a `quantity`, by creating an | ||
/// [`InvoiceRequest`] and enqueuing it to be sent via an onion message. [`ChannelManager`] will | ||
/// pay the actual [`Bolt12Invoice`] once it is received. | ||
/// | ||
/// This method is identical to [`Self::pay_for_offer`] with the one exception that it allows | ||
/// you to specify the [`InvoiceRequest::quantity`]. We expect this to be rather seldom used, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
/// as the "quantity" feature of offers doesn't line up with common payment flows today. | ||
/// | ||
/// This method is otherwise identical to [`Self::pay_for_offer`] but will additionally fail if | ||
/// the provided `quantity` does not meet the requirements described by | ||
/// [`Offer::supported_quantity`]. | ||
/// | ||
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest | ||
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice | ||
/// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity | ||
pub fn pay_for_offer_with_quantity( | ||
&self, offer: &Offer, amount_msats: Option<u64>, payment_id: PaymentId, | ||
optional_info: OptionalOfferPaymentInfo, quantity: u64, | ||
) -> Result<(), Bolt12SemanticError> { | ||
let create_pending_payment_fn = |invoice_request: &InvoiceRequest, nonce| { | ||
let expiration = StaleExpiration::TimerTicks(1); | ||
let retryable_invoice_request = RetryableInvoiceRequest { | ||
invoice_request: invoice_request.clone(), | ||
nonce, | ||
needs_retry: true, | ||
}; | ||
self.pending_outbound_payments | ||
.add_new_awaiting_invoice( | ||
payment_id, | ||
expiration, | ||
optional_info.retry_strategy, | ||
optional_info.route_params_config, | ||
Some(retryable_invoice_request), | ||
) | ||
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId) | ||
}; | ||
|
||
self.pay_for_offer_intern( | ||
offer, | ||
Some(quantity), | ||
amount_msats, | ||
optional_info.payer_note, | ||
payment_id, | ||
|
@@ -11378,9 +11413,7 @@ where | |
/// | ||
/// # Errors | ||
/// | ||
/// Errors if: | ||
/// - a duplicate `payment_id` is provided given the caveats in the aforementioned link, | ||
/// - [`OptionalOfferPaymentInfo.quantity`] is set. | ||
/// Errors if a duplicate `payment_id` is provided given the caveats in the aforementioned link. | ||
/// | ||
/// [BIP 353]: https://github.com/bitcoin/bips/blob/master/bip-0353.mediawiki | ||
/// [bLIP 32]: https://github.com/lightning/blips/blob/master/blip-0032.md | ||
|
@@ -11396,10 +11429,6 @@ where | |
&self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId, | ||
optional_info: OptionalOfferPaymentInfo, dns_resolvers: Vec<Destination>, | ||
) -> Result<(), ()> { | ||
if optional_info.quantity.is_some() { | ||
return Err(()); | ||
} | ||
|
||
let (onion_message, context) = | ||
self.flow.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?; | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.