@@ -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::offers::flow::OffersMessageCommons;
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, InboundV2Channel, InteractivelyFunded as _};
@@ -68,7 +69,6 @@ use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, Retr
68
69
use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
69
70
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
70
71
use crate::offers::nonce::Nonce;
71
- use crate::offers::offer::Offer;
72
72
use crate::offers::parse::Bolt12SemanticError;
73
73
use crate::offers::refund::Refund;
74
74
use crate::offers::signer;
@@ -2022,57 +2022,7 @@ where
2022
2022
///
2023
2023
/// For more information on creating offers, see [`create_offer_builder`].
2024
2024
///
2025
- /// Use [`pay_for_offer`] to initiated payment, which sends an [`InvoiceRequest`] for an [`Offer`]
2026
- /// and pays the [`Bolt12Invoice`] response.
2027
- ///
2028
- /// ```
2029
- /// # use lightning::events::{Event, EventsProvider};
2030
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2031
- /// # use lightning::offers::flow::OffersMessageCommons;
2032
- /// # use lightning::offers::offer::Offer;
2033
- /// #
2034
- /// # fn example<T: AChannelManager>(
2035
- /// # channel_manager: T, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
2036
- /// # payer_note: Option<String>, retry: Retry, max_total_routing_fee_msat: Option<u64>
2037
- /// # ) {
2038
- /// # let channel_manager = channel_manager.get_cm();
2039
- /// let payment_id = PaymentId([42; 32]);
2040
- /// match channel_manager.pay_for_offer(
2041
- /// offer, quantity, amount_msats, payer_note, payment_id, retry, max_total_routing_fee_msat
2042
- /// ) {
2043
- /// Ok(()) => println!("Requesting invoice for offer"),
2044
- /// Err(e) => println!("Unable to request invoice for offer: {:?}", e),
2045
- /// }
2046
- ///
2047
- /// // First the payment will be waiting on an invoice
2048
- /// let expected_payment_id = payment_id;
2049
- /// assert!(
2050
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2051
- /// details,
2052
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2053
- /// )).is_some()
2054
- /// );
2055
- ///
2056
- /// // Once the invoice is received, a payment will be sent
2057
- /// assert!(
2058
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2059
- /// details,
2060
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2061
- /// )).is_some()
2062
- /// );
2063
- ///
2064
- /// // On the event processing thread
2065
- /// channel_manager.process_pending_events(&|event| {
2066
- /// match event {
2067
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2068
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2069
- /// // ...
2070
- /// # _ => {},
2071
- /// }
2072
- /// Ok(())
2073
- /// });
2074
- /// # }
2075
- /// ```
2025
+ /// For details on initiating payments for offers, see [`pay_for_offer`].
2076
2026
///
2077
2027
/// ## BOLT 12 Refunds
2078
2028
///
@@ -2203,7 +2153,7 @@ where
2203
2153
/// [`claim_funds`]: Self::claim_funds
2204
2154
/// [`send_payment`]: Self::send_payment
2205
2155
/// [`offers`]: crate::offers
2206
- /// [`pay_for_offer `]: Self::pay_for_offer
2156
+ /// [`Offer `]: crate::offers::offer
2207
2157
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2208
2158
/// [`request_refund_payment`]: Self::request_refund_payment
2209
2159
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
@@ -2214,6 +2164,7 @@ where
2214
2164
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2215
2165
/// [`read`]: ReadableArgs::read
2216
2166
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2167
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2217
2168
/// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2218
2169
//
2219
2170
// Lock order:
@@ -2725,6 +2676,8 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2725
2676
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2726
2677
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2727
2678
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2679
+ ///
2680
+ /// [`Offer`]: crate::offers::offer
2728
2681
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2729
2682
2730
2683
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -2733,8 +2686,10 @@ pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 6
2733
2686
pub enum RecentPaymentDetails {
2734
2687
/// When an invoice was requested and thus a payment has not yet been sent.
2735
2688
AwaitingInvoice {
2736
- /// A user-provided identifier in [`ChannelManager ::pay_for_offer`] used to uniquely identify a
2689
+ /// A user-provided identifier in [`OffersMessageFlow ::pay_for_offer`] used to uniquely identify a
2737
2690
/// payment and ensure idempotency in LDK.
2691
+ ///
2692
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
2738
2693
payment_id: PaymentId,
2739
2694
},
2740
2695
/// When a payment is still being sent and awaiting successful delivery.
@@ -2743,7 +2698,7 @@ pub enum RecentPaymentDetails {
2743
2698
/// identify a payment and ensure idempotency in LDK.
2744
2699
///
2745
2700
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2746
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2701
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2747
2702
payment_id: PaymentId,
2748
2703
/// Hash of the payment that is currently being sent but has yet to be fulfilled or
2749
2704
/// abandoned.
@@ -2760,7 +2715,7 @@ pub enum RecentPaymentDetails {
2760
2715
/// identify a payment and ensure idempotency in LDK.
2761
2716
///
2762
2717
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2763
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2718
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2764
2719
payment_id: PaymentId,
2765
2720
/// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`]
2766
2721
/// made before LDK version 0.0.104.
@@ -2774,7 +2729,7 @@ pub enum RecentPaymentDetails {
2774
2729
/// identify a payment and ensure idempotency in LDK.
2775
2730
///
2776
2731
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
2777
- /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager ::pay_for_offer
2732
+ /// [`pay_for_offer`]: crate::offers::flow::OffersMessageFlow ::pay_for_offer
2778
2733
payment_id: PaymentId,
2779
2734
/// Hash of the payment that we have given up trying to send.
2780
2735
payment_hash: PaymentHash,
@@ -4674,7 +4629,7 @@ where
4674
4629
///
4675
4630
/// # Requested Invoices
4676
4631
///
4677
- /// In the case of paying a [`Bolt12Invoice`] via [`ChannelManager ::pay_for_offer`], abandoning
4632
+ /// In the case of paying a [`Bolt12Invoice`] via [`OffersMessageFlow ::pay_for_offer`], abandoning
4678
4633
/// the payment prior to receiving the invoice will result in an [`Event::PaymentFailed`] and
4679
4634
/// prevent any attempts at paying it once received.
4680
4635
///
@@ -4684,6 +4639,7 @@ where
4684
4639
/// [`ChannelManager`], another [`Event::PaymentFailed`] may be generated.
4685
4640
///
4686
4641
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
4642
+ /// [`OffersMessageFlow::pay_for_offer`]: crate::offers::flow::OffersMessageFlow::pay_for_offer
4687
4643
pub fn abandon_payment(&self, payment_id: PaymentId) {
4688
4644
self.abandon_payment_with_reason(payment_id, PaymentFailureReason::UserAbandoned)
4689
4645
}
@@ -9839,104 +9795,10 @@ where
9839
9795
}
9840
9796
9841
9797
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<(), ()> {
9842
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9843
9798
self.pending_outbound_payments.add_new_awaiting_invoice (
9844
9799
payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9845
9800
)
9846
9801
}
9847
- }
9848
-
9849
- /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9850
- /// along different paths.
9851
- /// Sending multiple requests increases the chances of successful delivery in case some
9852
- /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9853
- /// even if multiple invoices are received.
9854
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9855
-
9856
- 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>
9857
- where
9858
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9859
- T::Target: BroadcasterInterface,
9860
- ES::Target: EntropySource,
9861
- NS::Target: NodeSigner,
9862
- SP::Target: SignerProvider,
9863
- F::Target: FeeEstimator,
9864
- R::Target: Router,
9865
- MR::Target: MessageRouter,
9866
- L::Target: Logger,
9867
- {
9868
- /// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9869
- /// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9870
- /// [`Bolt12Invoice`] once it is received.
9871
- ///
9872
- /// Uses [`InvoiceRequestBuilder`] such that the [`InvoiceRequest`] it builds is recognized by
9873
- /// the [`ChannelManager`] when handling a [`Bolt12Invoice`] message in response to the request.
9874
- /// The optional parameters are used in the builder, if `Some`:
9875
- /// - `quantity` for [`InvoiceRequest::quantity`] which must be set if
9876
- /// [`Offer::expects_quantity`] is `true`.
9877
- /// - `amount_msats` if overpaying what is required for the given `quantity` is desired, and
9878
- /// - `payer_note` for [`InvoiceRequest::payer_note`].
9879
- ///
9880
- /// If `max_total_routing_fee_msat` is not specified, The default from
9881
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9882
- ///
9883
- /// # Payment
9884
- ///
9885
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9886
- /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9887
- /// been sent.
9888
- ///
9889
- /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9890
- /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9891
- /// payment will fail with an [`Event::PaymentFailed`].
9892
- ///
9893
- /// # Privacy
9894
- ///
9895
- /// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9896
- /// to construct a [`BlindedMessagePath`] for the reply path. For further privacy implications, see the
9897
- /// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9898
- ///
9899
- /// # Limitations
9900
- ///
9901
- /// Requires a direct connection to an introduction node in [`Offer::paths`] or to
9902
- /// [`Offer::issuer_signing_pubkey`], if empty. A similar restriction applies to the responding
9903
- /// [`Bolt12Invoice::payment_paths`].
9904
- ///
9905
- /// # Errors
9906
- ///
9907
- /// Errors if:
9908
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9909
- /// - the provided parameters are invalid for the offer,
9910
- /// - the offer is for an unsupported chain, or
9911
- /// - the parameterized [`Router`] is unable to create a blinded reply path for the invoice
9912
- /// request.
9913
- ///
9914
- /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
9915
- /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
9916
- /// [`InvoiceRequest::payer_note`]: crate::offers::invoice_request::InvoiceRequest::payer_note
9917
- /// [`InvoiceRequestBuilder`]: crate::offers::invoice_request::InvoiceRequestBuilder
9918
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9919
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9920
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9921
- pub fn pay_for_offer(
9922
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9923
- payer_note: Option<String>, payment_id: PaymentId, retry_strategy: Retry,
9924
- max_total_routing_fee_msat: Option<u64>
9925
- ) -> Result<(), Bolt12SemanticError> {
9926
- self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, None, |invoice_request, nonce| {
9927
- let expiration = StaleExpiration::TimerTicks(1);
9928
- let retryable_invoice_request = RetryableInvoiceRequest {
9929
- invoice_request: invoice_request.clone(),
9930
- nonce,
9931
- };
9932
- self.pending_outbound_payments
9933
- .add_new_awaiting_invoice(
9934
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat,
9935
- Some(retryable_invoice_request)
9936
- )
9937
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
9938
- })
9939
- }
9940
9802
9941
9803
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9942
9804
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -9984,7 +9846,27 @@ where
9984
9846
9985
9847
self.enqueue_invoice_request(invoice_request, reply_paths)
9986
9848
}
9849
+ }
9850
+
9851
+ /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9852
+ /// along different paths.
9853
+ /// Sending multiple requests increases the chances of successful delivery in case some
9854
+ /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9855
+ /// even if multiple invoices are received.
9856
+ const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9987
9857
9858
+ 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>
9859
+ where
9860
+ M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
9861
+ T::Target: BroadcasterInterface,
9862
+ ES::Target: EntropySource,
9863
+ NS::Target: NodeSigner,
9864
+ SP::Target: SignerProvider,
9865
+ F::Target: FeeEstimator,
9866
+ R::Target: Router,
9867
+ MR::Target: MessageRouter,
9868
+ L::Target: Logger,
9869
+ {
9988
9870
/// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9989
9871
/// message.
9990
9872
///
@@ -12552,6 +12434,8 @@ where
12552
12434
pub router: R,
12553
12435
/// The [`MessageRouter`] used for constructing [`BlindedMessagePath`]s for [`Offer`]s,
12554
12436
/// [`Refund`]s, and any reply paths.
12437
+ ///
12438
+ /// [`Offer`]: crate::offers::offer
12555
12439
pub message_router: MR,
12556
12440
/// The Logger for use in the ChannelManager and which may be used to log information during
12557
12441
/// deserialization.
0 commit comments