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