@@ -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, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder};
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;
@@ -1993,59 +1993,6 @@ where
1993
1993
/// # }
1994
1994
/// ```
1995
1995
///
1996
- /// ## BOLT 12 Offers
1997
- ///
1998
- /// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
1999
- /// and pays the [`Bolt12Invoice`] response.
2000
- ///
2001
- /// ```
2002
- /// # use lightning::events::{Event, EventsProvider};
2003
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons, PaymentId, RecentPaymentDetails, Retry};
2004
- /// # use lightning::offers::offer::Offer;
2005
- /// #
2006
- /// # fn example<T: AChannelManager>(
2007
- /// # channel_manager: T, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
2008
- /// # payer_note: Option<String>, retry: Retry, max_total_routing_fee_msat: Option<u64>
2009
- /// # ) {
2010
- /// # let channel_manager = channel_manager.get_cm();
2011
- /// let payment_id = PaymentId([42; 32]);
2012
- /// match channel_manager.pay_for_offer(
2013
- /// offer, quantity, amount_msats, payer_note, payment_id, retry, max_total_routing_fee_msat
2014
- /// ) {
2015
- /// Ok(()) => println!("Requesting invoice for offer"),
2016
- /// Err(e) => println!("Unable to request invoice for offer: {:?}", e),
2017
- /// }
2018
- ///
2019
- /// // First the payment will be waiting on an invoice
2020
- /// let expected_payment_id = payment_id;
2021
- /// assert!(
2022
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2023
- /// details,
2024
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2025
- /// )).is_some()
2026
- /// );
2027
- ///
2028
- /// // Once the invoice is received, a payment will be sent
2029
- /// assert!(
2030
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2031
- /// details,
2032
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2033
- /// )).is_some()
2034
- /// );
2035
- ///
2036
- /// // On the event processing thread
2037
- /// channel_manager.process_pending_events(&|event| {
2038
- /// match event {
2039
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2040
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2041
- /// // ...
2042
- /// # _ => {},
2043
- /// }
2044
- /// Ok(())
2045
- /// });
2046
- /// # }
2047
- /// ```
2048
- ///
2049
1996
/// ## BOLT 12 Refunds
2050
1997
///
2051
1998
/// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
@@ -2172,7 +2119,7 @@ where
2172
2119
/// [`claim_funds`]: Self::claim_funds
2173
2120
/// [`send_payment`]: Self::send_payment
2174
2121
/// [`offers`]: crate::offers
2175
- /// [`pay_for_offer `]: Self::pay_for_offer
2122
+ /// [`Offer `]: crate::offers::offer
2176
2123
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2177
2124
/// [`request_refund_payment`]: Self::request_refund_payment
2178
2125
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
@@ -2684,6 +2631,8 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2684
2631
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2685
2632
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2686
2633
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2634
+ ///
2635
+ /// [`Offer`]: crate::offers::offer
2687
2636
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2688
2637
2689
2638
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -2692,8 +2641,10 @@ pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 6
2692
2641
pub enum RecentPaymentDetails {
2693
2642
/// When an invoice was requested and thus a payment has not yet been sent.
2694
2643
AwaitingInvoice {
2695
- /// A user-provided identifier in [`ChannelManager ::pay_for_offer`] used to uniquely identify a
2644
+ /// A user-provided identifier in [`OffersMessageFlow ::pay_for_offer`] used to uniquely identify a
2696
2645
/// payment and ensure idempotency in LDK.
2646
+ ///
2647
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2697
2648
payment_id: PaymentId,
2698
2649
},
2699
2650
/// When a payment is still being sent and awaiting successful delivery.
@@ -2702,7 +2653,7 @@ pub enum RecentPaymentDetails {
2702
2653
/// identify a payment and ensure idempotency in LDK.
2703
2654
///
2704
2655
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2705
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2656
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2706
2657
payment_id: PaymentId,
2707
2658
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
2708
2659
/// abandoned.
@@ -2719,7 +2670,7 @@ pub enum RecentPaymentDetails {
2719
2670
/// identify a payment and ensure idempotency in LDK.
2720
2671
///
2721
2672
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2722
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2673
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2723
2674
payment_id: PaymentId,
2724
2675
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2725
2676
/// made before LDK version 0.0.104.
@@ -2733,7 +2684,7 @@ pub enum RecentPaymentDetails {
2733
2684
/// identify a payment and ensure idempotency in LDK.
2734
2685
///
2735
2686
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2736
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2687
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2737
2688
payment_id: PaymentId,
2738
2689
/// Hash of the payment that we have given up trying to send.
2739
2690
payment_hash: PaymentHash,
@@ -4607,7 +4558,7 @@ where
4607
4558
///
4608
4559
/// # Requested Invoices
4609
4560
///
4610
- /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager ::pay_for_offer`], abandoning
4561
+ /// In the case of paying a [`Bolt12Invoice`] via [`OffersMessageFlow ::pay_for_offer`], abandoning
4611
4562
/// the payment prior to receiving the invoice will result in an [`Event::PaymentFailed`] and
4612
4563
/// prevent any attempts at paying it once received.
4613
4564
///
@@ -4617,6 +4568,7 @@ where
4617
4568
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
4618
4569
///
4619
4570
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4571
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
4620
4572
pub fn abandon_payment(&self, payment_id: PaymentId) {
4621
4573
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4622
4574
}
@@ -9348,6 +9300,13 @@ pub trait OffersMessageCommons {
9348
9300
///
9349
9301
/// [`Event::PaymentSent`]: events::Event::PaymentSent
9350
9302
fn list_recent_payments(&self) -> Vec<RecentPaymentDetails>;
9303
+
9304
+ /// Internal pay_for_offer
9305
+ fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>> (
9306
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9307
+ payer_note: Option<String>, payment_id: PaymentId,
9308
+ human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9309
+ ) -> Result<(), Bolt12SemanticError>;
9351
9310
}
9352
9311
9353
9312
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>
@@ -9525,7 +9484,6 @@ where
9525
9484
}
9526
9485
9527
9486
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<(), ()> {
9528
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9529
9487
self.pending_outbound_payments.add_new_awaiting_invoice (
9530
9488
payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9531
9489
)
@@ -9561,99 +9519,6 @@ where
9561
9519
})
9562
9520
.collect()
9563
9521
}
9564
- }
9565
-
9566
- /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9567
- /// along different paths.
9568
- /// Sending multiple requests increases the chances of successful delivery in case some
9569
- /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9570
- /// even if multiple invoices are received.
9571
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9572
-
9573
- 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>
9574
- where
9575
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9576
- T::Target: BroadcasterInterface,
9577
- ES::Target: EntropySource,
9578
- NS::Target: NodeSigner,
9579
- SP::Target: SignerProvider,
9580
- F::Target: FeeEstimator,
9581
- R::Target: Router,
9582
- MR::Target: MessageRouter,
9583
- L::Target: Logger,
9584
- {
9585
- /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9586
- /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9587
- /// [`Bolt12Invoice`] once it is received.
9588
- ///
9589
- /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
9590
- /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
9591
- /// The optional parameters are used in the builder, if `Some`:
9592
- /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
9593
- /// [`Offer::expects_quantity`] is `true`.
9594
- /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
9595
- /// - `payer_note` for [`InvoiceRequest::payer_note`].
9596
- ///
9597
- /// If `max_total_routing_fee_msat` is not specified, The default from
9598
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9599
- ///
9600
- /// # Payment
9601
- ///
9602
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9603
- /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9604
- /// been sent.
9605
- ///
9606
- /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9607
- /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9608
- /// payment will fail with an [`Event::PaymentFailed`].
9609
- ///
9610
- /// # Privacy
9611
- ///
9612
- /// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9613
- /// to construct a [`BlindedMessagePath`] for the reply path. For further privacy implications, see the
9614
- /// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9615
- ///
9616
- /// # Limitations
9617
- ///
9618
- /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
9619
- /// [`Offer::issuer_signing_pubkey`], if empty. A similar restriction applies to the responding
9620
- /// [`Bolt12Invoice::payment_paths`].
9621
- ///
9622
- /// # Errors
9623
- ///
9624
- /// Errors if:
9625
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9626
- /// - the provided parameters are invalid for the offer,
9627
- /// - the offer is for an unsupported chain, or
9628
- /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
9629
- /// request.
9630
- ///
9631
- /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
9632
- /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
9633
- /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
9634
- /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
9635
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9636
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9637
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9638
- pub fn pay_for_offer(
9639
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9640
- payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
9641
- max_total_routing_fee_msat: Option<u64>
9642
- ) -> Result<(), Bolt12SemanticError> {
9643
- self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, None, |invoice_request, nonce| {
9644
- let expiration = StaleExpiration::TimerTicks(1);
9645
- let retryable_invoice_request = RetryableInvoiceRequest {
9646
- invoice_request: invoice_request.clone(),
9647
- nonce,
9648
- };
9649
- self.pending_outbound_payments
9650
- .add_new_awaiting_invoice(
9651
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9652
- Some(retryable_invoice_request)
9653
- )
9654
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
9655
- })
9656
- }
9657
9522
9658
9523
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9659
9524
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -9701,7 +9566,27 @@ where
9701
9566
9702
9567
self.enqueue_invoice_request(invoice_request, reply_paths)
9703
9568
}
9569
+ }
9704
9570
9571
+ /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9572
+ /// along different paths.
9573
+ /// Sending multiple requests increases the chances of successful delivery in case some
9574
+ /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9575
+ /// even if multiple invoices are received.
9576
+ const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9577
+
9578
+ 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>
9579
+ where
9580
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9581
+ T::Target: BroadcasterInterface,
9582
+ ES::Target: EntropySource,
9583
+ NS::Target: NodeSigner,
9584
+ SP::Target: SignerProvider,
9585
+ F::Target: FeeEstimator,
9586
+ R::Target: Router,
9587
+ MR::Target: MessageRouter,
9588
+ L::Target: Logger,
9589
+ {
9705
9590
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9706
9591
/// message.
9707
9592
///
@@ -12246,6 +12131,8 @@ where
12246
12131
pub router: R,
12247
12132
/// The [`MessageRouter`] used for constructing [`BlindedMessagePath`]s for [`Offer`]s,
12248
12133
/// [`Refund`]s, and any reply paths.
12134
+ ///
12135
+ /// [`Offer`]: crate::offers::offer
12249
12136
pub message_router: MR,
12250
12137
/// The Logger for use in the ChannelManager and which may be used to log information during
12251
12138
/// deserialization.
0 commit comments