Skip to content

Commit 4c31112

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

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 39 additions & 18 deletions
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,6 +7525,9 @@ where
75267525
self.finish_close_channel(failure);
75277526
}
75287527
}
7528+
}
7529+
7530+
macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
75297531

75307532
/// Creates an [`OfferBuilder`] such that the [`Offer`] it builds is recognized by the
75317533
/// [`ChannelManager`] when handling [`InvoiceRequest`] messages for the offer. The offer will
@@ -7555,34 +7557,53 @@ where
75557557
/// [`Offer`]: crate::offers::offer::Offer
75567558
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
75577559
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;
7560+
&$self, description: String
7561+
) -> Result<$builder, Bolt12SemanticError> {
7562+
let node_id = $self.get_our_node_id();
7563+
let expanded_key = &$self.inbound_payment_key;
7564+
let entropy = &*$self.entropy_source;
75637565

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

75667568
#[cfg(not(c_bindings))] {
7567-
let builder = OfferBuilder::deriving_signing_pubkey(
7568-
description, node_id, expanded_key, entropy, &self.secp_ctx
7569+
let builder = <$builder>::deriving_signing_pubkey(
7570+
description, node_id, expanded_key, entropy, &$self.secp_ctx
75697571
)
7570-
.chain_hash(self.chain_hash)
7572+
.chain_hash($self.chain_hash)
75717573
.path(path);
75727574

75737575
Ok(builder)
75747576
}
75757577

75767578
#[cfg(c_bindings)] {
7577-
let mut builder = OfferBuilder::deriving_signing_pubkey(
7578-
description, node_id, expanded_key, entropy, &self.secp_ctx
7579+
let mut builder = <$builder>::deriving_signing_pubkey(
7580+
description, node_id, expanded_key, entropy, &$self.secp_ctx
75797581
);
7580-
builder.chain_hash(self.chain_hash);
7582+
builder.chain_hash($self.chain_hash);
75817583
builder.path(path);
75827584

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

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

0 commit comments

Comments
 (0)