@@ -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};
@@ -65,11 +65,11 @@ use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
65
65
use crate::ln::outbound_payment;
66
66
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
67
67
use crate::ln::wire::Encode;
68
- use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
68
+ use crate::offers::invoice::Bolt12Invoice;
69
+ use crate::offers::invoice::UnsignedBolt12Invoice;
69
70
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
70
71
use crate::offers::nonce::Nonce;
71
72
use crate::offers::parse::Bolt12SemanticError;
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;
@@ -2008,52 +2008,8 @@ where
2008
2008
///
2009
2009
/// For more information on creating refunds, see [`create_refund_builder`].
2010
2010
///
2011
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2012
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2013
- ///
2014
- /// ```
2015
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2016
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons};
2017
- /// # use lightning::offers::refund::Refund;
2018
- /// #
2019
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2020
- /// # let channel_manager = channel_manager.get_cm();
2021
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2022
- /// Ok(invoice) => {
2023
- /// let payment_hash = invoice.payment_hash();
2024
- /// println!("Requesting refund payment {}", payment_hash);
2025
- /// payment_hash
2026
- /// },
2027
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2028
- /// };
2029
- ///
2030
- /// // On the event processing thread
2031
- /// channel_manager.process_pending_events(&|event| {
2032
- /// match event {
2033
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2034
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2035
- /// assert_eq!(payment_hash, known_payment_hash);
2036
- /// println!("Claiming payment {}", payment_hash);
2037
- /// channel_manager.claim_funds(payment_preimage);
2038
- /// },
2039
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2040
- /// println!("Unknown payment hash: {}", payment_hash);
2041
- /// },
2042
- /// // ...
2043
- /// # _ => {},
2044
- /// },
2045
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2046
- /// assert_eq!(payment_hash, known_payment_hash);
2047
- /// println!("Claimed {} msats", amount_msat);
2048
- /// },
2049
- /// // ...
2050
- /// # _ => {},
2051
- /// }
2052
- /// Ok(())
2053
- /// });
2054
- /// # }
2055
- /// ```
2056
- ///
2011
+ /// For requesting refund payments, see [`request_refund_payment`].
2012
+ ///
2057
2013
/// # Persistence
2058
2014
///
2059
2015
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2134,7 +2090,7 @@ where
2134
2090
/// [`offers`]: crate::offers
2135
2091
/// [`Offer`]: crate::offers::offer
2136
2092
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2137
- /// [`request_refund_payment`]: Self ::request_refund_payment
2093
+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
2138
2094
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2139
2095
/// [`funding_created`]: msgs::FundingCreated
2140
2096
/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2649,6 +2605,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2649
2605
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2650
2606
///
2651
2607
/// [`Offer`]: crate::offers::offer
2608
+ /// [`Refund`]: crate::offers::refund
2652
2609
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2653
2610
2654
2611
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9605,7 +9562,7 @@ where
9605
9562
/// Sending multiple requests increases the chances of successful delivery in case some
9606
9563
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9607
9564
/// even if multiple invoices are received.
9608
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9565
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9609
9566
9610
9567
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>
9611
9568
where
@@ -9619,106 +9576,6 @@ where
9619
9576
MR::Target: MessageRouter,
9620
9577
L::Target: Logger,
9621
9578
{
9622
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9623
- /// message.
9624
- ///
9625
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9626
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9627
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9628
- ///
9629
- /// # Limitations
9630
- ///
9631
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9632
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9633
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9634
- /// will be received and no retries will be made.
9635
- ///
9636
- /// # Errors
9637
- ///
9638
- /// Errors if:
9639
- /// - the refund is for an unsupported chain, or
9640
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9641
- /// the invoice.
9642
- ///
9643
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9644
- pub fn request_refund_payment(
9645
- &self, refund: &Refund
9646
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9647
- let expanded_key = &self.inbound_payment_key;
9648
- let entropy = &*self.entropy_source;
9649
- let secp_ctx = &self.secp_ctx;
9650
-
9651
- let amount_msats = refund.amount_msats();
9652
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9653
-
9654
- if refund.chain() != self.chain_hash {
9655
- return Err(Bolt12SemanticError::UnsupportedChain);
9656
- }
9657
-
9658
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9659
-
9660
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9661
- Ok((payment_hash, payment_secret)) => {
9662
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9663
- let payment_paths = self.create_blinded_payment_paths(
9664
- amount_msats, payment_secret, payment_context
9665
- )
9666
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9667
-
9668
- #[cfg(feature = "std")]
9669
- let builder = refund.respond_using_derived_keys(
9670
- payment_paths, payment_hash, expanded_key, entropy
9671
- )?;
9672
- #[cfg(not(feature = "std"))]
9673
- let created_at = Duration::from_secs(
9674
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9675
- );
9676
- #[cfg(not(feature = "std"))]
9677
- let builder = refund.respond_using_derived_keys_no_std(
9678
- payment_paths, payment_hash, created_at, expanded_key, entropy
9679
- )?;
9680
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9681
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9682
-
9683
- let nonce = Nonce::from_entropy_source(entropy);
9684
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9685
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9686
- payment_hash: invoice.payment_hash(), nonce, hmac
9687
- });
9688
- let reply_paths = self.create_blinded_paths(context)
9689
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9690
-
9691
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9692
- if refund.paths().is_empty() {
9693
- for reply_path in reply_paths {
9694
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9695
- destination: Destination::Node(refund.payer_signing_pubkey()),
9696
- reply_path,
9697
- };
9698
- let message = OffersMessage::Invoice(invoice.clone());
9699
- pending_offers_messages.push((message, instructions));
9700
- }
9701
- } else {
9702
- reply_paths
9703
- .iter()
9704
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9705
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9706
- .for_each(|(path, reply_path)| {
9707
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9708
- destination: Destination::BlindedPath(path.clone()),
9709
- reply_path: reply_path.clone(),
9710
- };
9711
- let message = OffersMessage::Invoice(invoice.clone());
9712
- pending_offers_messages.push((message, instructions));
9713
- });
9714
- }
9715
-
9716
- Ok(invoice)
9717
- },
9718
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9719
- }
9720
- }
9721
-
9722
9579
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9723
9580
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9724
9581
///
@@ -12165,6 +12022,7 @@ where
12165
12022
/// [`Refund`]s, and any reply paths.
12166
12023
///
12167
12024
/// [`Offer`]: crate::offers::offer
12025
+ /// [`Refund`]: crate::offers::refund
12168
12026
pub message_router: MR,
12169
12027
/// The Logger for use in the ChannelManager and which may be used to log information during
12170
12028
/// deserialization.
0 commit comments