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, NodePrimitivesProvider, PruneCheckpointReader,
12 StageCheckpointReader, 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<Primitives = Self::Primitives>
39 + NodePrimitivesProvider<Primitives = Self::Primitives>
40 + CanonStateSubscriptions<Primitives = Self::Primitives>
41 + StageCheckpointReader
42 + PruneCheckpointReader
43 + BalProvider
44 + Clone
45 + Unpin
46 + 'static;
47 type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Primitives>>>;
49 type Evm: ConfigureEvm<Primitives = Self::Primitives> + 'static;
51 type Network: NetworkInfo + Clone;
53
54 fn pool(&self) -> &Self::Pool;
56
57 fn evm_config(&self) -> &Self::Evm;
59
60 fn network(&self) -> &Self::Network;
62
63 fn provider(&self) -> &Self::Provider;
65}
66
67impl<T> RpcNodeCore for T
68where
69 T: FullNodeComponents<Provider: ChainSpecProvider<ChainSpec: Hardforks + EthereumHardforks>>,
70{
71 type Primitives = PrimitivesTy<T::Types>;
72 type Provider = T::Provider;
73 type Pool = T::Pool;
74 type Evm = T::Evm;
75 type Network = T::Network;
76
77 #[inline]
78 fn pool(&self) -> &Self::Pool {
79 FullNodeComponents::pool(self)
80 }
81
82 #[inline]
83 fn evm_config(&self) -> &Self::Evm {
84 FullNodeComponents::evm_config(self)
85 }
86
87 #[inline]
88 fn network(&self) -> &Self::Network {
89 FullNodeComponents::network(self)
90 }
91
92 #[inline]
93 fn provider(&self) -> &Self::Provider {
94 FullNodeComponents::provider(self)
95 }
96}
97
98pub trait RpcNodeCoreExt: RpcNodeCore<Provider: BlockReader> {
101 fn cache(&self) -> &EthStateCache<Self::Primitives>;
103}
104
105#[derive(Debug, Clone)]
107pub struct RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
108 provider: Provider,
109 pool: Pool,
110 network: Network,
111 evm_config: Evm,
112}
113
114impl<Provider, Pool, Network, Evm> RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
115 pub const fn new(provider: Provider, pool: Pool, network: Network, evm_config: Evm) -> Self {
117 Self { provider, pool, network, evm_config }
118 }
119}
120
121impl<Provider, Pool, Network, Evm> RpcNodeCore for RpcNodeCoreAdapter<Provider, Pool, Network, Evm>
122where
123 Provider: BlockReaderIdExt<
124 Block = BlockTy<Evm::Primitives>,
125 Receipt = ReceiptTy<Evm::Primitives>,
126 Header = HeaderTy<Evm::Primitives>,
127 Transaction = TxTy<Evm::Primitives>,
128 > + ChainSpecProvider<
129 ChainSpec: EthChainSpec<Header = HeaderTy<Evm::Primitives>>
130 + Hardforks
131 + EthereumHardforks,
132 > + StateProviderFactory<Primitives = Evm::Primitives>
133 + NodePrimitivesProvider<Primitives = Evm::Primitives>
134 + CanonStateSubscriptions<Primitives = Evm::Primitives>
135 + StageCheckpointReader
136 + PruneCheckpointReader
137 + BalProvider
138 + Unpin
139 + Clone
140 + 'static,
141 Evm: ConfigureEvm + 'static,
142 Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Evm::Primitives>>>
143 + Unpin
144 + 'static,
145 Network: NetworkInfo + Clone + Unpin + 'static,
146{
147 type Primitives = Evm::Primitives;
148 type Provider = Provider;
149 type Pool = Pool;
150 type Evm = Evm;
151 type Network = Network;
152
153 fn pool(&self) -> &Self::Pool {
154 &self.pool
155 }
156
157 fn evm_config(&self) -> &Self::Evm {
158 &self.evm_config
159 }
160
161 fn network(&self) -> &Self::Network {
162 &self.network
163 }
164
165 fn provider(&self) -> &Self::Provider {
166 &self.provider
167 }
168}