Skip to content

Commit b11d6cf

Browse files
committed
f - use macro instead of type alias
1 parent 572bcc6 commit b11d6cf

File tree

1 file changed

+37
-18
lines changed

1 file changed

+37
-18
lines changed

lightning/src/ln/channelmanager.rs

+37-18
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ use crate::util::logger::{Level, Logger, WithContext};
7676
use crate::util::errors::APIError;
7777
#[cfg(not(c_bindings))]
7878
use {
79+
crate::offers::offer::{DerivedMetadata, OfferBuilder},
7980
crate::routing::router::DefaultRouter,
8081
crate::routing::gossip::NetworkGraph,
8182
crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters},
8283
crate::sign::KeysManager,
8384
};
85+
#[cfg(c_bindings)]
86+
use {
87+
crate::offers::offer::OfferWithDerivedMetadataBuilder,
88+
};
8489

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

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

101-
#[cfg(not(c_bindings))]
102-
type OfferBuilder<'a> =
103-
crate::offers::offer::OfferBuilder<'a, crate::offers::offer::DerivedMetadata, secp256k1::All>;
104-
#[cfg(c_bindings)]
105-
type OfferBuilder<'a> = crate::offers::offer::OfferWithDerivedMetadataBuilder<'a>;
106-
107106
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
108107
//
109108
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should
@@ -7526,7 +7525,9 @@ where
75267525
self.finish_close_channel(failure);
75277526
}
75287527
}
7528+
}
75297529

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

7564-
let path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
7565+
let path = $self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
75657566

75667567
#[cfg(not(c_bindings))] {
7567-
let builder = OfferBuilder::deriving_signing_pubkey(
7568-
description, node_id, expanded_key, entropy, &self.secp_ctx
7568+
let builder = <$builder>::deriving_signing_pubkey(
7569+
description, node_id, expanded_key, entropy, &$self.secp_ctx
75697570
)
7570-
.chain_hash(self.chain_hash)
7571+
.chain_hash($self.chain_hash)
75717572
.path(path);
75727573

75737574
Ok(builder)
75747575
}
75757576

75767577
#[cfg(c_bindings)] {
7577-
let mut builder = OfferBuilder::deriving_signing_pubkey(
7578-
description, node_id, expanded_key, entropy, &self.secp_ctx
7578+
let mut builder = <$builder>::deriving_signing_pubkey(
7579+
description, node_id, expanded_key, entropy, &$self.secp_ctx
75797580
);
7580-
builder.chain_hash(self.chain_hash);
7581+
builder.chain_hash($self.chain_hash);
75817582
builder.path(path);
75827583

75837584
Ok(builder)
75847585
}
75857586
}
7587+
} }
7588+
7589+
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>
7590+
where
7591+
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
7592+
T::Target: BroadcasterInterface,
7593+
ES::Target: EntropySource,
7594+
NS::Target: NodeSigner,
7595+
SP::Target: SignerProvider,
7596+
F::Target: FeeEstimator,
7597+
R::Target: Router,
7598+
L::Target: Logger,
7599+
{
7600+
#[cfg(not(c_bindings))]
7601+
create_offer_builder!(self, OfferBuilder<DerivedMetadata, secp256k1::All>);
7602+
7603+
#[cfg(c_bindings)]
7604+
create_offer_builder!(self, OfferWithDerivedMetadataBuilder);
75867605

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

0 commit comments

Comments
 (0)