use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_network_api::NetworkInfo; use reth_primitives::{keccak256, Bytes, B256}; use reth_rpc_api::Web3ApiServer; use reth_rpc_server_types::ToRpcResult; /// `web3` API implementation. /// /// This type provides the functionality for handling `web3` related requests. pub struct Web3Api { /// An interface to interact with the network network: N, } impl Web3Api { /// Creates a new instance of `Web3Api`. pub const fn new(network: N) -> Self { Self { network } } } #[async_trait] impl Web3ApiServer for Web3Api where N: NetworkInfo + 'static, { /// Handler for `web3_clientVersion` async fn client_version(&self) -> RpcResult { let status = self.network.network_status().await.to_rpc_result()?; Ok(status.client_version) } /// Handler for `web3_sha3` fn sha3(&self, input: Bytes) -> RpcResult { Ok(keccak256(input)) } } impl std::fmt::Debug for Web3Api { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Web3Api").finish_non_exhaustive() } }