diff --git a/bin/src/main.rs b/bin/src/main.rs index 190bab311..3d4199fcf 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -53,19 +53,19 @@ fn setup_log(init: &str) { #[cfg(feature = "rpc")] -fn setup_rpc_server(client: Arc) { +fn setup_rpc_server(client: Arc, sync: Arc) { use rpc::v1::*; let mut server = rpc::HttpServer::new(1); server.add_delegate(Web3Client::new().to_delegate()); server.add_delegate(EthClient::new(client.clone()).to_delegate()); server.add_delegate(EthFilterClient::new(client).to_delegate()); - server.add_delegate(NetClient::new().to_delegate()); + server.add_delegate(NetClient::new(sync).to_delegate()); server.start_async("127.0.0.1:3030"); } #[cfg(not(feature = "rpc"))] -fn setup_rpc_server(_client: Arc) { +fn setup_rpc_server(_client: Arc, _sync: Arc) { } fn main() { @@ -81,7 +81,7 @@ fn main() { let mut net_settings = NetworkConfiguration::new(); net_settings.boot_nodes = init_nodes; let mut service = ClientService::start(spec, net_settings).unwrap(); - setup_rpc_server(service.client()); + setup_rpc_server(service.client(), service.sync()); let io_handler = Arc::new(ClientIoHandler { client: service.client(), info: Default::default(), sync: service.sync() }); service.io().register_handler(io_handler).expect("Error registering IO handler"); diff --git a/rpc/src/v1/impls/net.rs b/rpc/src/v1/impls/net.rs index 7bf9cb248..dff351c33 100644 --- a/rpc/src/v1/impls/net.rs +++ b/rpc/src/v1/impls/net.rs @@ -1,21 +1,29 @@ //! Net rpc implementation. +use std::sync::Arc; use jsonrpc_core::*; +use ethcore::sync::EthSync; use v1::traits::Net; /// Net rpc implementation. -pub struct NetClient; +pub struct NetClient { + sync: Arc +} impl NetClient { /// Creates new NetClient. - pub fn new() -> Self { NetClient } + pub fn new(sync: Arc) -> Self { + NetClient { + sync: sync + } + } } impl Net for NetClient { fn version(&self, _: Params) -> Result { - Ok(Value::U64(63)) + Ok(Value::U64(self.sync.status().protocol_version as u64)) } fn peer_count(&self, _params: Params) -> Result { - Ok(Value::U64(0)) + Ok(Value::U64(self.sync.status().num_peers as u64)) } }