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