@@ -10262,6 +10262,53 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10262
10262
} }
10263
10263
10264
10264
macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
10265
+ fn create_refund_builder_intern<PF>(
10266
+ &$self,
10267
+ make_path: PF,
10268
+ amount_msats: u64,
10269
+ absolute_expiry: Duration,
10270
+ payment_id: PaymentId,
10271
+ retry_strategy: Retry,
10272
+ route_params_config: RouteParametersConfig
10273
+ ) -> Result<$builder, Bolt12SemanticError>
10274
+ where
10275
+ PF: FnOnce(PublicKey, MessageContext, &secp256k1::Secp256k1<secp256k1::All>) -> Result<Option<BlindedMessagePath>, Bolt12SemanticError>,
10276
+ {
10277
+ let node_id = $self.get_our_node_id();
10278
+ let expanded_key = &$self.inbound_payment_key;
10279
+ let entropy = &*$self.entropy_source;
10280
+ let secp_ctx = &$self.secp_ctx;
10281
+
10282
+ let nonce = Nonce::from_entropy_source(entropy);
10283
+ let context = MessageContext::Offers(
10284
+ OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
10285
+ );
10286
+
10287
+ // Create the base builder with common properties
10288
+ let mut builder = RefundBuilder::deriving_signing_pubkey(
10289
+ node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
10290
+ )?
10291
+ .chain_hash($self.chain_hash)
10292
+ .absolute_expiry(absolute_expiry);
10293
+
10294
+ // Add path if one is provided by the path creator
10295
+ if let Some(path) = make_path(node_id, context, secp_ctx)? {
10296
+ builder = builder.path(path);
10297
+ }
10298
+
10299
+ // Handle persistence and payment tracking
10300
+ let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
10301
+
10302
+ let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
10303
+ $self.pending_outbound_payments
10304
+ .add_new_awaiting_invoice(
10305
+ payment_id, expiration, retry_strategy, route_params_config, None,
10306
+ )
10307
+ .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
10308
+
10309
+ Ok(builder.into())
10310
+ }
10311
+
10265
10312
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
10266
10313
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
10267
10314
///
@@ -10311,34 +10358,19 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
10311
10358
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
10312
10359
retry_strategy: Retry, route_params_config: RouteParametersConfig
10313
10360
) -> Result<$builder, Bolt12SemanticError> {
10314
- let node_id = $self.get_our_node_id();
10315
- let expanded_key = &$self.inbound_payment_key;
10316
- let entropy = &*$self.entropy_source;
10317
- let secp_ctx = &$self.secp_ctx;
10318
-
10319
- let nonce = Nonce::from_entropy_source(entropy);
10320
- let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
10321
- let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
10322
- .and_then(|paths| paths.into_iter().next().ok_or(()))
10323
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
10324
-
10325
- let builder = RefundBuilder::deriving_signing_pubkey(
10326
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
10327
- )?
10328
- .chain_hash($self.chain_hash)
10329
- .absolute_expiry(absolute_expiry)
10330
- .path(path);
10331
-
10332
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
10333
-
10334
- let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
10335
- $self.pending_outbound_payments
10336
- .add_new_awaiting_invoice(
10337
- payment_id, expiration, retry_strategy, route_params_config, None,
10338
- )
10339
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
10340
-
10341
- Ok(builder.into())
10361
+ $self.create_refund_builder_intern(
10362
+ |_, context, _| {
10363
+ $self.create_blinded_paths(context)
10364
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
10365
+ .map(Some)
10366
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10367
+ },
10368
+ amount_msats,
10369
+ absolute_expiry,
10370
+ payment_id,
10371
+ retry_strategy,
10372
+ route_params_config
10373
+ )
10342
10374
}
10343
10375
10344
10376
/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
@@ -10389,41 +10421,19 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
10389
10421
&$self, router: ME, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
10390
10422
retry_strategy: Retry, route_params_config: RouteParametersConfig
10391
10423
) -> Result<$builder, Bolt12SemanticError> {
10392
- let node_id = $self.get_our_node_id();
10393
- let expanded_key = &$self.inbound_payment_key;
10394
- let entropy = &*$self.entropy_source;
10395
- let secp_ctx = &$self.secp_ctx;
10396
-
10397
- let nonce = Nonce::from_entropy_source(entropy);
10398
- let context = MessageContext::Offers(
10399
- OffersContext::OutboundPayment { payment_id, nonce, hmac: None }
10400
- );
10401
-
10402
- let peers = $self.get_peers_for_blinded_path();
10403
- let path = router.create_blinded_paths(node_id, context, peers, secp_ctx)
10404
- .map_err(|_| Bolt12SemanticError::MissingPaths)?
10405
- .into_iter().next();
10406
-
10407
- let mut builder = RefundBuilder::deriving_signing_pubkey(
10408
- node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
10409
- )?
10410
- .chain_hash($self.chain_hash)
10411
- .absolute_expiry(absolute_expiry);
10412
-
10413
- if let Some(path) = path {
10414
- builder = builder.path(path)
10415
- }
10416
-
10417
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
10418
-
10419
- let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry);
10420
- $self.pending_outbound_payments
10421
- .add_new_awaiting_invoice(
10422
- payment_id, expiration, retry_strategy, route_params_config, None,
10423
- )
10424
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?;
10425
-
10426
- Ok(builder.into())
10424
+ $self.create_refund_builder_intern(
10425
+ |node_id, context, secp_ctx| {
10426
+ let peers = $self.get_peers_for_blinded_path();
10427
+ router.create_blinded_paths(node_id, context, peers, secp_ctx)
10428
+ .map(|paths| paths.into_iter().next())
10429
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10430
+ },
10431
+ amount_msats,
10432
+ absolute_expiry,
10433
+ payment_id,
10434
+ retry_strategy,
10435
+ route_params_config
10436
+ )
10427
10437
}
10428
10438
} }
10429
10439
0 commit comments