2016-01-21 11:25:39 +01:00
|
|
|
//! Net rpc implementation.
|
2016-01-28 10:54:49 +01:00
|
|
|
use std::sync::Arc;
|
2016-01-26 13:14:22 +01:00
|
|
|
use jsonrpc_core::*;
|
2016-02-01 12:08:43 +01:00
|
|
|
use ethsync::EthSync;
|
2016-01-27 17:14:41 +01:00
|
|
|
use v1::traits::Net;
|
2016-01-21 11:25:39 +01:00
|
|
|
|
2016-01-27 17:08:59 +01:00
|
|
|
/// Net rpc implementation.
|
2016-01-28 10:54:49 +01:00
|
|
|
pub struct NetClient {
|
|
|
|
sync: Arc<EthSync>
|
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
|
|
|
|
impl NetClient {
|
2016-01-27 17:08:59 +01:00
|
|
|
/// Creates new NetClient.
|
2016-01-28 10:54:49 +01:00
|
|
|
pub fn new(sync: Arc<EthSync>) -> Self {
|
|
|
|
NetClient {
|
|
|
|
sync: sync
|
|
|
|
}
|
|
|
|
}
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Net for NetClient {
|
2016-01-25 17:45:26 +01:00
|
|
|
fn version(&self, _: Params) -> Result<Value, Error> {
|
2016-01-28 10:54:49 +01:00
|
|
|
Ok(Value::U64(self.sync.status().protocol_version as u64))
|
2016-01-25 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
2016-01-21 11:25:39 +01:00
|
|
|
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
|
2016-01-28 10:54:49 +01:00
|
|
|
Ok(Value::U64(self.sync.status().num_peers as u64))
|
2016-01-21 11:25:39 +01:00
|
|
|
}
|
|
|
|
}
|