@@ -47,6 +47,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
47
47
// construct one themselves.
48
48
use crate::ln::inbound_payment;
49
49
use crate::ln::types::ChannelId;
50
+ use crate::offers::offer::Offer;
50
51
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
51
52
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
52
53
use crate::ln::channel_state::ChannelDetails;
@@ -65,7 +66,6 @@ use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, Retr
65
66
use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
66
67
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
67
68
use crate::offers::nonce::Nonce;
68
- use crate::offers::offer::Offer;
69
69
use crate::offers::parse::Bolt12SemanticError;
70
70
use crate::offers::refund::Refund;
71
71
use crate::offers::signer;
@@ -2009,56 +2009,7 @@ where
2009
2009
///
2010
2010
/// For more information on creating offers, see [`create_offer_builder`].
2011
2011
///
2012
- /// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
2013
- /// and pays the [`Bolt12Invoice`] response.
2014
- ///
2015
- /// ```
2016
- /// # use lightning::events::{Event, EventsProvider};
2017
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons, PaymentId, RecentPaymentDetails, Retry};
2018
- /// # use lightning::offers::offer::Offer;
2019
- /// #
2020
- /// # fn example<T: AChannelManager>(
2021
- /// # channel_manager: T, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
2022
- /// # payer_note: Option<String>, retry: Retry, max_total_routing_fee_msat: Option<u64>
2023
- /// # ) {
2024
- /// # let channel_manager = channel_manager.get_cm();
2025
- /// let payment_id = PaymentId([42; 32]);
2026
- /// match channel_manager.pay_for_offer(
2027
- /// offer, quantity, amount_msats, payer_note, payment_id, retry, max_total_routing_fee_msat
2028
- /// ) {
2029
- /// Ok(()) => println!("Requesting invoice for offer"),
2030
- /// Err(e) => println!("Unable to request invoice for offer: {:?}", e),
2031
- /// }
2032
- ///
2033
- /// // First the payment will be waiting on an invoice
2034
- /// let expected_payment_id = payment_id;
2035
- /// assert!(
2036
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2037
- /// details,
2038
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2039
- /// )).is_some()
2040
- /// );
2041
- ///
2042
- /// // Once the invoice is received, a payment will be sent
2043
- /// assert!(
2044
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2045
- /// details,
2046
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2047
- /// )).is_some()
2048
- /// );
2049
- ///
2050
- /// // On the event processing thread
2051
- /// channel_manager.process_pending_events(&|event| {
2052
- /// match event {
2053
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2054
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2055
- /// // ...
2056
- /// # _ => {},
2057
- /// }
2058
- /// Ok(())
2059
- /// });
2060
- /// # }
2061
- /// ```
2012
+ /// For details on initiating payments for offers, see [`pay_for_offer`].
2062
2013
///
2063
2014
/// ## BOLT 12 Refunds
2064
2015
///
@@ -2188,7 +2139,7 @@ where
2188
2139
/// [`claim_funds`]: Self::claim_funds
2189
2140
/// [`send_payment`]: Self::send_payment
2190
2141
/// [`offers`]: crate::offers
2191
- /// [`pay_for_offer `]: Self::pay_for_offer
2142
+ /// [`Offer `]: crate::offers::offer
2192
2143
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2193
2144
/// [`request_refund_payment`]: Self::request_refund_payment
2194
2145
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
@@ -2199,6 +2150,7 @@ where
2199
2150
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2200
2151
/// [`read`]: ReadableArgs::read
2201
2152
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2153
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2202
2154
/// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2203
2155
//
2204
2156
// Lock order:
@@ -2708,6 +2660,8 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2708
2660
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2709
2661
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2710
2662
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2663
+ ///
2664
+ /// [`Offer`]: crate::offers::offer
2711
2665
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2712
2666
2713
2667
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -2716,8 +2670,10 @@ pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 6
2716
2670
pub enum RecentPaymentDetails {
2717
2671
/// When an invoice was requested and thus a payment has not yet been sent.
2718
2672
AwaitingInvoice {
2719
- /// A user-provided identifier in [`ChannelManager ::pay_for_offer`] used to uniquely identify a
2673
+ /// A user-provided identifier in [`OffersMessageFlow ::pay_for_offer`] used to uniquely identify a
2720
2674
/// payment and ensure idempotency in LDK.
2675
+ ///
2676
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2721
2677
payment_id: PaymentId,
2722
2678
},
2723
2679
/// When a payment is still being sent and awaiting successful delivery.
@@ -2726,7 +2682,7 @@ pub enum RecentPaymentDetails {
2726
2682
/// identify a payment and ensure idempotency in LDK.
2727
2683
///
2728
2684
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2729
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2685
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2730
2686
payment_id: PaymentId,
2731
2687
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
2732
2688
/// abandoned.
@@ -2743,7 +2699,7 @@ pub enum RecentPaymentDetails {
2743
2699
/// identify a payment and ensure idempotency in LDK.
2744
2700
///
2745
2701
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2746
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2702
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2747
2703
payment_id: PaymentId,
2748
2704
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2749
2705
/// made before LDK version 0.0.104.
@@ -2757,7 +2713,7 @@ pub enum RecentPaymentDetails {
2757
2713
/// identify a payment and ensure idempotency in LDK.
2758
2714
///
2759
2715
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2760
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2716
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2761
2717
payment_id: PaymentId,
2762
2718
/// Hash of the payment that we have given up trying to send.
2763
2719
payment_hash: PaymentHash,
@@ -4643,7 +4599,7 @@ where
4643
4599
///
4644
4600
/// # Requested Invoices
4645
4601
///
4646
- /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager ::pay_for_offer`], abandoning
4602
+ /// In the case of paying a [`Bolt12Invoice`] via [`OffersMessageFlow ::pay_for_offer`], abandoning
4647
4603
/// the payment prior to receiving the invoice will result in an [`Event::PaymentFailed`] and
4648
4604
/// prevent any attempts at paying it once received.
4649
4605
///
@@ -4653,6 +4609,7 @@ where
4653
4609
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
4654
4610
///
4655
4611
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4612
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
4656
4613
pub fn abandon_payment(&self, payment_id: PaymentId) {
4657
4614
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4658
4615
}
@@ -9711,6 +9668,13 @@ pub trait OffersMessageCommons {
9711
9668
9712
9669
/// Add new awaiting invoice
9713
9670
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<(), ()>;
9671
+
9672
+ /// Internal pay_for_offer
9673
+ fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>> (
9674
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9675
+ payer_note: Option<String>, payment_id: PaymentId,
9676
+ human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9677
+ ) -> Result<(), Bolt12SemanticError>;
9714
9678
}
9715
9679
9716
9680
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>
@@ -9894,104 +9858,10 @@ where
9894
9858
}
9895
9859
9896
9860
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<(), ()> {
9897
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9898
9861
self.pending_outbound_payments.add_new_awaiting_invoice (
9899
9862
payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9900
9863
)
9901
9864
}
9902
- }
9903
-
9904
- /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9905
- /// along different paths.
9906
- /// Sending multiple requests increases the chances of successful delivery in case some
9907
- /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9908
- /// even if multiple invoices are received.
9909
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9910
-
9911
- 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>
9912
- where
9913
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9914
- T::Target: BroadcasterInterface,
9915
- ES::Target: EntropySource,
9916
- NS::Target: NodeSigner,
9917
- SP::Target: SignerProvider,
9918
- F::Target: FeeEstimator,
9919
- R::Target: Router,
9920
- MR::Target: MessageRouter,
9921
- L::Target: Logger,
9922
- {
9923
- /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9924
- /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9925
- /// [`Bolt12Invoice`] once it is received.
9926
- ///
9927
- /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
9928
- /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
9929
- /// The optional parameters are used in the builder, if `Some`:
9930
- /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
9931
- /// [`Offer::expects_quantity`] is `true`.
9932
- /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
9933
- /// - `payer_note` for [`InvoiceRequest::payer_note`].
9934
- ///
9935
- /// If `max_total_routing_fee_msat` is not specified, The default from
9936
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9937
- ///
9938
- /// # Payment
9939
- ///
9940
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9941
- /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9942
- /// been sent.
9943
- ///
9944
- /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9945
- /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9946
- /// payment will fail with an [`Event::PaymentFailed`].
9947
- ///
9948
- /// # Privacy
9949
- ///
9950
- /// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9951
- /// to construct a [`BlindedMessagePath`] for the reply path. For further privacy implications, see the
9952
- /// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9953
- ///
9954
- /// # Limitations
9955
- ///
9956
- /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
9957
- /// [`Offer::issuer_signing_pubkey`], if empty. A similar restriction applies to the responding
9958
- /// [`Bolt12Invoice::payment_paths`].
9959
- ///
9960
- /// # Errors
9961
- ///
9962
- /// Errors if:
9963
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9964
- /// - the provided parameters are invalid for the offer,
9965
- /// - the offer is for an unsupported chain, or
9966
- /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
9967
- /// request.
9968
- ///
9969
- /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
9970
- /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
9971
- /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
9972
- /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
9973
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9974
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9975
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9976
- pub fn pay_for_offer(
9977
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9978
- payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
9979
- max_total_routing_fee_msat: Option<u64>
9980
- ) -> Result<(), Bolt12SemanticError> {
9981
- self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, None, |invoice_request, nonce| {
9982
- let expiration = StaleExpiration::TimerTicks(1);
9983
- let retryable_invoice_request = RetryableInvoiceRequest {
9984
- invoice_request: invoice_request.clone(),
9985
- nonce,
9986
- };
9987
- self.pending_outbound_payments
9988
- .add_new_awaiting_invoice(
9989
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9990
- Some(retryable_invoice_request)
9991
- )
9992
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
9993
- })
9994
- }
9995
9865
9996
9866
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9997
9867
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -10039,7 +9909,27 @@ where
10039
9909
10040
9910
self.enqueue_invoice_request(invoice_request, reply_paths)
10041
9911
}
9912
+ }
10042
9913
9914
+ /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9915
+ /// along different paths.
9916
+ /// Sending multiple requests increases the chances of successful delivery in case some
9917
+ /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9918
+ /// even if multiple invoices are received.
9919
+ const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9920
+
9921
+ 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>
9922
+ where
9923
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9924
+ T::Target: BroadcasterInterface,
9925
+ ES::Target: EntropySource,
9926
+ NS::Target: NodeSigner,
9927
+ SP::Target: SignerProvider,
9928
+ F::Target: FeeEstimator,
9929
+ R::Target: Router,
9930
+ MR::Target: MessageRouter,
9931
+ L::Target: Logger,
9932
+ {
10043
9933
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
10044
9934
/// message.
10045
9935
///
@@ -12603,6 +12493,8 @@ where
12603
12493
pub router: R,
12604
12494
/// The [`MessageRouter`] used for constructing [`BlindedMessagePath`]s for [`Offer`]s,
12605
12495
/// [`Refund`]s, and any reply paths.
12496
+ ///
12497
+ /// [`Offer`]: crate::offers::offer
12606
12498
pub message_router: MR,
12607
12499
/// The Logger for use in the ChannelManager and which may be used to log information during
12608
12500
/// deserialization.
0 commit comments