@@ -36,7 +36,7 @@ use crate::events::FundingInfo;
36
36
use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
37
37
use crate::blinded_path::NodeIdLookUp;
38
38
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
39
- use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
39
+ use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, ReceiveTlvs};
40
40
use crate::chain;
41
41
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
42
42
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -64,11 +64,11 @@ use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, Ligh
64
64
#[cfg(test)]
65
65
use crate::ln::outbound_payment;
66
66
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
67
- use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
67
+ use crate::offers::invoice::Bolt12Invoice;
68
+ use crate::offers::invoice::UnsignedBolt12Invoice;
68
69
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
69
70
use crate::offers::nonce::Nonce;
70
71
use crate::offers::parse::Bolt12SemanticError;
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;
@@ -2010,53 +2010,8 @@ where
2010
2010
///
2011
2011
/// For more information on creating refunds, see [`create_refund_builder`].
2012
2012
///
2013
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2014
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2015
- ///
2016
- /// ```
2017
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2018
- /// # use lightning::ln::channelmanager::AChannelManager;
2019
- /// # use lightning::offers::flow::OffersMessageCommons;
2020
- /// # use lightning::offers::refund::Refund;
2021
- /// #
2022
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2023
- /// # let channel_manager = channel_manager.get_cm();
2024
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2025
- /// Ok(invoice) => {
2026
- /// let payment_hash = invoice.payment_hash();
2027
- /// println!("Requesting refund payment {}", payment_hash);
2028
- /// payment_hash
2029
- /// },
2030
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2031
- /// };
2032
- ///
2033
- /// // On the event processing thread
2034
- /// channel_manager.process_pending_events(&|event| {
2035
- /// match event {
2036
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2037
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2038
- /// assert_eq!(payment_hash, known_payment_hash);
2039
- /// println!("Claiming payment {}", payment_hash);
2040
- /// channel_manager.claim_funds(payment_preimage);
2041
- /// },
2042
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2043
- /// println!("Unknown payment hash: {}", payment_hash);
2044
- /// },
2045
- /// // ...
2046
- /// # _ => {},
2047
- /// },
2048
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2049
- /// assert_eq!(payment_hash, known_payment_hash);
2050
- /// println!("Claimed {} msats", amount_msat);
2051
- /// },
2052
- /// // ...
2053
- /// # _ => {},
2054
- /// }
2055
- /// Ok(())
2056
- /// });
2057
- /// # }
2058
- /// ```
2059
- ///
2013
+ /// For requesting refund payments, see [`request_refund_payment`].
2014
+ ///
2060
2015
/// # Persistence
2061
2016
///
2062
2017
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2137,7 +2092,7 @@ where
2137
2092
/// [`offers`]: crate::offers
2138
2093
/// [`Offer`]: crate::offers::offer
2139
2094
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2140
- /// [`request_refund_payment`]: Self ::request_refund_payment
2095
+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
2141
2096
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2142
2097
/// [`funding_created`]: msgs::FundingCreated
2143
2098
/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2658,6 +2613,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2658
2613
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2659
2614
///
2660
2615
/// [`Offer`]: crate::offers::offer
2616
+ /// [`Refund`]: crate::offers::refund
2661
2617
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2662
2618
2663
2619
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9775,7 +9731,7 @@ where
9775
9731
/// Sending multiple requests increases the chances of successful delivery in case some
9776
9732
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9777
9733
/// even if multiple invoices are received.
9778
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9734
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9779
9735
9780
9736
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>
9781
9737
where
@@ -9789,106 +9745,6 @@ where
9789
9745
MR::Target: MessageRouter,
9790
9746
L::Target: Logger,
9791
9747
{
9792
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9793
- /// message.
9794
- ///
9795
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9796
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9797
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9798
- ///
9799
- /// # Limitations
9800
- ///
9801
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9802
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9803
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9804
- /// will be received and no retries will be made.
9805
- ///
9806
- /// # Errors
9807
- ///
9808
- /// Errors if:
9809
- /// - the refund is for an unsupported chain, or
9810
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9811
- /// the invoice.
9812
- ///
9813
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9814
- pub fn request_refund_payment(
9815
- &self, refund: &Refund
9816
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9817
- let expanded_key = &self.inbound_payment_key;
9818
- let entropy = &*self.entropy_source;
9819
- let secp_ctx = &self.secp_ctx;
9820
-
9821
- let amount_msats = refund.amount_msats();
9822
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9823
-
9824
- if refund.chain() != self.chain_hash {
9825
- return Err(Bolt12SemanticError::UnsupportedChain);
9826
- }
9827
-
9828
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9829
-
9830
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9831
- Ok((payment_hash, payment_secret)) => {
9832
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9833
- let payment_paths = self.create_blinded_payment_paths(
9834
- amount_msats, payment_secret, payment_context
9835
- )
9836
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9837
-
9838
- #[cfg(feature = "std")]
9839
- let builder = refund.respond_using_derived_keys(
9840
- payment_paths, payment_hash, expanded_key, entropy
9841
- )?;
9842
- #[cfg(not(feature = "std"))]
9843
- let created_at = Duration::from_secs(
9844
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9845
- );
9846
- #[cfg(not(feature = "std"))]
9847
- let builder = refund.respond_using_derived_keys_no_std(
9848
- payment_paths, payment_hash, created_at, expanded_key, entropy
9849
- )?;
9850
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9851
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9852
-
9853
- let nonce = Nonce::from_entropy_source(entropy);
9854
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9855
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9856
- payment_hash: invoice.payment_hash(), nonce, hmac
9857
- });
9858
- let reply_paths = self.create_blinded_paths(context)
9859
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9860
-
9861
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9862
- if refund.paths().is_empty() {
9863
- for reply_path in reply_paths {
9864
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9865
- destination: Destination::Node(refund.payer_signing_pubkey()),
9866
- reply_path,
9867
- };
9868
- let message = OffersMessage::Invoice(invoice.clone());
9869
- pending_offers_messages.push((message, instructions));
9870
- }
9871
- } else {
9872
- reply_paths
9873
- .iter()
9874
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9875
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9876
- .for_each(|(path, reply_path)| {
9877
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9878
- destination: Destination::BlindedPath(path.clone()),
9879
- reply_path: reply_path.clone(),
9880
- };
9881
- let message = OffersMessage::Invoice(invoice.clone());
9882
- pending_offers_messages.push((message, instructions));
9883
- });
9884
- }
9885
-
9886
- Ok(invoice)
9887
- },
9888
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9889
- }
9890
- }
9891
-
9892
9748
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9893
9749
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9894
9750
///
@@ -12354,6 +12210,7 @@ where
12354
12210
/// [`Refund`]s, and any reply paths.
12355
12211
///
12356
12212
/// [`Offer`]: crate::offers::offer
12213
+ /// [`Refund`]: crate::offers::refund
12357
12214
pub message_router: MR,
12358
12215
/// The Logger for use in the ChannelManager and which may be used to log information during
12359
12216
/// deserialization.
0 commit comments