use jsonrpsee::core::RpcResult as Result; use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, B256, U256, U64}; use reth_rpc_api::{EngineEthApiServer, EthApiServer, EthFilterApiServer}; /// Re-export for convenience pub use reth_rpc_engine_api::EngineApi; use reth_rpc_types::{ state::StateOverride, BlockOverrides, EIP1186AccountProofResponse, Filter, JsonStorageKey, Log, RichBlock, SyncStatus, TransactionRequest, }; use tracing_futures::Instrument; macro_rules! engine_span { () => { tracing::trace_span!(target: "rpc", "engine") }; } /// A wrapper type for the `EthApi` and `EthFilter` implementations that only expose the required /// subset for the `eth_` namespace used in auth server alongside the `engine_` namespace. #[derive(Debug, Clone)] pub struct EngineEthApi { eth: Eth, eth_filter: EthFilter, } impl EngineEthApi { /// Create a new `EngineEthApi` instance. pub const fn new(eth: Eth, eth_filter: EthFilter) -> Self { Self { eth, eth_filter } } } #[async_trait::async_trait] impl EngineEthApiServer for EngineEthApi where Eth: EthApiServer, EthFilter: EthFilterApiServer, { /// Handler for: `eth_syncing` fn syncing(&self) -> Result { let span = engine_span!(); let _enter = span.enter(); self.eth.syncing() } /// Handler for: `eth_chainId` async fn chain_id(&self) -> Result> { let span = engine_span!(); let _enter = span.enter(); self.eth.chain_id().await } /// Handler for: `eth_blockNumber` fn block_number(&self) -> Result { let span = engine_span!(); let _enter = span.enter(); self.eth.block_number() } /// Handler for: `eth_call` async fn call( &self, request: TransactionRequest, block_number: Option, state_overrides: Option, block_overrides: Option>, ) -> Result { self.eth .call(request, block_number, state_overrides, block_overrides) .instrument(engine_span!()) .await } /// Handler for: `eth_getCode` async fn get_code(&self, address: Address, block_number: Option) -> Result { self.eth.get_code(address, block_number).instrument(engine_span!()).await } /// Handler for: `eth_getBlockByHash` async fn block_by_hash(&self, hash: B256, full: bool) -> Result> { self.eth.block_by_hash(hash, full).instrument(engine_span!()).await } /// Handler for: `eth_getBlockByNumber` async fn block_by_number( &self, number: BlockNumberOrTag, full: bool, ) -> Result> { self.eth.block_by_number(number, full).instrument(engine_span!()).await } /// Handler for: `eth_sendRawTransaction` async fn send_raw_transaction(&self, bytes: Bytes) -> Result { self.eth.send_raw_transaction(bytes).instrument(engine_span!()).await } /// Handler for `eth_getLogs` async fn logs(&self, filter: Filter) -> Result> { self.eth_filter.logs(filter).instrument(engine_span!()).await } /// Handler for `eth_getProof` async fn get_proof( &self, address: Address, keys: Vec, block_number: Option, ) -> Result { self.eth.get_proof(address, keys, block_number).instrument(engine_span!()).await } }