use jsonrpsee::core::RpcResult as Result; use reth_network_api::PeersInfo; use reth_primitives::U64; use reth_rpc_api::NetApiServer; use reth_rpc_eth_api::helpers::EthApiSpec; /// `Net` API implementation. /// /// This type provides the functionality for handling `net` related requests. pub struct NetApi { /// An interface to interact with the network network: Net, /// The implementation of `eth` API eth: Eth, } // === impl NetApi === impl NetApi { /// Returns a new instance with the given network and eth interface implementations pub const fn new(network: Net, eth: Eth) -> Self { Self { network, eth } } } /// Net rpc implementation impl NetApiServer for NetApi where Net: PeersInfo + 'static, Eth: EthApiSpec + 'static, { /// Handler for `net_version` fn version(&self) -> Result { // Note: net_version is numeric: ().to_string()) } /// Handler for `net_peerCount` fn peer_count(&self) -> Result { Ok(U64::from(self.network.num_connected_peers())) } /// Handler for `net_listening` fn is_listening(&self) -> Result { Ok(true) } } impl std::fmt::Debug for NetApi { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("NetApi").finish_non_exhaustive() } }