@@ -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;
@@ -1994,56 +1993,6 @@ where
1994
1993
/// # }
1995
1994
/// ```
1996
1995
///
1997
- /// ## BOLT 12 Offers
1998
- ///
1999
- /// ## BOLT 12 Refunds
2000
- ///
2001
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2002
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2003
- ///
2004
- /// ```
2005
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2006
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons};
2007
- /// # use lightning::offers::refund::Refund;
2008
- /// #
2009
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2010
- /// # let channel_manager = channel_manager.get_cm();
2011
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2012
- /// Ok(invoice) => {
2013
- /// let payment_hash = invoice.payment_hash();
2014
- /// println!("Requesting refund payment {}", payment_hash);
2015
- /// payment_hash
2016
- /// },
2017
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2018
- /// };
2019
- ///
2020
- /// // On the event processing thread
2021
- /// channel_manager.process_pending_events(&|event| {
2022
- /// match event {
2023
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2024
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2025
- /// assert_eq!(payment_hash, known_payment_hash);
2026
- /// println!("Claiming payment {}", payment_hash);
2027
- /// channel_manager.claim_funds(payment_preimage);
2028
- /// },
2029
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2030
- /// println!("Unknown payment hash: {}", payment_hash);
2031
- /// },
2032
- /// // ...
2033
- /// # _ => {},
2034
- /// },
2035
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2036
- /// assert_eq!(payment_hash, known_payment_hash);
2037
- /// println!("Claimed {} msats", amount_msat);
2038
- /// },
2039
- /// // ...
2040
- /// # _ => {},
2041
- /// }
2042
- /// Ok(())
2043
- /// });
2044
- /// # }
2045
- /// ```
2046
- ///
2047
1996
/// # Persistence
2048
1997
///
2049
1998
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2636,6 +2585,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2636
2585
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2637
2586
///
2638
2587
/// [`Offer`]: crate::offers::offer
2588
+ /// [`Refund`]: crate::offers::refund
2639
2589
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2640
2590
2641
2591
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9569,7 +9519,7 @@ where
9569
9519
/// Sending multiple requests increases the chances of successful delivery in case some
9570
9520
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9571
9521
/// even if multiple invoices are received.
9572
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9522
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9573
9523
9574
9524
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>
9575
9525
where
@@ -9656,106 +9606,6 @@ where
9656
9606
})
9657
9607
}
9658
9608
9659
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9660
- /// message.
9661
- ///
9662
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9663
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9664
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9665
- ///
9666
- /// # Limitations
9667
- ///
9668
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9669
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9670
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9671
- /// will be received and no retries will be made.
9672
- ///
9673
- /// # Errors
9674
- ///
9675
- /// Errors if:
9676
- /// - the refund is for an unsupported chain, or
9677
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9678
- /// the invoice.
9679
- ///
9680
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9681
- pub fn request_refund_payment(
9682
- &self, refund: &Refund
9683
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9684
- let expanded_key = &self.inbound_payment_key;
9685
- let entropy = &*self.entropy_source;
9686
- let secp_ctx = &self.secp_ctx;
9687
-
9688
- let amount_msats = refund.amount_msats();
9689
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9690
-
9691
- if refund.chain() != self.chain_hash {
9692
- return Err(Bolt12SemanticError::UnsupportedChain);
9693
- }
9694
-
9695
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9696
-
9697
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9698
- Ok((payment_hash, payment_secret)) => {
9699
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9700
- let payment_paths = self.create_blinded_payment_paths(
9701
- amount_msats, payment_secret, payment_context
9702
- )
9703
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9704
-
9705
- #[cfg(feature = "std")]
9706
- let builder = refund.respond_using_derived_keys(
9707
- payment_paths, payment_hash, expanded_key, entropy
9708
- )?;
9709
- #[cfg(not(feature = "std"))]
9710
- let created_at = Duration::from_secs(
9711
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9712
- );
9713
- #[cfg(not(feature = "std"))]
9714
- let builder = refund.respond_using_derived_keys_no_std(
9715
- payment_paths, payment_hash, created_at, expanded_key, entropy
9716
- )?;
9717
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9718
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9719
-
9720
- let nonce = Nonce::from_entropy_source(entropy);
9721
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9722
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9723
- payment_hash: invoice.payment_hash(), nonce, hmac
9724
- });
9725
- let reply_paths = self.create_blinded_paths(context)
9726
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9727
-
9728
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9729
- if refund.paths().is_empty() {
9730
- for reply_path in reply_paths {
9731
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9732
- destination: Destination::Node(refund.payer_signing_pubkey()),
9733
- reply_path,
9734
- };
9735
- let message = OffersMessage::Invoice(invoice.clone());
9736
- pending_offers_messages.push((message, instructions));
9737
- }
9738
- } else {
9739
- reply_paths
9740
- .iter()
9741
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9742
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9743
- .for_each(|(path, reply_path)| {
9744
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9745
- destination: Destination::BlindedPath(path.clone()),
9746
- reply_path: reply_path.clone(),
9747
- };
9748
- let message = OffersMessage::Invoice(invoice.clone());
9749
- pending_offers_messages.push((message, instructions));
9750
- });
9751
- }
9752
-
9753
- Ok(invoice)
9754
- },
9755
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9756
- }
9757
- }
9758
-
9759
9609
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9760
9610
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9761
9611
///
@@ -12202,6 +12052,7 @@ where
12202
12052
/// [`Refund`]s, and any reply paths.
12203
12053
///
12204
12054
/// [`Offer`]: crate::offers::offer
12055
+ /// [`Refund`]: crate::offers::refund
12205
12056
pub message_router: MR,
12206
12057
/// The Logger for use in the ChannelManager and which may be used to log information during
12207
12058
/// deserialization.
0 commit comments