1use reth_chain_state::CanonStateSubscriptions;
4use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks, Hardforks};
5use reth_evm::ConfigureEvm;
6use reth_network_api::NetworkInfo;
7use reth_primitives_traits::{BlockTy, HeaderTy, NodePrimitives, ReceiptTy, TxTy};
8use reth_rpc_eth_types::EthStateCache;
9use reth_storage_api::{
10 BalProvider, BlockReader, BlockReaderIdExt, NodePrimitivesProvider, PruneCheckpointReader,
11 StageCheckpointReader, StateProviderFactory,
12};
13use reth_transaction_pool::{PoolTransaction, TransactionPool};
14
15pub trait RpcNodeCore: Clone + Send + Sync + Unpin + 'static {
22 type Primitives: NodePrimitives;
24 type Provider: BlockReaderIdExt<
26 Block = BlockTy<Self::Primitives>,
27 Receipt = ReceiptTy<Self::Primitives>,
28 Header = HeaderTy<Self::Primitives>,
29 Transaction = TxTy<Self::Primitives>,
30 > + ChainSpecProvider<
31 ChainSpec: EthChainSpec<Header = HeaderTy<Self::Primitives>>
32 + Hardforks
33 + EthereumHardforks,
34 > + StateProviderFactory<Primitives = Self::Primitives>
35 + NodePrimitivesProvider<Primitives = Self::Primitives>
36 + CanonStateSubscriptions<Primitives = Self::Primitives>
37 + StageCheckpointReader
38 + PruneCheckpointReader
39 + BalProvider
40 + Clone
41 + Unpin
42 + 'static;
43 type Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Self::Primitives>>>;
45 type Evm: ConfigureEvm<Primitives = Self::Primitives> + 'static;
47 type Network: NetworkInfo + Clone;
49
50 fn pool(&self) -> &Self::Pool;
52
53 fn evm_config(&self) -> &Self::Evm;
55
56 fn network(&self) -> &Self::Network;
58
59 fn provider(&self) -> &Self::Provider;
61}
62
63pub trait RpcNodeCoreExt: RpcNodeCore<Provider: BlockReader> {
66 fn cache(&self) -> &EthStateCache<Self::Primitives>;
68}
69
70#[derive(Debug, Clone)]
72pub struct RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
73 provider: Provider,
74 pool: Pool,
75 network: Network,
76 evm_config: Evm,
77}
78
79impl<Provider, Pool, Network, Evm> RpcNodeCoreAdapter<Provider, Pool, Network, Evm> {
80 pub const fn new(provider: Provider, pool: Pool, network: Network, evm_config: Evm) -> Self {
82 Self { provider, pool, network, evm_config }
83 }
84}
85
86impl<Provider, Pool, Network, Evm> RpcNodeCore for RpcNodeCoreAdapter<Provider, Pool, Network, Evm>
87where
88 Provider: BlockReaderIdExt<
89 Block = BlockTy<Evm::Primitives>,
90 Receipt = ReceiptTy<Evm::Primitives>,
91 Header = HeaderTy<Evm::Primitives>,
92 Transaction = TxTy<Evm::Primitives>,
93 > + ChainSpecProvider<
94 ChainSpec: EthChainSpec<Header = HeaderTy<Evm::Primitives>>
95 + Hardforks
96 + EthereumHardforks,
97 > + StateProviderFactory<Primitives = Evm::Primitives>
98 + NodePrimitivesProvider<Primitives = Evm::Primitives>
99 + CanonStateSubscriptions<Primitives = Evm::Primitives>
100 + StageCheckpointReader
101 + PruneCheckpointReader
102 + BalProvider
103 + Unpin
104 + Clone
105 + 'static,
106 Evm: ConfigureEvm + 'static,
107 Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Evm::Primitives>>>
108 + Unpin
109 + 'static,
110 Network: NetworkInfo + Clone + Unpin + 'static,
111{
112 type Primitives = Evm::Primitives;
113 type Provider = Provider;
114 type Pool = Pool;
115 type Evm = Evm;
116 type Network = Network;
117
118 fn pool(&self) -> &Self::Pool {
119 &self.pool
120 }
121
122 fn evm_config(&self) -> &Self::Evm {
123 &self.evm_config
124 }
125
126 fn network(&self) -> &Self::Network {
127 &self.network
128 }
129
130 fn provider(&self) -> &Self::Provider {
131 &self.provider
132 }
133}