cfx_rpc/
net.rs

1use cfx_rpc_cfx_types::traits::ChainMetaProvider;
2use cfx_rpc_eth_api::NetApiServer;
3use cfx_types::U64;
4use jsonrpsee::core::RpcResult;
5
6pub struct NetApi {
7    chain_meta: Box<dyn ChainMetaProvider + Send + Sync>,
8}
9
10impl NetApi {
11    pub fn new(chain_meta: Box<dyn ChainMetaProvider + Send + Sync>) -> Self {
12        Self { chain_meta }
13    }
14}
15
16impl NetApiServer for NetApi {
17    fn version(&self) -> RpcResult<String> {
18        Ok(self.chain_meta.chain_id().to_string())
19    }
20
21    fn peer_count(&self) -> RpcResult<U64> { Ok(U64::from(0)) }
22
23    fn is_listening(&self) -> RpcResult<bool> { Ok(true) }
24}