rpc net methods returns real peer count && protocol version
This commit is contained in:
parent
7d327298dd
commit
07d6965ce7
@ -53,19 +53,19 @@ fn setup_log(init: &str) {
|
|||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "rpc")]
|
#[cfg(feature = "rpc")]
|
||||||
fn setup_rpc_server(client: Arc<Client>) {
|
fn setup_rpc_server(client: Arc<Client>, sync: Arc<EthSync>) {
|
||||||
use rpc::v1::*;
|
use rpc::v1::*;
|
||||||
|
|
||||||
let mut server = rpc::HttpServer::new(1);
|
let mut server = rpc::HttpServer::new(1);
|
||||||
server.add_delegate(Web3Client::new().to_delegate());
|
server.add_delegate(Web3Client::new().to_delegate());
|
||||||
server.add_delegate(EthClient::new(client.clone()).to_delegate());
|
server.add_delegate(EthClient::new(client.clone()).to_delegate());
|
||||||
server.add_delegate(EthFilterClient::new(client).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");
|
server.start_async("127.0.0.1:3030");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "rpc"))]
|
#[cfg(not(feature = "rpc"))]
|
||||||
fn setup_rpc_server(_client: Arc<Client>) {
|
fn setup_rpc_server(_client: Arc<Client>, _sync: Arc<EthSync>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -81,7 +81,7 @@ fn main() {
|
|||||||
let mut net_settings = NetworkConfiguration::new();
|
let mut net_settings = NetworkConfiguration::new();
|
||||||
net_settings.boot_nodes = init_nodes;
|
net_settings.boot_nodes = init_nodes;
|
||||||
let mut service = ClientService::start(spec, net_settings).unwrap();
|
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() });
|
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");
|
service.io().register_handler(io_handler).expect("Error registering IO handler");
|
||||||
|
|
||||||
|
@ -1,21 +1,29 @@
|
|||||||
//! Net rpc implementation.
|
//! Net rpc implementation.
|
||||||
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
use ethcore::sync::EthSync;
|
||||||
use v1::traits::Net;
|
use v1::traits::Net;
|
||||||
|
|
||||||
/// Net rpc implementation.
|
/// Net rpc implementation.
|
||||||
pub struct NetClient;
|
pub struct NetClient {
|
||||||
|
sync: Arc<EthSync>
|
||||||
|
}
|
||||||
|
|
||||||
impl NetClient {
|
impl NetClient {
|
||||||
/// Creates new NetClient.
|
/// Creates new NetClient.
|
||||||
pub fn new() -> Self { NetClient }
|
pub fn new(sync: Arc<EthSync>) -> Self {
|
||||||
|
NetClient {
|
||||||
|
sync: sync
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Net for NetClient {
|
impl Net for NetClient {
|
||||||
fn version(&self, _: Params) -> Result<Value, Error> {
|
fn version(&self, _: Params) -> Result<Value, Error> {
|
||||||
Ok(Value::U64(63))
|
Ok(Value::U64(self.sync.status().protocol_version as u64))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
|
fn peer_count(&self, _params: Params) -> Result<Value, Error> {
|
||||||
Ok(Value::U64(0))
|
Ok(Value::U64(self.sync.status().num_peers as u64))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user