@@ -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};
@@ -63,11 +63,11 @@ use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, Ligh
63
63
#[cfg(test)]
64
64
use crate::ln::outbound_payment;
65
65
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
66
- use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
66
+ use crate::offers::invoice::Bolt12Invoice;
67
+ use crate::offers::invoice::UnsignedBolt12Invoice;
67
68
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
68
69
use crate::offers::nonce::Nonce;
69
70
use crate::offers::parse::Bolt12SemanticError;
70
- use crate::offers::refund::Refund;
71
71
use crate::offers::signer;
72
72
#[cfg(async_payments)]
73
73
use crate::offers::static_invoice::StaticInvoice;
@@ -2015,52 +2015,8 @@ where
2015
2015
///
2016
2016
/// For more information on creating refunds, see [`create_refund_builder`].
2017
2017
///
2018
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2019
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2020
- ///
2021
- /// ```
2022
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2023
- /// # use lightning::ln::channelmanager::{AChannelManager, OffersMessageCommons};
2024
- /// # use lightning::offers::refund::Refund;
2025
- /// #
2026
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2027
- /// # let channel_manager = channel_manager.get_cm();
2028
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2029
- /// Ok(invoice) => {
2030
- /// let payment_hash = invoice.payment_hash();
2031
- /// println!("Requesting refund payment {}", payment_hash);
2032
- /// payment_hash
2033
- /// },
2034
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2035
- /// };
2036
- ///
2037
- /// // On the event processing thread
2038
- /// channel_manager.process_pending_events(&|event| {
2039
- /// match event {
2040
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2041
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2042
- /// assert_eq!(payment_hash, known_payment_hash);
2043
- /// println!("Claiming payment {}", payment_hash);
2044
- /// channel_manager.claim_funds(payment_preimage);
2045
- /// },
2046
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2047
- /// println!("Unknown payment hash: {}", payment_hash);
2048
- /// },
2049
- /// // ...
2050
- /// # _ => {},
2051
- /// },
2052
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2053
- /// assert_eq!(payment_hash, known_payment_hash);
2054
- /// println!("Claimed {} msats", amount_msat);
2055
- /// },
2056
- /// // ...
2057
- /// # _ => {},
2058
- /// }
2059
- /// Ok(())
2060
- /// });
2061
- /// # }
2062
- /// ```
2063
- ///
2018
+ /// For requesting refund payments, see [`request_refund_payment`].
2019
+ ///
2064
2020
/// # Persistence
2065
2021
///
2066
2022
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2141,7 +2097,7 @@ where
2141
2097
/// [`offers`]: crate::offers
2142
2098
/// [`Offer`]: crate::offers::offer
2143
2099
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2144
- /// [`request_refund_payment`]: Self ::request_refund_payment
2100
+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
2145
2101
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2146
2102
/// [`funding_created`]: msgs::FundingCreated
2147
2103
/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2662,6 +2618,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2662
2618
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2663
2619
///
2664
2620
/// [`Offer`]: crate::offers::offer
2621
+ /// [`Refund`]: crate::offers::refund
2665
2622
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2666
2623
2667
2624
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9916,7 +9873,7 @@ where
9916
9873
/// Sending multiple requests increases the chances of successful delivery in case some
9917
9874
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9918
9875
/// even if multiple invoices are received.
9919
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9876
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9920
9877
9921
9878
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>
9922
9879
where
@@ -9930,106 +9887,6 @@ where
9930
9887
MR::Target: MessageRouter,
9931
9888
L::Target: Logger,
9932
9889
{
9933
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9934
- /// message.
9935
- ///
9936
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9937
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9938
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9939
- ///
9940
- /// # Limitations
9941
- ///
9942
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9943
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9944
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9945
- /// will be received and no retries will be made.
9946
- ///
9947
- /// # Errors
9948
- ///
9949
- /// Errors if:
9950
- /// - the refund is for an unsupported chain, or
9951
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9952
- /// the invoice.
9953
- ///
9954
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9955
- pub fn request_refund_payment(
9956
- &self, refund: &Refund
9957
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9958
- let expanded_key = &self.inbound_payment_key;
9959
- let entropy = &*self.entropy_source;
9960
- let secp_ctx = &self.secp_ctx;
9961
-
9962
- let amount_msats = refund.amount_msats();
9963
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9964
-
9965
- if refund.chain() != self.chain_hash {
9966
- return Err(Bolt12SemanticError::UnsupportedChain);
9967
- }
9968
-
9969
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9970
-
9971
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9972
- Ok((payment_hash, payment_secret)) => {
9973
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9974
- let payment_paths = self.create_blinded_payment_paths(
9975
- amount_msats, payment_secret, payment_context
9976
- )
9977
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9978
-
9979
- #[cfg(feature = "std")]
9980
- let builder = refund.respond_using_derived_keys(
9981
- payment_paths, payment_hash, expanded_key, entropy
9982
- )?;
9983
- #[cfg(not(feature = "std"))]
9984
- let created_at = Duration::from_secs(
9985
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9986
- );
9987
- #[cfg(not(feature = "std"))]
9988
- let builder = refund.respond_using_derived_keys_no_std(
9989
- payment_paths, payment_hash, created_at, expanded_key, entropy
9990
- )?;
9991
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9992
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9993
-
9994
- let nonce = Nonce::from_entropy_source(entropy);
9995
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9996
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9997
- payment_hash: invoice.payment_hash(), nonce, hmac
9998
- });
9999
- let reply_paths = self.create_blinded_paths(context)
10000
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
10001
-
10002
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
10003
- if refund.paths().is_empty() {
10004
- for reply_path in reply_paths {
10005
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10006
- destination: Destination::Node(refund.payer_signing_pubkey()),
10007
- reply_path,
10008
- };
10009
- let message = OffersMessage::Invoice(invoice.clone());
10010
- pending_offers_messages.push((message, instructions));
10011
- }
10012
- } else {
10013
- reply_paths
10014
- .iter()
10015
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
10016
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
10017
- .for_each(|(path, reply_path)| {
10018
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
10019
- destination: Destination::BlindedPath(path.clone()),
10020
- reply_path: reply_path.clone(),
10021
- };
10022
- let message = OffersMessage::Invoice(invoice.clone());
10023
- pending_offers_messages.push((message, instructions));
10024
- });
10025
- }
10026
-
10027
- Ok(invoice)
10028
- },
10029
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
10030
- }
10031
- }
10032
-
10033
9890
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
10034
9891
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
10035
9892
///
@@ -12495,6 +12352,7 @@ where
12495
12352
/// [`Refund`]s, and any reply paths.
12496
12353
///
12497
12354
/// [`Offer`]: crate::offers::offer
12355
+ /// [`Refund`]: crate::offers::refund
12498
12356
pub message_router: MR,
12499
12357
/// The Logger for use in the ChannelManager and which may be used to log information during
12500
12358
/// deserialization.
0 commit comments