@@ -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,10 @@ 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, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder} ;
68
+ use crate::offers::invoice::Bolt12Invoice;
69
69
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
70
70
use crate::offers::nonce::Nonce;
71
71
use crate::offers::parse::Bolt12SemanticError;
72
- use crate::offers::refund::Refund;
73
72
use crate::offers::signer;
74
73
#[cfg(async_payments)]
75
74
use crate::offers::static_invoice::StaticInvoice;
@@ -1993,54 +1992,6 @@ where
1993
1992
/// # }
1994
1993
/// ```
1995
1994
///
1996
- /// ## BOLT 12 Refunds
1997
- ///
1998
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
1999
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2000
- ///
2001
- /// ```
2002
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2003
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons};
2004
- /// # use lightning::offers::refund::Refund;
2005
- /// #
2006
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2007
- /// # let channel_manager = channel_manager.get_cm();
2008
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2009
- /// Ok(invoice) => {
2010
- /// let payment_hash = invoice.payment_hash();
2011
- /// println!("Requesting refund payment {}", payment_hash);
2012
- /// payment_hash
2013
- /// },
2014
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2015
- /// };
2016
- ///
2017
- /// // On the event processing thread
2018
- /// channel_manager.process_pending_events(&|event| {
2019
- /// match event {
2020
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2021
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2022
- /// assert_eq!(payment_hash, known_payment_hash);
2023
- /// println!("Claiming payment {}", payment_hash);
2024
- /// channel_manager.claim_funds(payment_preimage);
2025
- /// },
2026
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2027
- /// println!("Unknown payment hash: {}", payment_hash);
2028
- /// },
2029
- /// // ...
2030
- /// # _ => {},
2031
- /// },
2032
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2033
- /// assert_eq!(payment_hash, known_payment_hash);
2034
- /// println!("Claimed {} msats", amount_msat);
2035
- /// },
2036
- /// // ...
2037
- /// # _ => {},
2038
- /// }
2039
- /// Ok(())
2040
- /// });
2041
- /// # }
2042
- /// ```
2043
- ///
2044
1995
/// # Persistence
2045
1996
///
2046
1997
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2633,6 +2584,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2633
2584
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2634
2585
///
2635
2586
/// [`Offer`]: crate::offers::offer
2587
+ /// [`Refund`]: crate::offers::refund
2636
2588
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2637
2589
2638
2590
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9573,7 +9525,7 @@ where
9573
9525
/// Sending multiple requests increases the chances of successful delivery in case some
9574
9526
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9575
9527
/// even if multiple invoices are received.
9576
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9528
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9577
9529
9578
9530
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>
9579
9531
where
@@ -9587,106 +9539,6 @@ where
9587
9539
MR::Target: MessageRouter,
9588
9540
L::Target: Logger,
9589
9541
{
9590
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9591
- /// message.
9592
- ///
9593
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9594
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9595
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9596
- ///
9597
- /// # Limitations
9598
- ///
9599
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9600
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9601
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9602
- /// will be received and no retries will be made.
9603
- ///
9604
- /// # Errors
9605
- ///
9606
- /// Errors if:
9607
- /// - the refund is for an unsupported chain, or
9608
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9609
- /// the invoice.
9610
- ///
9611
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9612
- pub fn request_refund_payment(
9613
- &self, refund: &Refund
9614
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9615
- let expanded_key = &self.inbound_payment_key;
9616
- let entropy = &*self.entropy_source;
9617
- let secp_ctx = &self.secp_ctx;
9618
-
9619
- let amount_msats = refund.amount_msats();
9620
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9621
-
9622
- if refund.chain() != self.chain_hash {
9623
- return Err(Bolt12SemanticError::UnsupportedChain);
9624
- }
9625
-
9626
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9627
-
9628
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9629
- Ok((payment_hash, payment_secret)) => {
9630
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9631
- let payment_paths = self.create_blinded_payment_paths(
9632
- amount_msats, payment_secret, payment_context
9633
- )
9634
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9635
-
9636
- #[cfg(feature = "std")]
9637
- let builder = refund.respond_using_derived_keys(
9638
- payment_paths, payment_hash, expanded_key, entropy
9639
- )?;
9640
- #[cfg(not(feature = "std"))]
9641
- let created_at = Duration::from_secs(
9642
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9643
- );
9644
- #[cfg(not(feature = "std"))]
9645
- let builder = refund.respond_using_derived_keys_no_std(
9646
- payment_paths, payment_hash, created_at, expanded_key, entropy
9647
- )?;
9648
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9649
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9650
-
9651
- let nonce = Nonce::from_entropy_source(entropy);
9652
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9653
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9654
- payment_hash: invoice.payment_hash(), nonce, hmac
9655
- });
9656
- let reply_paths = self.create_blinded_paths(context)
9657
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9658
-
9659
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9660
- if refund.paths().is_empty() {
9661
- for reply_path in reply_paths {
9662
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9663
- destination: Destination::Node(refund.payer_signing_pubkey()),
9664
- reply_path,
9665
- };
9666
- let message = OffersMessage::Invoice(invoice.clone());
9667
- pending_offers_messages.push((message, instructions));
9668
- }
9669
- } else {
9670
- reply_paths
9671
- .iter()
9672
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9673
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9674
- .for_each(|(path, reply_path)| {
9675
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9676
- destination: Destination::BlindedPath(path.clone()),
9677
- reply_path: reply_path.clone(),
9678
- };
9679
- let message = OffersMessage::Invoice(invoice.clone());
9680
- pending_offers_messages.push((message, instructions));
9681
- });
9682
- }
9683
-
9684
- Ok(invoice)
9685
- },
9686
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9687
- }
9688
- }
9689
-
9690
9542
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9691
9543
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9692
9544
///
@@ -12133,6 +11985,7 @@ where
12133
11985
/// [`Refund`]s, and any reply paths.
12134
11986
///
12135
11987
/// [`Offer`]: crate::offers::offer
11988
+ /// [`Refund`]: crate::offers::refund
12136
11989
pub message_router: MR,
12137
11990
/// The Logger for use in the ChannelManager and which may be used to log information during
12138
11991
/// deserialization.
0 commit comments