1use std::marker::PhantomData;
4
5use arb_primitives::ArbPrimitives;
6use reth_chainspec::{EthereumHardforks, Hardforks};
7use reth_evm::ConfigureEvm;
8use reth_node_api::{FullNodeComponents, HeaderTy, TxTy};
9use reth_node_builder::{
10 rpc::{EthApiBuilder, EthApiCtx},
11 NodeTypes,
12};
13use reth_rpc_convert::{RpcConvert, RpcConverter, RpcTypes, SignableTxRequest};
14use reth_rpc_eth_api::{helpers::pending_block::BuildPendingEnv, FromEvmError, FullEthApiServer};
15use reth_rpc_eth_types::EthApiError;
16
17use crate::{
18 api::ArbEthApi, header::ArbHeaderConverter, receipt::ArbReceiptConverter,
19 response::ArbRpcTxConverter, types::ArbRpcTypes,
20};
21
22pub type ArbRpcConvert<N> = RpcConverter<
24 ArbRpcTypes,
25 <N as FullNodeComponents>::Evm,
26 ArbReceiptConverter,
27 ArbHeaderConverter,
28 (),
29 (),
30 ArbRpcTxConverter,
31>;
32
33#[derive(Debug)]
35pub struct ArbEthApiBuilder<NetworkT = ArbRpcTypes> {
36 _nt: PhantomData<NetworkT>,
37}
38
39impl<NetworkT> Default for ArbEthApiBuilder<NetworkT> {
40 fn default() -> Self {
41 Self { _nt: PhantomData }
42 }
43}
44
45impl<N, NetworkT> EthApiBuilder<N> for ArbEthApiBuilder<NetworkT>
46where
47 N: FullNodeComponents<
48 Types: NodeTypes<ChainSpec: Hardforks + EthereumHardforks, Primitives = ArbPrimitives>,
49 Evm: ConfigureEvm<NextBlockEnvCtx: BuildPendingEnv<HeaderTy<N::Types>>>,
50 >,
51 NetworkT: RpcTypes<TransactionRequest: SignableTxRequest<TxTy<N::Types>>>,
52 ArbRpcConvert<N>: RpcConvert<
53 Primitives = ArbPrimitives,
54 Error = EthApiError,
55 Network = NetworkT,
56 Evm = N::Evm,
57 >,
58 EthApiError: FromEvmError<N::Evm>,
59 ArbEthApi<N, ArbRpcConvert<N>>: FullEthApiServer<Provider = N::Provider, Pool = N::Pool>,
60{
61 type EthApi = ArbEthApi<N, ArbRpcConvert<N>>;
62
63 async fn build_eth_api(self, ctx: EthApiCtx<'_, N>) -> eyre::Result<Self::EthApi> {
64 let rpc_converter =
65 RpcConverter::<ArbRpcTypes, N::Evm, ArbReceiptConverter>::new(ArbReceiptConverter)
66 .with_header_converter(ArbHeaderConverter)
67 .with_rpc_tx_converter(ArbRpcTxConverter);
68
69 let inner = ctx
70 .eth_api_builder()
71 .with_rpc_converter(rpc_converter)
72 .build_inner();
73
74 Ok(ArbEthApi::new(inner))
75 }
76}