@@ -7435,15 +7435,20 @@ where
7435
7435
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
7436
7436
pub fn create_offer_builder(
7437
7437
&self, description: String
7438
- ) -> OfferBuilder<DerivedMetadata, secp256k1::All> {
7438
+ ) -> Result< OfferBuilder<DerivedMetadata, secp256k1::All>, Bolt12SemanticError > {
7439
7439
let node_id = self.get_our_node_id();
7440
7440
let expanded_key = &self.inbound_payment_key;
7441
7441
let entropy = &*self.entropy_source;
7442
7442
let secp_ctx = &self.secp_ctx;
7443
7443
7444
- OfferBuilder::deriving_signing_pubkey(description, node_id, expanded_key, entropy, secp_ctx)
7444
+ let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7445
+ let builder = OfferBuilder::deriving_signing_pubkey(
7446
+ description, node_id, expanded_key, entropy, secp_ctx
7447
+ )
7445
7448
.chain_hash(self.chain_hash)
7446
- .path(self.create_blinded_path())
7449
+ .path(path);
7450
+
7451
+ Ok(builder)
7447
7452
}
7448
7453
7449
7454
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
@@ -7500,12 +7505,13 @@ where
7500
7505
let entropy = &*self.entropy_source;
7501
7506
let secp_ctx = &self.secp_ctx;
7502
7507
7508
+ let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7503
7509
let builder = RefundBuilder::deriving_payer_id(
7504
7510
description, node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
7505
7511
)?
7506
7512
.chain_hash(self.chain_hash)
7507
7513
.absolute_expiry(absolute_expiry)
7508
- .path(self.create_blinded_path() );
7514
+ .path(path );
7509
7515
7510
7516
let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
7511
7517
self.pending_outbound_payments
@@ -7592,7 +7598,7 @@ where
7592
7598
Some(payer_note) => builder.payer_note(payer_note),
7593
7599
};
7594
7600
let invoice_request = builder.build_and_sign()?;
7595
- let reply_path = self.create_blinded_path();
7601
+ let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)? ;
7596
7602
7597
7603
let expiration = StaleExpiration::TimerTicks(1);
7598
7604
self.pending_outbound_payments
@@ -7668,7 +7674,8 @@ where
7668
7674
payment_paths, payment_hash, created_at, expanded_key, entropy
7669
7675
)?;
7670
7676
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
7671
- let reply_path = self.create_blinded_path();
7677
+ let reply_path = self.create_blinded_path()
7678
+ .map_err(|_| Bolt12SemanticError::MissingPaths)?;
7672
7679
7673
7680
let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
7674
7681
if refund.paths().is_empty() {
@@ -7795,29 +7802,10 @@ where
7795
7802
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
7796
7803
}
7797
7804
7798
- /// Creates a multi-hop blinded path by delegating to [`MessageRouter::create_blinded_paths`].
7799
- /// If the router returns an error or no paths, creates a one-hop blinded path instead.
7800
- fn create_blinded_path(&self) -> BlindedPath {
7801
- self.create_multi_hop_blinded_paths()
7802
- .ok()
7803
- .and_then(|paths| paths.into_iter().next())
7804
- .unwrap_or_else(|| self.create_one_hop_blinded_path())
7805
- }
7806
-
7807
- /// Creates a one-hop blinded path with [`ChannelManager::get_our_node_id`] as the introduction
7808
- /// node.
7809
- fn create_one_hop_blinded_path(&self) -> BlindedPath {
7810
- let entropy_source = self.entropy_source.deref();
7811
- let secp_ctx = &self.secp_ctx;
7812
- BlindedPath::one_hop_for_message(self.get_our_node_id(), entropy_source, secp_ctx).unwrap()
7813
- }
7814
-
7815
- /// Creates blinded paths by delegating to [`MessageRouter::create_blinded_paths`].
7816
- ///
7817
- /// May return no paths if no peers [support onion messages].
7805
+ /// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
7818
7806
///
7819
- /// [support onion messages]: crate::ln::features::InitFeatures::supports_onion_messages
7820
- fn create_multi_hop_blinded_paths (&self) -> Result<Vec< BlindedPath> , ()> {
7807
+ /// Errors if the `MessageRouter` errors or returns an empty `Vec`.
7808
+ fn create_blinded_path (&self) -> Result<BlindedPath, ()> {
7821
7809
let recipient = self.get_our_node_id();
7822
7810
let entropy_source = self.entropy_source.deref();
7823
7811
let secp_ctx = &self.secp_ctx;
@@ -7828,7 +7816,9 @@ where
7828
7816
.map(|(node_id, _)| *node_id)
7829
7817
.collect::<Vec<_>>();
7830
7818
7831
- self.router.create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7819
+ self.router
7820
+ .create_blinded_paths(recipient, peers, entropy_source, secp_ctx)
7821
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
7832
7822
}
7833
7823
7834
7824
/// Creates a one-hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
0 commit comments