Skip to content

Commit

Permalink
f - use macro instead of type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Feb 20, 2024
1 parent 572bcc6 commit b11d6cf
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ use crate::util::logger::{Level, Logger, WithContext};
use crate::util::errors::APIError;
#[cfg(not(c_bindings))]
use {
crate::offers::offer::{DerivedMetadata, OfferBuilder},
crate::routing::router::DefaultRouter,
crate::routing::gossip::NetworkGraph,
crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
crate::sign::KeysManager,
};
#[cfg(c_bindings)]
use {
crate::offers::offer::OfferWithDerivedMetadataBuilder,
};

use alloc::collections::{btree_map, BTreeMap};

Expand All @@ -98,12 +103,6 @@ use core::ops::Deref;
pub use crate::ln::outbound_payment::{PaymentSendFailure, ProbeSendFailure, Retry, RetryableSendFailure, RecipientOnionFields};
use crate::ln::script::ShutdownScript;

#[cfg(not(c_bindings))]
type OfferBuilder<'a> =
crate::offers::offer::OfferBuilder<'a, crate::offers::offer::DerivedMetadata, secp256k1::All>;
#[cfg(c_bindings)]
type OfferBuilder<'a> = crate::offers::offer::OfferWithDerivedMetadataBuilder<'a>;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
//
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
Expand Down Expand Up @@ -7526,7 +7525,9 @@ where
self.finish_close_channel(failure);
}
}
}

macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer will
/// not have an expiration unless otherwise set on the builder.
Expand Down Expand Up @@ -7555,34 +7556,52 @@ where
/// [`Offer`]: crate::offers::offer::Offer
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
pub fn create_offer_builder(
&self, description: String
) -> Result<OfferBuilder, Bolt12SemanticError> {
let node_id = self.get_our_node_id();
let expanded_key = &self.inbound_payment_key;
let entropy = &*self.entropy_source;
&$self, description: String
) -> Result<$builder, Bolt12SemanticError> {
let node_id = $self.get_our_node_id();
let expanded_key = &$self.inbound_payment_key;
let entropy = &*$self.entropy_source;

let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;

#[cfg(not(c_bindings))] {
let builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, &self.secp_ctx
let builder = <$builder>::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, &$self.secp_ctx
)
.chain_hash(self.chain_hash)
.chain_hash($self.chain_hash)
.path(path);

Ok(builder)
}

#[cfg(c_bindings)] {
let mut builder = OfferBuilder::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, &self.secp_ctx
let mut builder = <$builder>::deriving_signing_pubkey(
description, node_id, expanded_key, entropy, &$self.secp_ctx
);
builder.chain_hash(self.chain_hash);
builder.chain_hash($self.chain_hash);
builder.path(path);

Ok(builder)
}
}
} }

impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, L>
where
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
T::Target: BroadcasterInterface,
ES::Target: EntropySource,
NS::Target: NodeSigner,
SP::Target: SignerProvider,
F::Target: FeeEstimator,
R::Target: Router,
L::Target: Logger,
{
#[cfg(not(c_bindings))]
create_offer_builder!(self, OfferBuilder<DerivedMetadata, secp256k1::All>);

#[cfg(c_bindings)]
create_offer_builder!(self, OfferWithDerivedMetadataBuilder);

/// Creates a [`RefundBuilder`] such that the [`Refund`] it builds is recognized by the
/// [`ChannelManager`] when handling [`Bolt12Invoice`] messages for the refund.
Expand Down

0 comments on commit b11d6cf

Please sign in to comment.