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

50 lines
1.4 KiB
Rust
Raw Normal View History

// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
2017-03-22 21:09:43 +01:00
// Parity Ethereum is free software: you can redistribute it and/or modify
2017-03-22 21:09:43 +01:00
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
2017-03-22 21:09:43 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
2017-03-22 21:09:43 +01:00
//! Net rpc implementation.
use std::sync::Arc;
2017-11-14 11:38:17 +01:00
use jsonrpc_core::Result;
2018-04-10 12:13:49 +02:00
use sync::LightSyncProvider;
2017-03-22 21:09:43 +01:00
use v1::traits::Net;
/// Net rpc implementation.
pub struct NetClient<S: ?Sized> {
sync: Arc<S>
}
impl<S: ?Sized> NetClient<S> where S: LightSyncProvider {
/// Creates new NetClient.
pub fn new(sync: Arc<S>) -> Self {
NetClient {
sync,
2017-03-22 21:09:43 +01:00
}
}
}
impl<S: ?Sized + Sync + Send + 'static> Net for NetClient<S> where S: LightSyncProvider {
2017-11-14 11:38:17 +01:00
fn version(&self) -> Result<String> {
2017-03-22 21:09:43 +01:00
Ok(format!("{}", self.sync.network_id()).to_owned())
}
2017-11-14 11:38:17 +01:00
fn peer_count(&self) -> Result<String> {
2017-03-22 21:09:43 +01:00
Ok(format!("0x{:x}", self.sync.peer_numbers().connected as u64).to_owned())
}
2017-11-14 11:38:17 +01:00
fn is_listening(&self) -> Result<bool> {
2017-03-22 21:09:43 +01:00
Ok(true)
}
}