@@ -48,6 +48,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
48
48
// construct one themselves.
49
49
use crate::ln::inbound_payment;
50
50
use crate::ln::types::ChannelId;
51
+ use crate::offers::offer::Offer;
51
52
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
52
53
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
53
54
use crate::ln::channel_state::ChannelDetails;
@@ -67,7 +68,6 @@ use crate::ln::wire::Encode;
67
68
use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
68
69
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
69
70
use crate::offers::nonce::Nonce;
70
- use crate::offers::offer::Offer;
71
71
use crate::offers::parse::Bolt12SemanticError;
72
72
use crate::offers::refund::Refund;
73
73
use crate::offers::signer;
@@ -2002,56 +2002,7 @@ where
2002
2002
///
2003
2003
/// For more information on creating offers, see [`create_offer_builder`].
2004
2004
///
2005
- /// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
2006
- /// and pays the [`Bolt12Invoice`] response.
2007
- ///
2008
- /// ```
2009
- /// # use lightning::events::{Event, EventsProvider};
2010
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons, PaymentId, RecentPaymentDetails, Retry};
2011
- /// # use lightning::offers::offer::Offer;
2012
- /// #
2013
- /// # fn example<T: AChannelManager>(
2014
- /// # channel_manager: T, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
2015
- /// # payer_note: Option<String>, retry: Retry, max_total_routing_fee_msat: Option<u64>
2016
- /// # ) {
2017
- /// # let channel_manager = channel_manager.get_cm();
2018
- /// let payment_id = PaymentId([42; 32]);
2019
- /// match channel_manager.pay_for_offer(
2020
- /// offer, quantity, amount_msats, payer_note, payment_id, retry, max_total_routing_fee_msat
2021
- /// ) {
2022
- /// Ok(()) => println!("Requesting invoice for offer"),
2023
- /// Err(e) => println!("Unable to request invoice for offer: {:?}", e),
2024
- /// }
2025
- ///
2026
- /// // First the payment will be waiting on an invoice
2027
- /// let expected_payment_id = payment_id;
2028
- /// assert!(
2029
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2030
- /// details,
2031
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2032
- /// )).is_some()
2033
- /// );
2034
- ///
2035
- /// // Once the invoice is received, a payment will be sent
2036
- /// assert!(
2037
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2038
- /// details,
2039
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2040
- /// )).is_some()
2041
- /// );
2042
- ///
2043
- /// // On the event processing thread
2044
- /// channel_manager.process_pending_events(&|event| {
2045
- /// match event {
2046
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2047
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2048
- /// // ...
2049
- /// # _ => {},
2050
- /// }
2051
- /// Ok(())
2052
- /// });
2053
- /// # }
2054
- /// ```
2005
+ /// For details on initiating payments for offers, see [`pay_for_offer`].
2055
2006
///
2056
2007
/// ## BOLT 12 Refunds
2057
2008
///
@@ -2181,7 +2132,7 @@ where
2181
2132
/// [`claim_funds`]: Self::claim_funds
2182
2133
/// [`send_payment`]: Self::send_payment
2183
2134
/// [`offers`]: crate::offers
2184
- /// [`pay_for_offer `]: Self::pay_for_offer
2135
+ /// [`Offer `]: crate::offers::offer
2185
2136
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2186
2137
/// [`request_refund_payment`]: Self::request_refund_payment
2187
2138
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
@@ -2192,6 +2143,7 @@ where
2192
2143
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2193
2144
/// [`read`]: ReadableArgs::read
2194
2145
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2146
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2195
2147
/// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2196
2148
//
2197
2149
// Lock order:
@@ -2695,6 +2647,8 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2695
2647
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2696
2648
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2697
2649
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2650
+ ///
2651
+ /// [`Offer`]: crate::offers::offer
2698
2652
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2699
2653
2700
2654
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -2703,8 +2657,10 @@ pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 6
2703
2657
pub enum RecentPaymentDetails {
2704
2658
/// When an invoice was requested and thus a payment has not yet been sent.
2705
2659
AwaitingInvoice {
2706
- /// A user-provided identifier in [`ChannelManager ::pay_for_offer`] used to uniquely identify a
2660
+ /// A user-provided identifier in [`OffersMessageFlow ::pay_for_offer`] used to uniquely identify a
2707
2661
/// payment and ensure idempotency in LDK.
2662
+ ///
2663
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2708
2664
payment_id: PaymentId,
2709
2665
},
2710
2666
/// When a payment is still being sent and awaiting successful delivery.
@@ -2713,7 +2669,7 @@ pub enum RecentPaymentDetails {
2713
2669
/// identify a payment and ensure idempotency in LDK.
2714
2670
///
2715
2671
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2716
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2672
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2717
2673
payment_id: PaymentId,
2718
2674
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
2719
2675
/// abandoned.
@@ -2730,7 +2686,7 @@ pub enum RecentPaymentDetails {
2730
2686
/// identify a payment and ensure idempotency in LDK.
2731
2687
///
2732
2688
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2733
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2689
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2734
2690
payment_id: PaymentId,
2735
2691
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2736
2692
/// made before LDK version 0.0.104.
@@ -2744,7 +2700,7 @@ pub enum RecentPaymentDetails {
2744
2700
/// identify a payment and ensure idempotency in LDK.
2745
2701
///
2746
2702
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2747
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2703
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2748
2704
payment_id: PaymentId,
2749
2705
/// Hash of the payment that we have given up trying to send.
2750
2706
payment_hash: PaymentHash,
@@ -4657,7 +4613,7 @@ where
4657
4613
///
4658
4614
/// # Requested Invoices
4659
4615
///
4660
- /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager ::pay_for_offer`], abandoning
4616
+ /// In the case of paying a [`Bolt12Invoice`] via [`OffersMessageFlow ::pay_for_offer`], abandoning
4661
4617
/// the payment prior to receiving the invoice will result in an [`Event::PaymentFailed`] and
4662
4618
/// prevent any attempts at paying it once received.
4663
4619
///
@@ -4667,6 +4623,7 @@ where
4667
4623
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
4668
4624
///
4669
4625
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4626
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
4670
4627
pub fn abandon_payment(&self, payment_id: PaymentId) {
4671
4628
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4672
4629
}
@@ -9400,6 +9357,13 @@ pub trait OffersMessageCommons {
9400
9357
9401
9358
/// Add new awaiting invoice
9402
9359
fn add_new_awaiting_invoice(&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>, retryable_invoice_request: Option<RetryableInvoiceRequest>) -> Result<(), ()>;
9360
+
9361
+ /// Internal pay_for_offer
9362
+ fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>> (
9363
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9364
+ payer_note: Option<String>, payment_id: PaymentId,
9365
+ human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9366
+ ) -> Result<(), Bolt12SemanticError>;
9403
9367
}
9404
9368
9405
9369
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> OffersMessageCommons for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
@@ -9583,104 +9547,10 @@ where
9583
9547
}
9584
9548
9585
9549
fn add_new_awaiting_invoice(&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>, retryable_invoice_request: Option<RetryableInvoiceRequest>) -> Result<(), ()> {
9586
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9587
9550
self.pending_outbound_payments.add_new_awaiting_invoice (
9588
9551
payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9589
9552
)
9590
9553
}
9591
- }
9592
-
9593
- /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9594
- /// along different paths.
9595
- /// Sending multiple requests increases the chances of successful delivery in case some
9596
- /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9597
- /// even if multiple invoices are received.
9598
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9599
-
9600
- impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
9601
- where
9602
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9603
- T::Target: BroadcasterInterface,
9604
- ES::Target: EntropySource,
9605
- NS::Target: NodeSigner,
9606
- SP::Target: SignerProvider,
9607
- F::Target: FeeEstimator,
9608
- R::Target: Router,
9609
- MR::Target: MessageRouter,
9610
- L::Target: Logger,
9611
- {
9612
- /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9613
- /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9614
- /// [`Bolt12Invoice`] once it is received.
9615
- ///
9616
- /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
9617
- /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
9618
- /// The optional parameters are used in the builder, if `Some`:
9619
- /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
9620
- /// [`Offer::expects_quantity`] is `true`.
9621
- /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
9622
- /// - `payer_note` for [`InvoiceRequest::payer_note`].
9623
- ///
9624
- /// If `max_total_routing_fee_msat` is not specified, The default from
9625
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9626
- ///
9627
- /// # Payment
9628
- ///
9629
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9630
- /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9631
- /// been sent.
9632
- ///
9633
- /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9634
- /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9635
- /// payment will fail with an [`Event::PaymentFailed`].
9636
- ///
9637
- /// # Privacy
9638
- ///
9639
- /// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9640
- /// to construct a [`BlindedMessagePath`] for the reply path. For further privacy implications, see the
9641
- /// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9642
- ///
9643
- /// # Limitations
9644
- ///
9645
- /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
9646
- /// [`Offer::issuer_signing_pubkey`], if empty. A similar restriction applies to the responding
9647
- /// [`Bolt12Invoice::payment_paths`].
9648
- ///
9649
- /// # Errors
9650
- ///
9651
- /// Errors if:
9652
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9653
- /// - the provided parameters are invalid for the offer,
9654
- /// - the offer is for an unsupported chain, or
9655
- /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
9656
- /// request.
9657
- ///
9658
- /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
9659
- /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
9660
- /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
9661
- /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
9662
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9663
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9664
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9665
- pub fn pay_for_offer(
9666
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9667
- payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
9668
- max_total_routing_fee_msat: Option<u64>
9669
- ) -> Result<(), Bolt12SemanticError> {
9670
- self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, None, |invoice_request, nonce| {
9671
- let expiration = StaleExpiration::TimerTicks(1);
9672
- let retryable_invoice_request = RetryableInvoiceRequest {
9673
- invoice_request: invoice_request.clone(),
9674
- nonce,
9675
- };
9676
- self.pending_outbound_payments
9677
- .add_new_awaiting_invoice(
9678
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9679
- Some(retryable_invoice_request)
9680
- )
9681
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
9682
- })
9683
- }
9684
9554
9685
9555
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9686
9556
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -9728,7 +9598,27 @@ where
9728
9598
9729
9599
self.enqueue_invoice_request(invoice_request, reply_paths)
9730
9600
}
9601
+ }
9731
9602
9603
+ /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9604
+ /// along different paths.
9605
+ /// Sending multiple requests increases the chances of successful delivery in case some
9606
+ /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9607
+ /// even if multiple invoices are received.
9608
+ const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9609
+
9610
+ impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
9611
+ where
9612
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9613
+ T::Target: BroadcasterInterface,
9614
+ ES::Target: EntropySource,
9615
+ NS::Target: NodeSigner,
9616
+ SP::Target: SignerProvider,
9617
+ F::Target: FeeEstimator,
9618
+ R::Target: Router,
9619
+ MR::Target: MessageRouter,
9620
+ L::Target: Logger,
9621
+ {
9732
9622
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9733
9623
/// message.
9734
9624
///
@@ -12273,6 +12163,8 @@ where
12273
12163
pub router: R,
12274
12164
/// The [`MessageRouter`] used for constructing [`BlindedMessagePath`]s for [`Offer`]s,
12275
12165
/// [`Refund`]s, and any reply paths.
12166
+ ///
12167
+ /// [`Offer`]: crate::offers::offer
12276
12168
pub message_router: MR,
12277
12169
/// The Logger for use in the ChannelManager and which may be used to log information during
12278
12170
/// deserialization.
0 commit comments