@@ -69,7 +69,7 @@ use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
69
69
use crate::offers::nonce::Nonce;
70
70
use crate::offers::offer::Offer;
71
71
use crate::offers::parse::Bolt12SemanticError;
72
- use crate::offers::refund::{ Refund, RefundBuilder} ;
72
+ use crate::offers::refund::Refund;
73
73
use crate::offers::signer;
74
74
#[cfg(async_payments)]
75
75
use crate::offers::static_invoice::StaticInvoice;
@@ -1953,7 +1953,7 @@ where
1953
1953
/// ```
1954
1954
/// # use lightning::events::{Event, EventsProvider};
1955
1955
/// # use lightning::types::payment::PaymentHash;
1956
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
1956
+ /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons, PaymentId, RecentPaymentDetails, RecipientOnionFields, Retry};
1957
1957
/// # use lightning::routing::router::RouteParameters;
1958
1958
/// #
1959
1959
/// # fn example<T: AChannelManager>(
@@ -2007,7 +2007,7 @@ where
2007
2007
///
2008
2008
/// ```
2009
2009
/// # use lightning::events::{Event, EventsProvider};
2010
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2010
+ /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons, PaymentId, RecentPaymentDetails, Retry};
2011
2011
/// # use lightning::offers::offer::Offer;
2012
2012
/// #
2013
2013
/// # fn example<T: AChannelManager>(
@@ -2054,67 +2054,8 @@ where
2054
2054
/// ```
2055
2055
///
2056
2056
/// ## BOLT 12 Refunds
2057
- ///
2058
- /// A [`Refund`] is a request for an invoice to be paid. Like *paying* for an [`Offer`], *creating*
2059
- /// a [`Refund`] involves maintaining state since it represents a future outbound payment.
2060
- /// Therefore, use [`create_refund_builder`] when creating one, otherwise [`ChannelManager`] will
2061
- /// refuse to pay any corresponding [`Bolt12Invoice`] that it receives.
2062
- ///
2063
- /// ```
2064
- /// # use core::time::Duration;
2065
- /// # use lightning::events::{Event, EventsProvider};
2066
- /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
2067
- /// # use lightning::offers::parse::Bolt12SemanticError;
2068
- /// #
2069
- /// # fn example<T: AChannelManager>(
2070
- /// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
2071
- /// # max_total_routing_fee_msat: Option<u64>
2072
- /// # ) -> Result<(), Bolt12SemanticError> {
2073
- /// # let channel_manager = channel_manager.get_cm();
2074
- /// let payment_id = PaymentId([42; 32]);
2075
- /// let refund = channel_manager
2076
- /// .create_refund_builder(
2077
- /// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
2078
- /// )?
2079
- /// # ;
2080
- /// # // Needed for compiling for c_bindings
2081
- /// # let builder: lightning::offers::refund::RefundBuilder<_> = refund.into();
2082
- /// # let refund = builder
2083
- /// .description("coffee".to_string())
2084
- /// .payer_note("refund for order 1234".to_string())
2085
- /// .build()?;
2086
- /// let bech32_refund = refund.to_string();
2087
- ///
2088
- /// // First the payment will be waiting on an invoice
2089
- /// let expected_payment_id = payment_id;
2090
- /// assert!(
2091
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2092
- /// details,
2093
- /// RecentPaymentDetails::AwaitingInvoice { payment_id: expected_payment_id }
2094
- /// )).is_some()
2095
- /// );
2096
- ///
2097
- /// // Once the invoice is received, a payment will be sent
2098
- /// assert!(
2099
- /// channel_manager.list_recent_payments().iter().find(|details| matches!(
2100
- /// details,
2101
- /// RecentPaymentDetails::Pending { payment_id: expected_payment_id, .. }
2102
- /// )).is_some()
2103
- /// );
2104
- ///
2105
- /// // On the event processing thread
2106
- /// channel_manager.process_pending_events(&|event| {
2107
- /// match event {
2108
- /// Event::PaymentSent { payment_id: Some(payment_id), .. } => println!("Paid {}", payment_id),
2109
- /// Event::PaymentFailed { payment_id, .. } => println!("Failed paying {}", payment_id),
2110
- /// // ...
2111
- /// # _ => {},
2112
- /// }
2113
- /// Ok(())
2114
- /// });
2115
- /// # Ok(())
2116
- /// # }
2117
- /// ```
2057
+ ///
2058
+ /// For more information on creating refunds, see [`create_refund_builder`].
2118
2059
///
2119
2060
/// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2120
2061
/// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
@@ -2242,7 +2183,6 @@ where
2242
2183
/// [`offers`]: crate::offers
2243
2184
/// [`pay_for_offer`]: Self::pay_for_offer
2244
2185
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2245
- /// [`create_refund_builder`]: Self::create_refund_builder
2246
2186
/// [`request_refund_payment`]: Self::request_refund_payment
2247
2187
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2248
2188
/// [`funding_created`]: msgs::FundingCreated
@@ -2252,6 +2192,7 @@ where
2252
2192
/// [`ChannelUpdate`]: msgs::ChannelUpdate
2253
2193
/// [`read`]: ReadableArgs::read
2254
2194
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2195
+ /// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2255
2196
//
2256
2197
// Lock order:
2257
2198
// The tree structure below illustrates the lock order requirements for the different locks of the
@@ -2742,12 +2683,14 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2742
2683
/// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2743
2684
/// short-lived, while anything with a greater expiration is considered long-lived.
2744
2685
///
2745
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`ChannelManager ::create_refund_builder`],
2686
+ /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow ::create_refund_builder`],
2746
2687
/// will included a [`BlindedMessagePath`] created using:
2747
2688
/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2748
2689
/// - [`MessageRouter::create_blinded_paths`] when long-lived.
2749
2690
///
2750
2691
/// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2692
+ /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2693
+ ///
2751
2694
///
2752
2695
/// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2753
2696
/// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
@@ -9339,87 +9282,6 @@ impl Default for Bolt11InvoiceParameters {
9339
9282
}
9340
9283
}
9341
9284
9342
- macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
9343
- /// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
9344
- /// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
9345
- ///
9346
- /// # Payment
9347
- ///
9348
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the refund.
9349
- /// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent.
9350
- ///
9351
- /// The builder will have the provided expiration set. Any changes to the expiration on the
9352
- /// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen
9353
- /// block time minus two hours is used for the current time when determining if the refund has
9354
- /// expired.
9355
- ///
9356
- /// To revoke the refund, use [`ChannelManager::abandon_payment`] prior to receiving the
9357
- /// invoice. If abandoned, or an invoice isn't received before expiration, the payment will fail
9358
- /// with an [`Event::PaymentFailed`].
9359
- ///
9360
- /// If `max_total_routing_fee_msat` is not specified, The default from
9361
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
9362
- ///
9363
- /// # Privacy
9364
- ///
9365
- /// Uses [`MessageRouter`] to construct a [`BlindedMessagePath`] for the refund based on the given
9366
- /// `absolute_expiry` according to [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`]. See those docs for
9367
- /// privacy implications as well as those of the parameterized [`Router`], which implements
9368
- /// [`MessageRouter`].
9369
- ///
9370
- /// Also, uses a derived payer id in the refund for payer privacy.
9371
- ///
9372
- /// # Limitations
9373
- ///
9374
- /// Requires a direct connection to an introduction node in the responding
9375
- /// [`Bolt12Invoice::payment_paths`].
9376
- ///
9377
- /// # Errors
9378
- ///
9379
- /// Errors if:
9380
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9381
- /// - `amount_msats` is invalid, or
9382
- /// - the parameterized [`Router`] is unable to create a blinded path for the refund.
9383
- ///
9384
- /// [`Refund`]: crate::offers::refund::Refund
9385
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9386
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9387
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9388
- pub fn create_refund_builder(
9389
- &$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
9390
- retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
9391
- ) -> Result<$builder, Bolt12SemanticError> {
9392
- let node_id = $self.get_our_node_id();
9393
- let expanded_key = &$self.inbound_payment_key;
9394
- let entropy = &*$self.entropy_source;
9395
- let secp_ctx = &$self.secp_ctx;
9396
-
9397
- let nonce = Nonce::from_entropy_source(entropy);
9398
- let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
9399
- let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
9400
- .and_then(|paths| paths.into_iter().next().ok_or(()))
9401
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9402
-
9403
- let builder = RefundBuilder::deriving_signing_pubkey(
9404
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
9405
- )?
9406
- .chain_hash($self.chain_hash)
9407
- .absolute_expiry(absolute_expiry)
9408
- .path(path);
9409
-
9410
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
9411
-
9412
- let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
9413
- $self.pending_outbound_payments
9414
- .add_new_awaiting_invoice(
9415
- payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None,
9416
- )
9417
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
9418
-
9419
- Ok(builder.into())
9420
- }
9421
- } }
9422
-
9423
9285
/// Functions commonly shared in usage between [`ChannelManager`] & [`OffersMessageFlow`]
9424
9286
///
9425
9287
/// [`OffersMessageFlow`]: crate::offers::flow::OffersMessageFlow
@@ -9535,6 +9397,9 @@ pub trait OffersMessageCommons {
9535
9397
9536
9398
/// Get the [`ChainHash`] of the chain
9537
9399
fn get_chain_hash(&self) -> ChainHash;
9400
+
9401
+ /// Add new awaiting invoice
9402
+ 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<(), ()>;
9538
9403
}
9539
9404
9540
9405
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>
@@ -9716,6 +9581,13 @@ where
9716
9581
fn get_chain_hash(&self) -> ChainHash {
9717
9582
self.chain_hash
9718
9583
}
9584
+
9585
+ 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<(), ()> {
9586
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9587
+ self.pending_outbound_payments.add_new_awaiting_invoice (
9588
+ payment_id, expiration, retry_strategy, max_total_routing_fee_msat, retryable_invoice_request,
9589
+ )
9590
+ }
9719
9591
}
9720
9592
9721
9593
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9737,12 +9609,6 @@ where
9737
9609
MR::Target: MessageRouter,
9738
9610
L::Target: Logger,
9739
9611
{
9740
- #[cfg(not(c_bindings))]
9741
- create_refund_builder!(self, RefundBuilder<secp256k1::All>);
9742
-
9743
- #[cfg(c_bindings)]
9744
- create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
9745
-
9746
9612
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
9747
9613
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
9748
9614
/// [`Bolt12Invoice`] once it is received.
0 commit comments