@@ -68,7 +68,7 @@ use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
68
68
use crate::offers::nonce::Nonce;
69
69
use crate::offers::offer::Offer;
70
70
use crate::offers::parse::Bolt12SemanticError;
71
- use crate::offers::refund::{ Refund, RefundBuilder} ;
71
+ use crate::offers::refund::Refund;
72
72
use crate::offers::signer;
73
73
#[cfg(async_payments)]
74
74
use crate::offers::static_invoice::StaticInvoice;
@@ -100,8 +100,6 @@ use {
100
100
crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
101
101
crate::sign::KeysManager,
102
102
};
103
- #[cfg(c_bindings)]
104
- use crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder;
105
103
106
104
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, CreationError, Currency, Description, InvoiceBuilder as Bolt11InvoiceBuilder, SignOrCreationError, DEFAULT_EXPIRY_TIME};
107
105
@@ -1957,6 +1955,7 @@ where
1957
1955
/// # use lightning::events::{Event, EventsProvider};
1958
1956
/// # use lightning::types::payment::PaymentHash;
1959
1957
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
1958
+ /// # use lightning::offers::flow::OffersMessageCommons;
1960
1959
/// # use lightning::routing::router::RouteParameters;
1961
1960
/// #
1962
1961
/// # fn example<T: AChannelManager>(
@@ -2011,6 +2010,7 @@ where
2011
2010
/// ```
2012
2011
/// # use lightning::events::{Event, EventsProvider};
2013
2012
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2013
+ /// # use lightning::offers::flow::OffersMessageCommons;
2014
2014
/// # use lightning::offers::offer::Offer;
2015
2015
/// #
2016
2016
/// # fn example<T: AChannelManager>(
@@ -2057,67 +2057,8 @@ where
2057
2057
/// ```
2058
2058
///
2059
2059
/// ## BOLT 12 Refunds
2060
- ///
2061
- /// A [`Refund`] is a request for an invoice to be paid. Like *paying* for an [`Offer`], *creating*
2062
- /// a [`Refund`] involves maintaining state since it represents a future outbound payment.
2063
- /// Therefore, use [`create_refund_builder`] when creating one, otherwise [`ChannelManager`] will
2064
- /// refuse to pay any corresponding [`Bolt12Invoice`] that it receives.
2065
- ///
2066
- /// ```
2067
- /// # use core::time::Duration;
2068
- /// # use lightning::events::{Event, EventsProvider};
2069
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2070
- /// # use lightning::offers::parse::Bolt12SemanticError;
2071
- /// #
2072
- /// # fn example<T: AChannelManager>(
2073
- /// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
2074
- /// # max_total_routing_fee_msat: Option<u64>
2075
- /// # ) -> Result<(), Bolt12SemanticError> {
2076
- /// # let channel_manager = channel_manager.get_cm();
2077
- /// let payment_id = PaymentId([42; 32]);
2078
- /// let refund = channel_manager
2079
- /// .create_refund_builder(
2080
- /// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
2081
- /// )?
2082
- /// # ;
2083
- /// # // Needed for compiling for c_bindings
2084
- /// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
2085
- /// # let refund = builder
2086
- /// .description("coffee".to_string())
2087
- /// .payer_note("refund for order 1234".to_string())
2088
- /// .build()?;
2089
- /// let bech32_refund = refund.to_string();
2090
- ///
2091
- /// // First the payment will be waiting on an invoice
2092
- /// let expected_payment_id = payment_id;
2093
- /// assert!(
2094
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2095
- /// details,
2096
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2097
- /// )).is_some()
2098
- /// );
2099
- ///
2100
- /// // Once the invoice is received, a payment will be sent
2101
- /// assert!(
2102
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2103
- /// details,
2104
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2105
- /// )).is_some()
2106
- /// );
2107
- ///
2108
- /// // On the event processing thread
2109
- /// channel_manager.process_pending_events(&|event| {
2110
- /// match event {
2111
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2112
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2113
- /// // ...
2114
- /// # _ => {},
2115
- /// }
2116
- /// Ok(())
2117
- /// });
2118
- /// # Ok(())
2119
- /// # }
2120
- /// ```
2060
+ ///
2061
+ /// For more information on creating refunds, see [`create_refund_builder`].
2121
2062
///
2122
2063
/// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2123
2064
/// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
@@ -2246,7 +2187,6 @@ where
2246
2187
/// [`offers`]: crate::offers
2247
2188
/// [`pay_for_offer`]: Self::pay_for_offer
2248
2189
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2249
- /// [`create_refund_builder`]: Self::create_refund_builder
2250
2190
/// [`request_refund_payment`]: Self::request_refund_payment
2251
2191
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2252
2192
/// [`funding_created`]: msgs::FundingCreated
@@ -2256,6 +2196,7 @@ where
2256
2196
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2257
2197
/// [`read`]: ReadableArgs::read
2258
2198
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2199
+ /// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2259
2200
//
2260
2201
// Lock order:
2261
2202
// The tree structure below illustrates the lock order requirements for the different locks of the
@@ -2752,12 +2693,14 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2752
2693
/// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2753
2694
/// short-lived, while anything with a greater expiration is considered long-lived.
2754
2695
///
2755
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`ChannelManager ::create_refund_builder`],
2696
+ /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow ::create_refund_builder`],
2756
2697
/// will included a [`BlindedMessagePath`] created using:
2757
2698
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2758
2699
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2759
2700
///
2760
2701
/// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2702
+ /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2703
+ ///
2761
2704
///
2762
2705
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2763
2706
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -9593,87 +9536,6 @@ impl Default for Bolt11InvoiceParameters {
9593
9536
}
9594
9537
}
9595
9538
9596
- macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
9597
- /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
9598
- /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
9599
- ///
9600
- /// # Payment
9601
- ///
9602
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
9603
- /// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
9604
- ///
9605
- /// The builder will have the provided expiration set. Any changes to the expiration on the
9606
- /// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
9607
- /// block time minus two hours is used for the current time when determining if the refund has
9608
- /// expired.
9609
- ///
9610
- /// To revoke the refund, use [`ChannelManager::abandon_payment`] prior to receiving the
9611
- /// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
9612
- /// with an [`Event::PaymentFailed`].
9613
- ///
9614
- /// If `max_total_routing_fee_msat` is not specified, The default from
9615
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9616
- ///
9617
- /// # Privacy
9618
- ///
9619
- /// Uses [`MessageRouter`] to construct a [`BlindedMessagePath`] for the refund based on the given
9620
- /// `absolute_expiry` according to [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`]. See those docs for
9621
- /// privacy implications as well as those of the parameterized [`Router`], which implements
9622
- /// [`MessageRouter`].
9623
- ///
9624
- /// Also, uses a derived payer id in the refund for payer privacy.
9625
- ///
9626
- /// # Limitations
9627
- ///
9628
- /// Requires a direct connection to an introduction node in the responding
9629
- /// [`Bolt12Invoice::payment_paths`].
9630
- ///
9631
- /// # Errors
9632
- ///
9633
- /// Errors if:
9634
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9635
- /// - `amount_msats` is invalid, or
9636
- /// - the parameterized [`Router`] is unable to create a blinded path for the refund.
9637
- ///
9638
- /// [`Refund`]: crate::offers::refund::Refund
9639
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9640
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9641
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9642
- pub fn create_refund_builder(
9643
- &$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
9644
- retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
9645
- ) -> Result<$builder, Bolt12SemanticError> {
9646
- let node_id = $self.get_our_node_id();
9647
- let expanded_key = &$self.inbound_payment_key;
9648
- let entropy = &*$self.entropy_source;
9649
- let secp_ctx = &$self.secp_ctx;
9650
-
9651
- let nonce = Nonce::from_entropy_source(entropy);
9652
- let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
9653
- let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
9654
- .and_then(|paths| paths.into_iter().next().ok_or(()))
9655
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9656
-
9657
- let builder = RefundBuilder::deriving_signing_pubkey(
9658
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
9659
- )?
9660
- .chain_hash($self.chain_hash)
9661
- .absolute_expiry(absolute_expiry)
9662
- .path(path);
9663
-
9664
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
9665
-
9666
- let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
9667
- $self.pending_outbound_payments
9668
- .add_new_awaiting_invoice(
9669
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
9670
- )
9671
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
9672
-
9673
- Ok(builder.into())
9674
- }
9675
- } }
9676
-
9677
9539
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>
9678
9540
where
9679
9541
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
@@ -9897,6 +9759,13 @@ where
9897
9759
fn get_chain_hash(&self) -> ChainHash {
9898
9760
self.chain_hash
9899
9761
}
9762
+
9763
+ 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<(), ()> {
9764
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9765
+ self.pending_outbound_payments.add_new_awaiting_invoice (
9766
+ payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9767
+ )
9768
+ }
9900
9769
}
9901
9770
9902
9771
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9918,12 +9787,6 @@ where
9918
9787
MR::Target: MessageRouter,
9919
9788
L::Target: Logger,
9920
9789
{
9921
- #[cfg(not(c_bindings))]
9922
- create_refund_builder!(self, RefundBuilder<secp256k1::All>);
9923
-
9924
- #[cfg(c_bindings)]
9925
- create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
9926
-
9927
9790
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9928
9791
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9929
9792
/// [`Bolt12Invoice`] once it is received.
0 commit comments