@@ -10172,6 +10172,28 @@ impl Default for Bolt11InvoiceParameters {
10172
10172
}
10173
10173
10174
10174
macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10175
+ fn create_offer_builder_intern<PF>(&$self, make_path: PF) -> Result<$builder, Bolt12SemanticError>
10176
+ where
10177
+ PF: FnOnce(PublicKey, MessageContext, &secp256k1::Secp256k1<secp256k1::All>) -> Result<Option<BlindedMessagePath>, Bolt12SemanticError>,
10178
+ {
10179
+ let node_id = $self.get_our_node_id();
10180
+ let expanded_key = &$self.inbound_payment_key;
10181
+ let entropy = &*$self.entropy_source;
10182
+ let secp_ctx = &$self.secp_ctx;
10183
+
10184
+ let nonce = Nonce::from_entropy_source(entropy);
10185
+ let context = MessageContext::Offers(OffersContext::InvoiceRequest { nonce });
10186
+
10187
+ let mut builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10188
+ .chain_hash($self.chain_hash);
10189
+
10190
+ if let Some(path) = make_path(node_id, context, secp_ctx)? {
10191
+ builder = builder.path(path)
10192
+ }
10193
+
10194
+ Ok(builder.into())
10195
+ }
10196
+
10175
10197
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
10176
10198
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer's
10177
10199
/// expiration will be `absolute_expiry` if `Some`, otherwise it will not expire.
@@ -10196,21 +10218,12 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10196
10218
/// [`Offer`]: crate::offers::offer::Offer
10197
10219
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
10198
10220
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
10199
- let node_id = $self.get_our_node_id();
10200
- let expanded_key = &$self.inbound_payment_key;
10201
- let entropy = &*$self.entropy_source;
10202
- let secp_ctx = &$self.secp_ctx;
10203
-
10204
- let nonce = Nonce::from_entropy_source(entropy);
10205
- let context = MessageContext::Offers(OffersContext::InvoiceRequest { nonce });
10206
- let path = $self.create_blinded_paths(context)
10207
- .and_then(|paths| paths.into_iter().next().ok_or(()))
10208
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
10209
- let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10210
- .chain_hash($self.chain_hash)
10211
- .path(path);
10212
-
10213
- Ok(builder.into())
10221
+ $self.create_offer_builder_intern(|_, context, _| {
10222
+ $self.create_blinded_paths(context)
10223
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
10224
+ .map(Some)
10225
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10226
+ })
10214
10227
}
10215
10228
10216
10229
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
@@ -10239,28 +10252,12 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10239
10252
&$self,
10240
10253
router: ME,
10241
10254
) -> Result<$builder, Bolt12SemanticError> {
10242
- let node_id = $self.get_our_node_id();
10243
- let expanded_key = &$self.inbound_payment_key;
10244
- let entropy = &*$self.entropy_source;
10245
- let secp_ctx = &$self.secp_ctx;
10246
-
10247
- let nonce = Nonce::from_entropy_source(entropy);
10248
- let context = MessageContext::Offers(OffersContext::InvoiceRequest { nonce });
10249
-
10250
- let peers = $self.get_peers_for_blinded_path();
10251
-
10252
- let path = router.create_blinded_paths(node_id, context, peers, secp_ctx)
10253
- .map_err(|_| Bolt12SemanticError::MissingPaths)?
10254
- .into_iter().next();
10255
-
10256
- let mut builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10257
- .chain_hash($self.chain_hash);
10258
-
10259
- if let Some(path) = path {
10260
- builder = builder.path(path)
10261
- }
10262
-
10263
- Ok(builder.into())
10255
+ $self.create_offer_builder_intern(|node_id, context, secp_ctx| {
10256
+ let peers = $self.get_peers_for_blinded_path();
10257
+ router.create_blinded_paths(node_id, context, peers, secp_ctx)
10258
+ .map(|paths| paths.into_iter().next())
10259
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10260
+ })
10264
10261
}
10265
10262
} }
10266
10263
0 commit comments