1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use async_trait::async_trait;
use cfx_rpc_cfx_types::ChainStaticMeta;
use cfx_rpc_eth_api::Web3ApiServer;
use cfx_rpc_primitives::Bytes;
use cfx_types::H256;
use jsonrpsee::core::RpcResult;
use keccak_hash::keccak;
use std::fmt::Debug;

pub struct Web3Api;

#[async_trait]
impl Web3ApiServer for Web3Api {
    async fn client_version(&self) -> RpcResult<String> {
        Ok(ChainStaticMeta::client_version())
    }

    fn sha3(&self, input: Bytes) -> RpcResult<H256> {
        Ok(keccak(input.into_vec()))
    }
}

impl Debug for Web3Api {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Web3Api").finish_non_exhaustive()
    }
}