1use reth_chain_state::CanonStateSubscriptions;
4use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks, Hardforks};
5use reth_evm::ConfigureEvm;
6use reth_network_api::NetworkInfo;
7use reth_node_api::{FullNodeComponents, NodePrimitives, PrimitivesTy};
8use reth_primitives_traits::{BlockTy, HeaderTy, ReceiptTy, TxTy};
9use reth_rpc_eth_types::EthStateCache;
10use reth_storage_api::{
11 BalProvider, BlockReader, BlockReaderIdExt, PruneCheckpointReader, StageCheckpointReader,
12 StateProviderFactory,
13};
14use reth_transaction_pool::{PoolTransaction, TransactionPool};
15
16pub trait RpcNodeCore: Clone + Send + Sync + Unpin + 'static {
26 type Primitives: NodePrimitives;
28 type Provider: BlockReaderIdExt<
30 Block = BlockTy<Self::Primitives>,
31 Receipt = ReceiptTy<Self::Primitives>,
32 Header = HeaderTy<Self::Primitives>,
33 Transaction = TxTy<Self::Primitives>,
34 > + ChainSpecProvider<
35 ChainSpec: EthChainSpec<Header = HeaderTy<Self::Primitives>>
36 + Hardforks
37 + EthereumHardforks,
38 > + StateProviderFactory
39 + CanonStateSubscriptions<Primitives = Self::Primitives>
40 + StageCheckpointReader
41 + PruneCheckpointReader
42 + BalProvider
43 + Send
44 + Sync
45 + Clone
46 + Unpin
47 + 'static;
48 type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Primitives>>>;
50 type Evm: ConfigureEvm<Primitives = Self::Primitives> + Send + Sync + 'static;
52 type Network: NetworkInfo + Clone;
54
55 fn pool(&self) -> &Self::Pool;
57
58 fn evm_config(&self) -> &Self::Evm;
60
61 fn network(&self) -> &Self::Network;
63
64 fn provider(&self) -> &Self::Provider;
66}
67
68impl<T> RpcNodeCore for T
69where
70 T: FullNodeComponents<Provider: ChainSpecProvider<ChainSpec: Hardforks + EthereumHardforks>>,
71{
72 type Primitives = PrimitivesTy<T::Types>;
73 type Provider = T::Provider;
74 type Pool = T::Pool;
75 type Evm = T::Evm;
76 type Network = T::Network;
77
78 #[inline]
79 fn pool(&self) -> &Self::Pool {
80 FullNodeComponents::pool(self)
81 }
82
83 #[inline]
84 fn evm_config(&self) -> &Self::Evm {
85 FullNodeComponents::evm_config(self)
86 }
87
88 #[inline]
89 fn network(&self) -> &Self::Network {
90 FullNodeComponents::network(self)
91 }
92
93 #[inline]
94 fn provider(&self) -> &Self::Provider {
95 FullNodeComponents::provider(self)
96 }
97}
98
99pub trait RpcNodeCoreExt: RpcNodeCore<Provider: BlockReader> {
102 fn cache(&self) -> &EthStateCache<Self::Primitives>;
104}
105
106#[derive(Debug, Clone)]
108pub struct RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
109 provider: Provider,
110 pool: Pool,
111 network: Network,
112 evm_config: Evm,
113}
114
115impl<Provider, Pool, Network, Evm> RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
116 pub const fn new(provider: Provider, pool: Pool, network: Network, evm_config: Evm) -> Self {
118 Self { provider, pool, network, evm_config }
119 }
120}
121
122impl<Provider, Pool, Network, Evm> RpcNodeCore for RpcNodeCoreAdapter<Provider, Pool, Network, Evm>
123where
124 Provider: BlockReaderIdExt<
125 Block = BlockTy<Evm::Primitives>,
126 Receipt = ReceiptTy<Evm::Primitives>,
127 Header = HeaderTy<Evm::Primitives>,
128 Transaction = TxTy<Evm::Primitives>,
129 > + ChainSpecProvider<
130 ChainSpec: EthChainSpec<Header = HeaderTy<Evm::Primitives>>
131 + Hardforks
132 + EthereumHardforks,
133 > + StateProviderFactory
134 + CanonStateSubscriptions<Primitives = Evm::Primitives>
135 + StageCheckpointReader
136 + PruneCheckpointReader
137 + BalProvider
138 + Send
139 + Sync
140 + Unpin
141 + Clone
142 + 'static,
143 Evm: ConfigureEvm + Clone + 'static,
144 Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Evm::Primitives>>>
145 + Unpin
146 + 'static,
147 Network: NetworkInfo + Clone + Unpin + 'static,
148{
149 type Primitives = Evm::Primitives;
150 type Provider = Provider;
151 type Pool = Pool;
152 type Evm = Evm;
153 type Network = Network;
154
155 fn pool(&self) -> &Self::Pool {
156 &self.pool
157 }
158
159 fn evm_config(&self) -> &Self::Evm {
160 &self.evm_config
161 }
162
163 fn network(&self) -> &Self::Network {
164 &self.network
165 }
166
167 fn provider(&self) -> &Self::Provider {
168 &self.provider
169 }
170}