@@ -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.
@@ -10197,21 +10219,12 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10197
10219
/// [`Offer`]: crate::offers::offer::Offer
10198
10220
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
10199
10221
pub fn create_offer_builder(&$self) -> Result<$builder, Bolt12SemanticError> {
10200
- let node_id = $self.get_our_node_id();
10201
- let expanded_key = &$self.inbound_payment_key;
10202
- let entropy = &*$self.entropy_source;
10203
- let secp_ctx = &$self.secp_ctx;
10204
-
10205
- let nonce = Nonce::from_entropy_source(entropy);
10206
- let context = MessageContext::Offers(OffersContext::InvoiceRequest { nonce });
10207
- let path = $self.create_blinded_paths(context)
10208
- .and_then(|paths| paths.into_iter().next().ok_or(()))
10209
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
10210
- let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10211
- .chain_hash($self.chain_hash)
10212
- .path(path);
10213
-
10214
- Ok(builder.into())
10222
+ $self.create_offer_builder_intern(|_, context, _| {
10223
+ $self.create_blinded_paths(context)
10224
+ .and_then(|paths| paths.into_iter().next().ok_or(()))
10225
+ .map(Some)
10226
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10227
+ })
10215
10228
}
10216
10229
10217
10230
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
@@ -10240,28 +10253,12 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
10240
10253
&$self,
10241
10254
router: ME,
10242
10255
) -> Result<$builder, Bolt12SemanticError> {
10243
- let node_id = $self.get_our_node_id();
10244
- let expanded_key = &$self.inbound_payment_key;
10245
- let entropy = &*$self.entropy_source;
10246
- let secp_ctx = &$self.secp_ctx;
10247
-
10248
- let nonce = Nonce::from_entropy_source(entropy);
10249
- let context = MessageContext::Offers(OffersContext::InvoiceRequest { nonce });
10250
-
10251
- let peers = $self.get_peers_for_blinded_path();
10252
-
10253
- let path = router.create_blinded_paths(node_id, context, peers, secp_ctx)
10254
- .map_err(|_| Bolt12SemanticError::MissingPaths)?
10255
- .into_iter().next();
10256
-
10257
- let mut builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
10258
- .chain_hash($self.chain_hash);
10259
-
10260
- if let Some(path) = path {
10261
- builder = builder.path(path)
10262
- }
10263
-
10264
- Ok(builder.into())
10256
+ $self.create_offer_builder_intern(|node_id, context, secp_ctx| {
10257
+ let peers = $self.get_peers_for_blinded_path();
10258
+ router.create_blinded_paths(node_id, context, peers, secp_ctx)
10259
+ .map(|paths| paths.into_iter().next())
10260
+ .map_err(|_| Bolt12SemanticError::MissingPaths)
10261
+ })
10265
10262
}
10266
10263
} }
10267
10264
0 commit comments