@@ -62,7 +62,7 @@ use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutb
62
62
use crate::ln::wire::Encode;
63
63
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
64
64
use crate::offers::invoice_error::InvoiceError;
65
- use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
65
+ use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequest, InvoiceRequestBuilder};
66
66
use crate::offers::offer::{Offer, OfferBuilder};
67
67
use crate::offers::parse::Bolt12SemanticError;
68
68
use crate::offers::refund::{Refund, RefundBuilder};
@@ -8437,6 +8437,43 @@ where
8437
8437
#[cfg(c_bindings)]
8438
8438
create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
8439
8439
8440
+ fn create_invoice_request_messages(&self, invoice_request: InvoiceRequest, reply_path: BlindedPath)
8441
+ -> Result<Vec<PendingOnionMessage<OffersMessage>>, Bolt12SemanticError> {
8442
+ let paths = invoice_request.paths();
8443
+ let signing_pubkey = invoice_request.signing_pubkey();
8444
+
8445
+ if paths.is_empty() && signing_pubkey.is_none() {
8446
+ debug_assert!(false);
8447
+ return Err(Bolt12SemanticError::MissingSigningPubkey);
8448
+ }
8449
+
8450
+ // Send as many invoice requests as there are paths in the offer (with an upper bound).
8451
+ // Using only one path could result in a failure if the path no longer exists. But only
8452
+ // one invoice for a given payment id will be paid, even if more than one is received.
8453
+ const REQUEST_LIMIT: usize = 10;
8454
+
8455
+ let messages = if !paths.is_empty() {
8456
+ paths.into_iter()
8457
+ .take(REQUEST_LIMIT)
8458
+ .map(|path| {
8459
+ new_pending_onion_message(
8460
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8461
+ Destination::BlindedPath(path.clone()),
8462
+ Some(reply_path.clone()),
8463
+ )
8464
+ })
8465
+ .collect()
8466
+ } else {
8467
+ vec![new_pending_onion_message(
8468
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8469
+ Destination::Node(signing_pubkey.unwrap()),
8470
+ Some(reply_path.clone()),
8471
+ )]
8472
+ };
8473
+
8474
+ Ok(messages)
8475
+ }
8476
+
8440
8477
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
8441
8478
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
8442
8479
/// [`Bolt12Invoice`] once it is received.
@@ -8529,31 +8566,7 @@ where
8529
8566
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
8530
8567
8531
8568
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8532
- if !offer.paths().is_empty() {
8533
- // Send as many invoice requests as there are paths in the offer (with an upper bound).
8534
- // Using only one path could result in a failure if the path no longer exists. But only
8535
- // one invoice for a given payment id will be paid, even if more than one is received.
8536
- const REQUEST_LIMIT: usize = 10;
8537
- for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8538
- let message = new_pending_onion_message(
8539
- OffersMessage::InvoiceRequest(invoice_request.clone()),
8540
- Destination::BlindedPath(path.clone()),
8541
- Some(reply_path.clone()),
8542
- );
8543
- pending_offers_messages.push(message);
8544
- }
8545
- } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8546
- let message = new_pending_onion_message(
8547
- OffersMessage::InvoiceRequest(invoice_request),
8548
- Destination::Node(signing_pubkey),
8549
- Some(reply_path),
8550
- );
8551
- pending_offers_messages.push(message);
8552
- } else {
8553
- debug_assert!(false);
8554
- return Err(Bolt12SemanticError::MissingSigningPubkey);
8555
- }
8556
-
8569
+ pending_offers_messages.extend(self.create_invoice_request_messages(invoice_request, reply_path)?);
8557
8570
self.pending_outbound_payments.awaiting_invoice_flag.store(true, Ordering::SeqCst);
8558
8571
8559
8572
Ok(())
0 commit comments