@@ -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};
@@ -66,11 +66,11 @@ use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, Ligh
66
66
#[cfg(test)]
67
67
use crate::ln::outbound_payment;
68
68
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
69
- use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
69
+ use crate::offers::invoice::Bolt12Invoice;
70
+ use crate::offers::invoice::UnsignedBolt12Invoice;
70
71
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
71
72
use crate::offers::nonce::Nonce;
72
73
use crate::offers::parse::Bolt12SemanticError;
73
- use crate::offers::refund::Refund;
74
74
use crate::offers::signer;
75
75
#[cfg(async_payments)]
76
76
use crate::offers::static_invoice::StaticInvoice;
@@ -2028,53 +2028,8 @@ where
2028
2028
///
2029
2029
/// For more information on creating refunds, see [`create_refund_builder`].
2030
2030
///
2031
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2032
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2033
- ///
2034
- /// ```
2035
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2036
- /// # use lightning::ln::channelmanager::AChannelManager;
2037
- /// # use lightning::offers::flow::OffersMessageCommons;
2038
- /// # use lightning::offers::refund::Refund;
2039
- /// #
2040
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2041
- /// # let channel_manager = channel_manager.get_cm();
2042
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2043
- /// Ok(invoice) => {
2044
- /// let payment_hash = invoice.payment_hash();
2045
- /// println!("Requesting refund payment {}", payment_hash);
2046
- /// payment_hash
2047
- /// },
2048
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2049
- /// };
2050
- ///
2051
- /// // On the event processing thread
2052
- /// channel_manager.process_pending_events(&|event| {
2053
- /// match event {
2054
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2055
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2056
- /// assert_eq!(payment_hash, known_payment_hash);
2057
- /// println!("Claiming payment {}", payment_hash);
2058
- /// channel_manager.claim_funds(payment_preimage);
2059
- /// },
2060
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2061
- /// println!("Unknown payment hash: {}", payment_hash);
2062
- /// },
2063
- /// // ...
2064
- /// # _ => {},
2065
- /// },
2066
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2067
- /// assert_eq!(payment_hash, known_payment_hash);
2068
- /// println!("Claimed {} msats", amount_msat);
2069
- /// },
2070
- /// // ...
2071
- /// # _ => {},
2072
- /// }
2073
- /// Ok(())
2074
- /// });
2075
- /// # }
2076
- /// ```
2077
- ///
2031
+ /// For requesting refund payments, see [`request_refund_payment`].
2032
+ ///
2078
2033
/// # Persistence
2079
2034
///
2080
2035
/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2155,7 +2110,7 @@ where
2155
2110
/// [`offers`]: crate::offers
2156
2111
/// [`Offer`]: crate::offers::offer
2157
2112
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2158
- /// [`request_refund_payment`]: Self ::request_refund_payment
2113
+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
2159
2114
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2160
2115
/// [`funding_created`]: msgs::FundingCreated
2161
2116
/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2678,6 +2633,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
2678
2633
/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2679
2634
///
2680
2635
/// [`Offer`]: crate::offers::offer
2636
+ /// [`Refund`]: crate::offers::refund
2681
2637
pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2682
2638
2683
2639
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9853,7 +9809,7 @@ where
9853
9809
/// Sending multiple requests increases the chances of successful delivery in case some
9854
9810
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9855
9811
/// even if multiple invoices are received.
9856
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9812
+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9857
9813
9858
9814
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>
9859
9815
where
@@ -9867,106 +9823,6 @@ where
9867
9823
MR::Target: MessageRouter,
9868
9824
L::Target: Logger,
9869
9825
{
9870
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9871
- /// message.
9872
- ///
9873
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9874
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9875
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9876
- ///
9877
- /// # Limitations
9878
- ///
9879
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9880
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9881
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9882
- /// will be received and no retries will be made.
9883
- ///
9884
- /// # Errors
9885
- ///
9886
- /// Errors if:
9887
- /// - the refund is for an unsupported chain, or
9888
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9889
- /// the invoice.
9890
- ///
9891
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9892
- pub fn request_refund_payment(
9893
- &self, refund: &Refund
9894
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9895
- let expanded_key = &self.inbound_payment_key;
9896
- let entropy = &*self.entropy_source;
9897
- let secp_ctx = &self.secp_ctx;
9898
-
9899
- let amount_msats = refund.amount_msats();
9900
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9901
-
9902
- if refund.chain() != self.chain_hash {
9903
- return Err(Bolt12SemanticError::UnsupportedChain);
9904
- }
9905
-
9906
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9907
-
9908
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9909
- Ok((payment_hash, payment_secret)) => {
9910
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9911
- let payment_paths = self.create_blinded_payment_paths(
9912
- amount_msats, payment_secret, payment_context
9913
- )
9914
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9915
-
9916
- #[cfg(feature = "std")]
9917
- let builder = refund.respond_using_derived_keys(
9918
- payment_paths, payment_hash, expanded_key, entropy
9919
- )?;
9920
- #[cfg(not(feature = "std"))]
9921
- let created_at = Duration::from_secs(
9922
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9923
- );
9924
- #[cfg(not(feature = "std"))]
9925
- let builder = refund.respond_using_derived_keys_no_std(
9926
- payment_paths, payment_hash, created_at, expanded_key, entropy
9927
- )?;
9928
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9929
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9930
-
9931
- let nonce = Nonce::from_entropy_source(entropy);
9932
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9933
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9934
- payment_hash: invoice.payment_hash(), nonce, hmac
9935
- });
9936
- let reply_paths = self.create_blinded_paths(context)
9937
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9938
-
9939
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9940
- if refund.paths().is_empty() {
9941
- for reply_path in reply_paths {
9942
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9943
- destination: Destination::Node(refund.payer_signing_pubkey()),
9944
- reply_path,
9945
- };
9946
- let message = OffersMessage::Invoice(invoice.clone());
9947
- pending_offers_messages.push((message, instructions));
9948
- }
9949
- } else {
9950
- reply_paths
9951
- .iter()
9952
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9953
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9954
- .for_each(|(path, reply_path)| {
9955
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9956
- destination: Destination::BlindedPath(path.clone()),
9957
- reply_path: reply_path.clone(),
9958
- };
9959
- let message = OffersMessage::Invoice(invoice.clone());
9960
- pending_offers_messages.push((message, instructions));
9961
- });
9962
- }
9963
-
9964
- Ok(invoice)
9965
- },
9966
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9967
- }
9968
- }
9969
-
9970
9826
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9971
9827
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9972
9828
///
@@ -12436,6 +12292,7 @@ where
12436
12292
/// [`Refund`]s, and any reply paths.
12437
12293
///
12438
12294
/// [`Offer`]: crate::offers::offer
12295
+ /// [`Refund`]: crate::offers::refund
12439
12296
pub message_router: MR,
12440
12297
/// The Logger for use in the ChannelManager and which may be used to log information during
12441
12298
/// deserialization.
0 commit comments