@@ -7724,6 +7724,11 @@ where
7724
7724
/// node meeting the aforementioned criteria, but there's no guarantee that they will be
7725
7725
/// received and no retries will be made.
7726
7726
///
7727
+ /// # Errors
7728
+ ///
7729
+ /// Errors if the parameterized [`Router`] is unable to create a blinded payment path or reply
7730
+ /// path for the invoice.
7731
+ ///
7727
7732
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
7728
7733
pub fn request_refund_payment(&self, refund: &Refund) -> Result<(), Bolt12SemanticError> {
7729
7734
let expanded_key = &self.inbound_payment_key;
@@ -7735,9 +7740,9 @@ where
7735
7740
7736
7741
match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
7737
7742
Ok((payment_hash, payment_secret)) => {
7738
- let payment_paths = vec![
7739
- self.create_one_hop_blinded_payment_path(payment_secret),
7740
- ];
7743
+ let payment_paths = self.create_blinded_payment_paths(amount_msats, payment_secret)
7744
+ .map_err(|_| Bolt12SemanticError::MissingPaths)?;
7745
+
7741
7746
#[cfg(not(feature = "no-std"))]
7742
7747
let builder = refund.respond_using_derived_keys(
7743
7748
payment_paths, payment_hash, expanded_key, entropy
@@ -7898,14 +7903,15 @@ where
7898
7903
.and_then(|paths| paths.into_iter().next().ok_or(()))
7899
7904
}
7900
7905
7901
- /// Creates a one -hop blinded payment path with [`ChannelManager::get_our_node_id`] as the
7902
- /// introduction node .
7903
- fn create_one_hop_blinded_payment_path (
7904
- &self, payment_secret: PaymentSecret
7905
- ) -> (BlindedPayInfo, BlindedPath) {
7906
+ /// Creates multi -hop blinded payment paths for the given `amount_msats` by delegating to
7907
+ /// [`Router::create_blinded_payment_paths`] .
7908
+ fn create_blinded_payment_paths (
7909
+ &self, amount_msats: u64, payment_secret: PaymentSecret
7910
+ ) -> Result<Vec< (BlindedPayInfo, BlindedPath)>, ()> {
7906
7911
let entropy_source = self.entropy_source.deref();
7907
7912
let secp_ctx = &self.secp_ctx;
7908
7913
7914
+ let first_hops = self.list_usable_channels();
7909
7915
let payee_node_id = self.get_our_node_id();
7910
7916
let max_cltv_expiry = self.best_block.read().unwrap().height() + CLTV_FAR_FAR_AWAY
7911
7917
+ LATENCY_GRACE_PERIOD_BLOCKS;
@@ -7916,10 +7922,9 @@ where
7916
7922
htlc_minimum_msat: 1,
7917
7923
},
7918
7924
};
7919
- // TODO: Err for overflow?
7920
- BlindedPath::one_hop_for_payment(
7921
- payee_node_id, payee_tlvs, entropy_source, secp_ctx
7922
- ).unwrap()
7925
+ self.router.create_blinded_payment_paths(
7926
+ payee_node_id, first_hops, payee_tlvs, amount_msats, entropy_source, secp_ctx
7927
+ )
7923
7928
}
7924
7929
7925
7930
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
@@ -9159,7 +9164,7 @@ where
9159
9164
let amount_msats = match InvoiceBuilder::<DerivedSigningPubkey>::amount_msats(
9160
9165
&invoice_request
9161
9166
) {
9162
- Ok(amount_msats) => Some( amount_msats) ,
9167
+ Ok(amount_msats) => amount_msats,
9163
9168
Err(error) => return Some(OffersMessage::InvoiceError(error.into())),
9164
9169
};
9165
9170
let invoice_request = match invoice_request.verify(expanded_key, secp_ctx) {
@@ -9171,11 +9176,17 @@ where
9171
9176
};
9172
9177
let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9173
9178
9174
- match self.create_inbound_payment(amount_msats, relative_expiry, None) {
9179
+ match self.create_inbound_payment(Some( amount_msats) , relative_expiry, None) {
9175
9180
Ok((payment_hash, payment_secret)) if invoice_request.keys.is_some() => {
9176
- let payment_paths = vec![
9177
- self.create_one_hop_blinded_payment_path(payment_secret),
9178
- ];
9181
+ let payment_paths = match self.create_blinded_payment_paths(
9182
+ amount_msats, payment_secret
9183
+ ) {
9184
+ Ok(payment_paths) => payment_paths,
9185
+ Err(()) => {
9186
+ let error = Bolt12SemanticError::MissingPaths;
9187
+ return Some(OffersMessage::InvoiceError(error.into()));
9188
+ },
9189
+ };
9179
9190
#[cfg(not(feature = "no-std"))]
9180
9191
let builder = invoice_request.respond_using_derived_keys(
9181
9192
payment_paths, payment_hash
@@ -9194,9 +9205,16 @@ where
9194
9205
}
9195
9206
},
9196
9207
Ok((payment_hash, payment_secret)) => {
9197
- let payment_paths = vec![
9198
- self.create_one_hop_blinded_payment_path(payment_secret),
9199
- ];
9208
+ let payment_paths = match self.create_blinded_payment_paths(
9209
+ amount_msats, payment_secret
9210
+ ) {
9211
+ Ok(payment_paths) => payment_paths,
9212
+ Err(()) => {
9213
+ let error = Bolt12SemanticError::MissingPaths;
9214
+ return Some(OffersMessage::InvoiceError(error.into()));
9215
+ },
9216
+ };
9217
+
9200
9218
#[cfg(not(feature = "no-std"))]
9201
9219
let builder = invoice_request.respond_with(payment_paths, payment_hash);
9202
9220
#[cfg(feature = "no-std")]
0 commit comments