@@ -62,7 +62,7 @@ use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PaymentA
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};
@@ -8400,6 +8400,43 @@ where
8400
8400
#[cfg(c_bindings)]
8401
8401
create_refund_builder!(self, RefundMaybeWithDerivedMetadataBuilder);
8402
8402
8403
+ fn create_invoice_request_messages(&self, invoice_request: InvoiceRequest, reply_path: BlindedPath)
8404
+ -> Result<Vec<PendingOnionMessage<OffersMessage>>, Bolt12SemanticError> {
8405
+ let paths = invoice_request.paths();
8406
+ let signing_pubkey = invoice_request.signing_pubkey();
8407
+
8408
+ if paths.is_empty() && signing_pubkey.is_none() {
8409
+ debug_assert!(false);
8410
+ return Err(Bolt12SemanticError::MissingSigningPubkey);
8411
+ }
8412
+
8413
+ // Send as many invoice requests as there are paths in the offer (with an upper bound).
8414
+ // Using only one path could result in a failure if the path no longer exists. But only
8415
+ // one invoice for a given payment id will be paid, even if more than one is received.
8416
+ const REQUEST_LIMIT: usize = 10;
8417
+
8418
+ let messages = if !paths.is_empty() {
8419
+ paths.into_iter()
8420
+ .take(REQUEST_LIMIT)
8421
+ .map(|path| {
8422
+ new_pending_onion_message(
8423
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8424
+ Destination::BlindedPath(path.clone()),
8425
+ Some(reply_path.clone()),
8426
+ )
8427
+ })
8428
+ .collect()
8429
+ } else {
8430
+ vec![new_pending_onion_message(
8431
+ OffersMessage::InvoiceRequest(invoice_request.clone()),
8432
+ Destination::Node(signing_pubkey.unwrap()),
8433
+ Some(reply_path.clone()),
8434
+ )]
8435
+ };
8436
+
8437
+ Ok(messages)
8438
+ }
8439
+
8403
8440
/// Pays for an [`Offer`] using the given parameters by creating an [`InvoiceRequest`] and
8404
8441
/// enqueuing it to be sent via an onion message. [`ChannelManager`] will pay the actual
8405
8442
/// [`Bolt12Invoice`] once it is received.
@@ -8492,31 +8529,7 @@ where
8492
8529
.map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
8493
8530
8494
8531
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
8495
- if !offer.paths().is_empty() {
8496
- // Send as many invoice requests as there are paths in the offer (with an upper bound).
8497
- // Using only one path could result in a failure if the path no longer exists. But only
8498
- // one invoice for a given payment id will be paid, even if more than one is received.
8499
- const REQUEST_LIMIT: usize = 10;
8500
- for path in offer.paths().into_iter().take(REQUEST_LIMIT) {
8501
- let message = new_pending_onion_message(
8502
- OffersMessage::InvoiceRequest(invoice_request.clone()),
8503
- Destination::BlindedPath(path.clone()),
8504
- Some(reply_path.clone()),
8505
- );
8506
- pending_offers_messages.push(message);
8507
- }
8508
- } else if let Some(signing_pubkey) = offer.signing_pubkey() {
8509
- let message = new_pending_onion_message(
8510
- OffersMessage::InvoiceRequest(invoice_request),
8511
- Destination::Node(signing_pubkey),
8512
- Some(reply_path),
8513
- );
8514
- pending_offers_messages.push(message);
8515
- } else {
8516
- debug_assert!(false);
8517
- return Err(Bolt12SemanticError::MissingSigningPubkey);
8518
- }
8519
-
8532
+ pending_offers_messages.extend(self.create_invoice_request_messages(invoice_request, reply_path)?);
8520
8533
self.pending_outbound_payments.awaiting_invoice_flag.store(true, Ordering::SeqCst);
8521
8534
8522
8535
Ok(())
0 commit comments