1use alloy_primitives::U64;
2use jsonrpsee::core::RpcResult as Result;
3use reth_network_api::PeersInfo;
4use reth_rpc_api::NetApiServer;
5use reth_rpc_eth_api::helpers::EthApiSpec;
6
7pub struct NetApi<Net, Eth> {
11 network: Net,
13 eth: Eth,
15}
16
17impl<Net, Eth> NetApi<Net, Eth> {
20 pub const fn new(network: Net, eth: Eth) -> Self {
22 Self { network, eth }
23 }
24}
25
26impl<Net, Eth> NetApiServer for NetApi<Net, Eth>
28where
29 Net: PeersInfo + 'static,
30 Eth: EthApiSpec + 'static,
31{
32 fn version(&self) -> Result<String> {
34 Ok(self.eth.chain_id().to::<u64>().to_string())
36 }
37
38 fn peer_count(&self) -> Result<U64> {
40 Ok(U64::from(self.network.num_connected_peers()))
41 }
42
43 fn is_listening(&self) -> Result<bool> {
45 Ok(true)
46 }
47}
48
49impl<Net, Eth> std::fmt::Debug for NetApi<Net, Eth> {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 f.debug_struct("NetApi").finish_non_exhaustive()
52 }
53}