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