@@ -10172,6 +10172,28 @@ impl Default for Bolt11InvoiceParameters {
1017210172}
1017310173
1017410174macro_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+
1017510197 /// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
1017610198 /// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer's
1017710199 /// 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) => {
1019610218 /// [`Offer`]: crate::offers::offer::Offer
1019710219 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
1019810220 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+ })
1021410227 }
1021510228
1021610229 /// 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) => {
1023910252 &$self,
1024010253 router: ME,
1024110254 ) -> 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+ })
1026410261 }
1026510262} }
1026610263
0 commit comments