From 5a11b58ad22179cb526782bfd88f9f112aaf523b Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 23 Jan 2023 15:59:37 +0100 Subject: [PATCH] refactor: replace NetworkHandle with trait in NetApi (#979) --- crates/net/rpc/src/net.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/net/rpc/src/net.rs b/crates/net/rpc/src/net.rs index 826652f8a5..c0e9e03861 100644 --- a/crates/net/rpc/src/net.rs +++ b/crates/net/rpc/src/net.rs @@ -1,6 +1,5 @@ use crate::eth::EthApiSpec; use jsonrpsee::core::RpcResult as Result; -use reth_network::NetworkHandle; use reth_network_api::PeersInfo; use reth_rpc_api::NetApiServer; use reth_rpc_types::PeerCount; @@ -8,21 +7,28 @@ use reth_rpc_types::PeerCount; /// `Net` API implementation. /// /// This type provides the functionality for handling `net` related requests. -pub struct NetApi { +pub struct NetApi { /// An interface to interact with the network - network: NetworkHandle, + network: Net, /// The implementation of `eth` API - eth: Box, + eth: Eth, } -impl std::fmt::Debug for NetApi { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("NetApi").finish_non_exhaustive() +// === impl NetApi === + +impl NetApi { + /// Returns a new instance with the given network and eth interface implementations + pub fn new(network: Net, eth: Eth) -> Self { + Self { network, eth } } } /// Net rpc implementation -impl NetApiServer for NetApi { +impl NetApiServer for NetApi +where + Net: PeersInfo + 'static, + Eth: EthApiSpec + 'static, +{ fn version(&self) -> Result { Ok(self.eth.chain_id().to_string()) } @@ -35,3 +41,9 @@ impl NetApiServer for NetApi { 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() + } +}