1#![doc(
4 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
5 html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
6 issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
7)]
8#![cfg_attr(not(test), warn(unused_crate_dependencies))]
9#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
10#![cfg_attr(not(feature = "std"), no_std)]
11
12use core::{fmt::Debug, marker::PhantomData};
13pub use reth_primitives_traits::{
14 Block, BlockBody, FullBlock, FullNodePrimitives, FullReceipt, FullSignedTx, NodePrimitives,
15};
16
17use reth_chainspec::EthChainSpec;
18use reth_db_api::{database_metrics::DatabaseMetrics, Database};
19use reth_engine_primitives::EngineTypes;
20use reth_payload_primitives::{BuiltPayload, PayloadTypes};
21
22pub trait NodeTypes: Clone + Debug + Send + Sync + Unpin + 'static {
28 type Primitives: NodePrimitives;
30 type ChainSpec: EthChainSpec<Header = <Self::Primitives as NodePrimitives>::BlockHeader>;
32 type Storage: Default + Send + Sync + Unpin + Debug + 'static;
34 type Payload: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = Self::Primitives>>;
36}
37
38pub trait NodeTypesWithDB: NodeTypes {
43 type DB: Database + DatabaseMetrics + Clone + Unpin + 'static;
45}
46
47#[derive(Clone, Debug, Default)]
49pub struct NodeTypesWithDBAdapter<Types, DB> {
50 types: PhantomData<Types>,
51 db: PhantomData<DB>,
52}
53
54impl<Types, DB> NodeTypesWithDBAdapter<Types, DB> {
55 pub fn new() -> Self {
57 Self { types: Default::default(), db: Default::default() }
58 }
59}
60
61impl<Types, DB> NodeTypes for NodeTypesWithDBAdapter<Types, DB>
62where
63 Types: NodeTypes,
64 DB: Clone + Debug + Send + Sync + Unpin + 'static,
65{
66 type Primitives = Types::Primitives;
67 type ChainSpec = Types::ChainSpec;
68 type Storage = Types::Storage;
69 type Payload = Types::Payload;
70}
71
72impl<Types, DB> NodeTypesWithDB for NodeTypesWithDBAdapter<Types, DB>
73where
74 Types: NodeTypes,
75 DB: Database + DatabaseMetrics + Clone + Unpin + 'static,
76{
77 type DB = DB;
78}
79
80#[derive(Clone, Debug, Default)]
82pub struct AnyNodeTypes<P = (), C = (), S = (), PL = ()>(
83 PhantomData<P>,
84 PhantomData<C>,
85 PhantomData<S>,
86 PhantomData<PL>,
87);
88
89impl<P, C, S, PL> AnyNodeTypes<P, C, S, PL> {
90 pub const fn new() -> Self {
92 Self(PhantomData, PhantomData, PhantomData, PhantomData)
93 }
94
95 pub const fn primitives<T>(self) -> AnyNodeTypes<T, C, S, PL> {
97 AnyNodeTypes::new()
98 }
99
100 pub const fn chain_spec<T>(self) -> AnyNodeTypes<P, T, S, PL> {
102 AnyNodeTypes::new()
103 }
104
105 pub const fn storage<T>(self) -> AnyNodeTypes<P, C, T, PL> {
107 AnyNodeTypes::new()
108 }
109
110 pub const fn payload<T>(self) -> AnyNodeTypes<P, C, S, T> {
112 AnyNodeTypes::new()
113 }
114}
115
116impl<P, C, S, PL> NodeTypes for AnyNodeTypes<P, C, S, PL>
117where
118 P: NodePrimitives + Send + Sync + Unpin + 'static,
119 C: EthChainSpec<Header = P::BlockHeader> + Clone + 'static,
120 S: Default + Clone + Send + Sync + Unpin + Debug + 'static,
121 PL: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = P>> + Send + Sync + Unpin + 'static,
122{
123 type Primitives = P;
124 type ChainSpec = C;
125 type Storage = S;
126 type Payload = PL;
127}
128
129#[derive(Clone, Debug, Default)]
131pub struct AnyNodeTypesWithEngine<P = (), E = (), C = (), S = (), PL = ()> {
132 _base: AnyNodeTypes<P, C, S, PL>,
134 _engine: PhantomData<E>,
136}
137
138impl<P, E, C, S, PL> AnyNodeTypesWithEngine<P, E, C, S, PL> {
139 pub const fn new() -> Self {
141 Self { _base: AnyNodeTypes::new(), _engine: PhantomData }
142 }
143
144 pub const fn primitives<T>(self) -> AnyNodeTypesWithEngine<T, E, C, S, PL> {
146 AnyNodeTypesWithEngine::new()
147 }
148
149 pub const fn engine<T>(self) -> AnyNodeTypesWithEngine<P, T, C, S, PL> {
151 AnyNodeTypesWithEngine::new()
152 }
153
154 pub const fn chain_spec<T>(self) -> AnyNodeTypesWithEngine<P, E, T, S, PL> {
156 AnyNodeTypesWithEngine::new()
157 }
158
159 pub const fn storage<T>(self) -> AnyNodeTypesWithEngine<P, E, C, T, PL> {
161 AnyNodeTypesWithEngine::new()
162 }
163
164 pub const fn payload<T>(self) -> AnyNodeTypesWithEngine<P, E, C, S, T> {
166 AnyNodeTypesWithEngine::new()
167 }
168}
169
170impl<P, E, C, S, PL> NodeTypes for AnyNodeTypesWithEngine<P, E, C, S, PL>
171where
172 P: NodePrimitives + Send + Sync + Unpin + 'static,
173 E: EngineTypes + Send + Sync + Unpin,
174 C: EthChainSpec<Header = P::BlockHeader> + Clone + 'static,
175 S: Default + Clone + Send + Sync + Unpin + Debug + 'static,
176 PL: PayloadTypes<BuiltPayload: BuiltPayload<Primitives = P>> + Send + Sync + Unpin + 'static,
177{
178 type Primitives = P;
179 type ChainSpec = C;
180 type Storage = S;
181 type Payload = PL;
182}
183
184pub type BlockTy<N> = <PrimitivesTy<N> as NodePrimitives>::Block;
186
187pub type HeaderTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockHeader;
189
190pub type BodyTy<N> = <PrimitivesTy<N> as NodePrimitives>::BlockBody;
192
193pub type TxTy<N> = <PrimitivesTy<N> as NodePrimitives>::SignedTx;
195
196pub type ReceiptTy<N> = <PrimitivesTy<N> as NodePrimitives>::Receipt;
198
199pub type PrimitivesTy<N> = <N as NodeTypes>::Primitives;
201
202pub type PayloadAttrTy<N> = <<N as NodeTypes>::Payload as PayloadTypes>::PayloadAttributes;