openethereum/rpc/src/v1/impls/net.rs

30 lines
589 B
Rust
Raw Normal View History

2016-01-21 11:25:39 +01:00
//! Net rpc implementation.
use std::sync::Arc;
2016-01-26 13:14:22 +01:00
use jsonrpc_core::*;
use ethcore::sync::EthSync;
use v1::traits::Net;
2016-01-21 11:25:39 +01:00
/// Net rpc implementation.
pub struct NetClient {
sync: Arc<EthSync>
}
2016-01-21 11:25:39 +01:00
impl NetClient {
/// Creates new NetClient.
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> {
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> {
Ok(Value::U64(self.sync.status().num_peers as u64))
2016-01-21 11:25:39 +01:00
}
}