@@ -70,7 +70,7 @@ use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
70
70
use crate::offers::nonce::Nonce;
71
71
use crate::offers::offer::Offer;
72
72
use crate::offers::parse::Bolt12SemanticError;
73
- use crate::offers::refund::{ Refund, RefundBuilder} ;
73
+ use crate::offers::refund::Refund;
74
74
use crate::offers::signer;
75
75
#[cfg(async_payments)]
76
76
use crate::offers::static_invoice::StaticInvoice;
@@ -102,8 +102,6 @@ use {
102
102
crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
103
103
crate::sign::KeysManager,
104
104
};
105
- #[cfg(c_bindings)]
106
- use crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder;
107
105
108
106
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, CreationError, Currency, Description, InvoiceBuilder as Bolt11InvoiceBuilder, SignOrCreationError, DEFAULT_EXPIRY_TIME};
109
107
@@ -1975,6 +1973,7 @@ where
1975
1973
/// # use lightning::events::{Event, EventsProvider};
1976
1974
/// # use lightning::types::payment::PaymentHash;
1977
1975
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
1976
+ /// # use lightning::offers::flow::OffersMessageCommons;
1978
1977
/// # use lightning::routing::router::RouteParameters;
1979
1978
/// #
1980
1979
/// # fn example<T: AChannelManager>(
@@ -2029,6 +2028,7 @@ where
2029
2028
/// ```
2030
2029
/// # use lightning::events::{Event, EventsProvider};
2031
2030
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2031
+ /// # use lightning::offers::flow::OffersMessageCommons;
2032
2032
/// # use lightning::offers::offer::Offer;
2033
2033
/// #
2034
2034
/// # fn example<T: AChannelManager>(
@@ -2075,67 +2075,8 @@ where
2075
2075
/// ```
2076
2076
///
2077
2077
/// ## BOLT 12 Refunds
2078
- ///
2079
- /// A [`Refund`] is a request for an invoice to be paid. Like *paying* for an [`Offer`], *creating*
2080
- /// a [`Refund`] involves maintaining state since it represents a future outbound payment.
2081
- /// Therefore, use [`create_refund_builder`] when creating one, otherwise [`ChannelManager`] will
2082
- /// refuse to pay any corresponding [`Bolt12Invoice`] that it receives.
2083
- ///
2084
- /// ```
2085
- /// # use core::time::Duration;
2086
- /// # use lightning::events::{Event, EventsProvider};
2087
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2088
- /// # use lightning::offers::parse::Bolt12SemanticError;
2089
- /// #
2090
- /// # fn example<T: AChannelManager>(
2091
- /// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
2092
- /// # max_total_routing_fee_msat: Option<u64>
2093
- /// # ) -> Result<(), Bolt12SemanticError> {
2094
- /// # let channel_manager = channel_manager.get_cm();
2095
- /// let payment_id = PaymentId([42; 32]);
2096
- /// let refund = channel_manager
2097
- /// .create_refund_builder(
2098
- /// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
2099
- /// )?
2100
- /// # ;
2101
- /// # // Needed for compiling for c_bindings
2102
- /// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
2103
- /// # let refund = builder
2104
- /// .description("coffee".to_string())
2105
- /// .payer_note("refund for order 1234".to_string())
2106
- /// .build()?;
2107
- /// let bech32_refund = refund.to_string();
2108
- ///
2109
- /// // First the payment will be waiting on an invoice
2110
- /// let expected_payment_id = payment_id;
2111
- /// assert!(
2112
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2113
- /// details,
2114
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2115
- /// )).is_some()
2116
- /// );
2117
- ///
2118
- /// // Once the invoice is received, a payment will be sent
2119
- /// assert!(
2120
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2121
- /// details,
2122
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2123
- /// )).is_some()
2124
- /// );
2125
- ///
2126
- /// // On the event processing thread
2127
- /// channel_manager.process_pending_events(&|event| {
2128
- /// match event {
2129
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2130
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2131
- /// // ...
2132
- /// # _ => {},
2133
- /// }
2134
- /// Ok(())
2135
- /// });
2136
- /// # Ok(())
2137
- /// # }
2138
- /// ```
2078
+ ///
2079
+ /// For more information on creating refunds, see [`create_refund_builder`].
2139
2080
///
2140
2081
/// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2141
2082
/// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
@@ -2264,7 +2205,6 @@ where
2264
2205
/// [`offers`]: crate::offers
2265
2206
/// [`pay_for_offer`]: Self::pay_for_offer
2266
2207
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2267
- /// [`create_refund_builder`]: Self::create_refund_builder
2268
2208
/// [`request_refund_payment`]: Self::request_refund_payment
2269
2209
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2270
2210
/// [`funding_created`]: msgs::FundingCreated
@@ -2274,6 +2214,7 @@ where
2274
2214
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2275
2215
/// [`read`]: ReadableArgs::read
2276
2216
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2217
+ /// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2277
2218
//
2278
2219
// Lock order:
2279
2220
// The tree structure below illustrates the lock order requirements for the different locks of the
@@ -2772,12 +2713,14 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2772
2713
/// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2773
2714
/// short-lived, while anything with a greater expiration is considered long-lived.
2774
2715
///
2775
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`ChannelManager ::create_refund_builder`],
2716
+ /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow ::create_refund_builder`],
2776
2717
/// will included a [`BlindedMessagePath`] created using:
2777
2718
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2778
2719
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2779
2720
///
2780
2721
/// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2722
+ /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2723
+ ///
2781
2724
///
2782
2725
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2783
2726
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -9671,87 +9614,6 @@ impl Default for Bolt11InvoiceParameters {
9671
9614
}
9672
9615
}
9673
9616
9674
- macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
9675
- /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
9676
- /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
9677
- ///
9678
- /// # Payment
9679
- ///
9680
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
9681
- /// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
9682
- ///
9683
- /// The builder will have the provided expiration set. Any changes to the expiration on the
9684
- /// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
9685
- /// block time minus two hours is used for the current time when determining if the refund has
9686
- /// expired.
9687
- ///
9688
- /// To revoke the refund, use [`ChannelManager::abandon_payment`] prior to receiving the
9689
- /// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
9690
- /// with an [`Event::PaymentFailed`].
9691
- ///
9692
- /// If `max_total_routing_fee_msat` is not specified, The default from
9693
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9694
- ///
9695
- /// # Privacy
9696
- ///
9697
- /// Uses [`MessageRouter`] to construct a [`BlindedMessagePath`] for the refund based on the given
9698
- /// `absolute_expiry` according to [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`]. See those docs for
9699
- /// privacy implications as well as those of the parameterized [`Router`], which implements
9700
- /// [`MessageRouter`].
9701
- ///
9702
- /// Also, uses a derived payer id in the refund for payer privacy.
9703
- ///
9704
- /// # Limitations
9705
- ///
9706
- /// Requires a direct connection to an introduction node in the responding
9707
- /// [`Bolt12Invoice::payment_paths`].
9708
- ///
9709
- /// # Errors
9710
- ///
9711
- /// Errors if:
9712
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9713
- /// - `amount_msats` is invalid, or
9714
- /// - the parameterized [`Router`] is unable to create a blinded path for the refund.
9715
- ///
9716
- /// [`Refund`]: crate::offers::refund::Refund
9717
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9718
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9719
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9720
- pub fn create_refund_builder(
9721
- &$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
9722
- retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
9723
- ) -> Result<$builder, Bolt12SemanticError> {
9724
- let node_id = $self.get_our_node_id();
9725
- let expanded_key = &$self.inbound_payment_key;
9726
- let entropy = &*$self.entropy_source;
9727
- let secp_ctx = &$self.secp_ctx;
9728
-
9729
- let nonce = Nonce::from_entropy_source(entropy);
9730
- let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
9731
- let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
9732
- .and_then(|paths| paths.into_iter().next().ok_or(()))
9733
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9734
-
9735
- let builder = RefundBuilder::deriving_signing_pubkey(
9736
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
9737
- )?
9738
- .chain_hash($self.chain_hash)
9739
- .absolute_expiry(absolute_expiry)
9740
- .path(path);
9741
-
9742
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
9743
-
9744
- let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
9745
- $self.pending_outbound_payments
9746
- .add_new_awaiting_invoice(
9747
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
9748
- )
9749
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
9750
-
9751
- Ok(builder.into())
9752
- }
9753
- } }
9754
-
9755
9617
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>
9756
9618
where
9757
9619
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
@@ -9975,6 +9837,13 @@ where
9975
9837
fn get_chain_hash(&self) -> ChainHash {
9976
9838
self.chain_hash
9977
9839
}
9840
+
9841
+ 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
+ self.pending_outbound_payments.add_new_awaiting_invoice (
9844
+ payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9845
+ )
9846
+ }
9978
9847
}
9979
9848
9980
9849
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9996,12 +9865,6 @@ where
9996
9865
MR::Target: MessageRouter,
9997
9866
L::Target: Logger,
9998
9867
{
9999
- #[cfg(not(c_bindings))]
10000
- create_refund_builder!(self, RefundBuilder<secp256k1::All>);
10001
-
10002
- #[cfg(c_bindings)]
10003
- create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
10004
-
10005
9868
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
10006
9869
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
10007
9870
/// [`Bolt12Invoice`] once it is received.
0 commit comments