Peers RPC + UI displaying active/connected/max peers (#1915)
* Peers API * Bumping Parity-UI * Fixing tests
This commit is contained in:
parent
07844d611e
commit
f114a933a3
48
Cargo.lock
generated
48
Cargo.lock
generated
@ -282,10 +282,10 @@ dependencies = [
|
|||||||
"jsonrpc-http-server 6.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
|
"jsonrpc-http-server 6.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
"parity-dapps-home 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps-home 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
"parity-dapps-status 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps-status 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
"parity-dapps-wallet 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps-wallet 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_codegen 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_codegen 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -441,7 +441,7 @@ dependencies = [
|
|||||||
"ethcore-util 1.4.0",
|
"ethcore-util 1.4.0",
|
||||||
"jsonrpc-core 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"jsonrpc-core 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parity-dapps-signer 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps-signer 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ws 0.5.2 (git+https://github.com/ethcore/ws-rs.git?branch=mio-upstream-stable)",
|
"ws 0.5.2 (git+https://github.com/ethcore/ws-rs.git?branch=mio-upstream-stable)",
|
||||||
@ -991,8 +991,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-dapps"
|
name = "parity-dapps"
|
||||||
version = "0.6.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/parity-ui.git#697e860dedc45003909602a002e7743478ab173a"
|
source = "git+https://github.com/ethcore/parity-ui.git#fa7c8b054507b0c85db22e555fe7cca838704661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"aster 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1005,34 +1005,34 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-dapps-home"
|
name = "parity-dapps-home"
|
||||||
version = "0.6.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/parity-ui.git#697e860dedc45003909602a002e7743478ab173a"
|
source = "git+https://github.com/ethcore/parity-ui.git#fa7c8b054507b0c85db22e555fe7cca838704661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-dapps-signer"
|
name = "parity-dapps-signer"
|
||||||
version = "0.6.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/parity-ui.git#697e860dedc45003909602a002e7743478ab173a"
|
source = "git+https://github.com/ethcore/parity-ui.git#fa7c8b054507b0c85db22e555fe7cca838704661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-dapps-status"
|
name = "parity-dapps-status"
|
||||||
version = "0.6.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/parity-ui.git#697e860dedc45003909602a002e7743478ab173a"
|
source = "git+https://github.com/ethcore/parity-ui.git#fa7c8b054507b0c85db22e555fe7cca838704661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-dapps-wallet"
|
name = "parity-dapps-wallet"
|
||||||
version = "0.6.0"
|
version = "1.4.0"
|
||||||
source = "git+https://github.com/ethcore/parity-ui.git#697e860dedc45003909602a002e7743478ab173a"
|
source = "git+https://github.com/ethcore/parity-ui.git#fa7c8b054507b0c85db22e555fe7cca838704661"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)",
|
"parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1657,11 +1657,11 @@ dependencies = [
|
|||||||
"checksum num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "51fedae97a05f7353612fe017ab705a37e6db8f4d67c5c6fe739a9e70d6eed09"
|
"checksum num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "51fedae97a05f7353612fe017ab705a37e6db8f4d67c5c6fe739a9e70d6eed09"
|
||||||
"checksum number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "084d05f4bf60621a9ac9bde941a410df548f4de9545f06e5ee9d3aef4b97cd77"
|
"checksum number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "084d05f4bf60621a9ac9bde941a410df548f4de9545f06e5ee9d3aef4b97cd77"
|
||||||
"checksum odds 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "b28c06e81b0f789122d415d6394b5fe849bde8067469f4c2980d3cdc10c78ec1"
|
"checksum odds 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "b28c06e81b0f789122d415d6394b5fe849bde8067469f4c2980d3cdc10c78ec1"
|
||||||
"checksum parity-dapps 0.6.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
"checksum parity-dapps 1.4.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
||||||
"checksum parity-dapps-home 0.6.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
"checksum parity-dapps-home 1.4.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
||||||
"checksum parity-dapps-signer 0.6.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
"checksum parity-dapps-signer 1.4.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
||||||
"checksum parity-dapps-status 0.6.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
"checksum parity-dapps-status 1.4.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
||||||
"checksum parity-dapps-wallet 0.6.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
"checksum parity-dapps-wallet 1.4.0 (git+https://github.com/ethcore/parity-ui.git)" = "<none>"
|
||||||
"checksum parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e0fd1be2c3cf5fef20a6d18fec252c4f3c87c14fc3039002eb7d4ed91e436826"
|
"checksum parking_lot 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e0fd1be2c3cf5fef20a6d18fec252c4f3c87c14fc3039002eb7d4ed91e436826"
|
||||||
"checksum phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "447d9d45f2e0b4a9b532e808365abf18fc211be6ca217202fcd45236ef12f026"
|
"checksum phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "447d9d45f2e0b4a9b532e808365abf18fc211be6ca217202fcd45236ef12f026"
|
||||||
"checksum phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8af7ae7c3f75a502292b491e5cc0a1f69e3407744abe6e57e2a3b712bb82f01d"
|
"checksum phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8af7ae7c3f75a502292b491e5cc0a1f69e3407744abe6e57e2a3b712bb82f01d"
|
||||||
|
@ -21,11 +21,11 @@ serde_json = "0.7.0"
|
|||||||
serde_macros = { version = "0.7.0", optional = true }
|
serde_macros = { version = "0.7.0", optional = true }
|
||||||
ethcore-rpc = { path = "../rpc" }
|
ethcore-rpc = { path = "../rpc" }
|
||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
parity-dapps = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
|
parity-dapps = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
|
||||||
# List of apps
|
# List of apps
|
||||||
parity-dapps-status = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
|
parity-dapps-status = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
|
||||||
parity-dapps-home = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6" }
|
parity-dapps-home = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4" }
|
||||||
parity-dapps-wallet = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true }
|
parity-dapps-wallet = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4", optional = true }
|
||||||
mime_guess = { version = "1.6.1" }
|
mime_guess = { version = "1.6.1" }
|
||||||
clippy = { version = "0.0.80", optional = true}
|
clippy = { version = "0.0.80", optional = true}
|
||||||
|
|
||||||
|
@ -501,8 +501,6 @@ impl Configuration {
|
|||||||
NetworkSettings {
|
NetworkSettings {
|
||||||
name: self.args.flag_identity.clone(),
|
name: self.args.flag_identity.clone(),
|
||||||
chain: self.chain(),
|
chain: self.chain(),
|
||||||
max_peers: self.max_peers(),
|
|
||||||
min_peers: self.min_peers(),
|
|
||||||
network_port: self.args.flag_port,
|
network_port: self.args.flag_port,
|
||||||
rpc_enabled: !self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc,
|
rpc_enabled: !self.args.flag_jsonrpc_off && !self.args.flag_no_jsonrpc,
|
||||||
rpc_interface: self.args.flag_rpcaddr.clone().unwrap_or(self.args.flag_jsonrpc_interface.clone()),
|
rpc_interface: self.args.flag_rpcaddr.clone().unwrap_or(self.args.flag_jsonrpc_interface.clone()),
|
||||||
@ -779,8 +777,6 @@ mod tests {
|
|||||||
assert_eq!(conf.network_settings(), NetworkSettings {
|
assert_eq!(conf.network_settings(), NetworkSettings {
|
||||||
name: "testname".to_owned(),
|
name: "testname".to_owned(),
|
||||||
chain: "morden".to_owned(),
|
chain: "morden".to_owned(),
|
||||||
max_peers: 50,
|
|
||||||
min_peers: 25,
|
|
||||||
network_port: 30303,
|
network_port: 30303,
|
||||||
rpc_enabled: true,
|
rpc_enabled: true,
|
||||||
rpc_interface: "local".to_owned(),
|
rpc_interface: "local".to_owned(),
|
||||||
|
@ -131,7 +131,7 @@ impl Informant {
|
|||||||
},
|
},
|
||||||
paint(Cyan.bold(), format!("{:2}", sync_info.num_active_peers)),
|
paint(Cyan.bold(), format!("{:2}", sync_info.num_active_peers)),
|
||||||
paint(Cyan.bold(), format!("{:2}", sync_info.num_peers)),
|
paint(Cyan.bold(), format!("{:2}", sync_info.num_peers)),
|
||||||
paint(Cyan.bold(), format!("{:2}", if sync_info.num_peers as u32 > net_config.min_peers { net_config.max_peers} else { net_config.min_peers} ))
|
paint(Cyan.bold(), format!("{:2}", sync_info.current_max_peers(net_config.min_peers, net_config.max_peers))),
|
||||||
),
|
),
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
},
|
},
|
||||||
|
@ -186,7 +186,7 @@ pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: ApiSet
|
|||||||
},
|
},
|
||||||
Api::Ethcore => {
|
Api::Ethcore => {
|
||||||
let queue = deps.signer_port.map(|_| deps.signer_queue.clone());
|
let queue = deps.signer_port.map(|_| deps.signer_queue.clone());
|
||||||
server.add_delegate(EthcoreClient::new(&deps.client, &deps.miner, deps.logger.clone(), deps.settings.clone(), queue).to_delegate())
|
server.add_delegate(EthcoreClient::new(&deps.client, &deps.miner, &deps.sync, &deps.net_service, deps.logger.clone(), deps.settings.clone(), queue).to_delegate())
|
||||||
},
|
},
|
||||||
Api::EthcoreSet => {
|
Api::EthcoreSet => {
|
||||||
server.add_delegate(EthcoreSetClient::new(&deps.client, &deps.miner, &deps.net_service).to_delegate())
|
server.add_delegate(EthcoreSetClient::new(&deps.client, &deps.miner, &deps.net_service).to_delegate())
|
||||||
|
@ -22,10 +22,6 @@ pub struct NetworkSettings {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
/// Name of the chain we are connected to
|
/// Name of the chain we are connected to
|
||||||
pub chain: String,
|
pub chain: String,
|
||||||
/// Min number of peers
|
|
||||||
pub min_peers: u32,
|
|
||||||
/// Max number of peers
|
|
||||||
pub max_peers: u32,
|
|
||||||
/// Networking port
|
/// Networking port
|
||||||
pub network_port: u16,
|
pub network_port: u16,
|
||||||
/// Is JSON-RPC server enabled?
|
/// Is JSON-RPC server enabled?
|
||||||
@ -41,8 +37,6 @@ impl Default for NetworkSettings {
|
|||||||
NetworkSettings {
|
NetworkSettings {
|
||||||
name: "".into(),
|
name: "".into(),
|
||||||
chain: "homestead".into(),
|
chain: "homestead".into(),
|
||||||
min_peers: 25,
|
|
||||||
max_peers: 50,
|
|
||||||
network_port: 30303,
|
network_port: 30303,
|
||||||
rpc_enabled: true,
|
rpc_enabled: true,
|
||||||
rpc_interface: "local".into(),
|
rpc_interface: "local".into(),
|
||||||
|
@ -19,33 +19,49 @@ use util::{RotatingLogger, KeyPair};
|
|||||||
use util::misc::version_data;
|
use util::misc::version_data;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::collections::{BTreeMap};
|
use std::collections::{BTreeMap};
|
||||||
|
|
||||||
use ethstore::random_phrase;
|
use ethstore::random_phrase;
|
||||||
use ethcore::client::{MiningBlockChainClient};
|
use ethsync::{SyncProvider, ManageNetwork};
|
||||||
use jsonrpc_core::*;
|
|
||||||
use ethcore::miner::MinerService;
|
use ethcore::miner::MinerService;
|
||||||
|
use ethcore::client::{MiningBlockChainClient};
|
||||||
|
|
||||||
|
use jsonrpc_core::*;
|
||||||
use v1::traits::Ethcore;
|
use v1::traits::Ethcore;
|
||||||
use v1::types::{Bytes, U256, H160};
|
use v1::types::{Bytes, U256, H160, Peers};
|
||||||
use v1::helpers::{errors, SigningQueue, ConfirmationsQueue, NetworkSettings};
|
use v1::helpers::{errors, SigningQueue, ConfirmationsQueue, NetworkSettings};
|
||||||
use v1::helpers::params::expect_no_params;
|
use v1::helpers::params::expect_no_params;
|
||||||
|
|
||||||
/// Ethcore implementation.
|
/// Ethcore implementation.
|
||||||
pub struct EthcoreClient<C, M> where
|
pub struct EthcoreClient<C, M, S: ?Sized> where
|
||||||
C: MiningBlockChainClient,
|
C: MiningBlockChainClient,
|
||||||
M: MinerService {
|
M: MinerService,
|
||||||
|
S: SyncProvider {
|
||||||
|
|
||||||
client: Weak<C>,
|
client: Weak<C>,
|
||||||
miner: Weak<M>,
|
miner: Weak<M>,
|
||||||
|
sync: Weak<S>,
|
||||||
|
net: Weak<ManageNetwork>,
|
||||||
logger: Arc<RotatingLogger>,
|
logger: Arc<RotatingLogger>,
|
||||||
settings: Arc<NetworkSettings>,
|
settings: Arc<NetworkSettings>,
|
||||||
confirmations_queue: Option<Arc<ConfirmationsQueue>>,
|
confirmations_queue: Option<Arc<ConfirmationsQueue>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, M> EthcoreClient<C, M> where C: MiningBlockChainClient, M: MinerService {
|
impl<C, M, S: ?Sized> EthcoreClient<C, M, S> where C: MiningBlockChainClient, M: MinerService, S: SyncProvider {
|
||||||
/// Creates new `EthcoreClient`.
|
/// Creates new `EthcoreClient`.
|
||||||
pub fn new(client: &Arc<C>, miner: &Arc<M>, logger: Arc<RotatingLogger>, settings: Arc<NetworkSettings>, queue: Option<Arc<ConfirmationsQueue>>) -> Self {
|
pub fn new(
|
||||||
|
client: &Arc<C>,
|
||||||
|
miner: &Arc<M>,
|
||||||
|
sync: &Arc<S>,
|
||||||
|
net: &Arc<ManageNetwork>,
|
||||||
|
logger: Arc<RotatingLogger>,
|
||||||
|
settings: Arc<NetworkSettings>,
|
||||||
|
queue: Option<Arc<ConfirmationsQueue>>
|
||||||
|
) -> Self {
|
||||||
EthcoreClient {
|
EthcoreClient {
|
||||||
client: Arc::downgrade(client),
|
client: Arc::downgrade(client),
|
||||||
miner: Arc::downgrade(miner),
|
miner: Arc::downgrade(miner),
|
||||||
|
sync: Arc::downgrade(sync),
|
||||||
|
net: Arc::downgrade(net),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
confirmations_queue: queue,
|
confirmations_queue: queue,
|
||||||
@ -59,7 +75,7 @@ impl<C, M> EthcoreClient<C, M> where C: MiningBlockChainClient, M: MinerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: MiningBlockChainClient + 'static {
|
impl<C, M, S: ?Sized> Ethcore for EthcoreClient<C, M, S> where M: MinerService + 'static, C: MiningBlockChainClient + 'static, S: SyncProvider + 'static {
|
||||||
|
|
||||||
fn transactions_limit(&self, params: Params) -> Result<Value, Error> {
|
fn transactions_limit(&self, params: Params) -> Result<Value, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
@ -110,10 +126,18 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
|
|||||||
to_value(&self.settings.chain)
|
to_value(&self.settings.chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn net_max_peers(&self, params: Params) -> Result<Value, Error> {
|
fn net_peers(&self, params: Params) -> Result<Value, Error> {
|
||||||
try!(self.active());
|
try!(self.active());
|
||||||
try!(expect_no_params(params));
|
try!(expect_no_params(params));
|
||||||
to_value(&self.settings.max_peers)
|
|
||||||
|
let sync_status = take_weak!(self.sync).status();
|
||||||
|
let net_config = take_weak!(self.net).network_config();
|
||||||
|
|
||||||
|
to_value(&Peers {
|
||||||
|
active: sync_status.num_active_peers,
|
||||||
|
connected: sync_status.num_peers,
|
||||||
|
max: sync_status.current_max_peers(net_config.min_peers, net_config.max_peers),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn net_port(&self, params: Params) -> Result<Value, Error> {
|
fn net_port(&self, params: Params) -> Result<Value, Error> {
|
||||||
|
@ -15,13 +15,16 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use util::log::RotatingLogger;
|
||||||
|
use util::U256;
|
||||||
|
use ethsync::ManageNetwork;
|
||||||
|
use ethcore::client::{TestBlockChainClient};
|
||||||
|
|
||||||
use jsonrpc_core::IoHandler;
|
use jsonrpc_core::IoHandler;
|
||||||
use v1::{Ethcore, EthcoreClient};
|
use v1::{Ethcore, EthcoreClient};
|
||||||
use v1::tests::helpers::TestMinerService;
|
use v1::helpers::{ConfirmationsQueue, NetworkSettings};
|
||||||
use v1::helpers::ConfirmationsQueue;
|
use v1::tests::helpers::{TestSyncProvider, Config, TestMinerService};
|
||||||
use ethcore::client::{TestBlockChainClient};
|
use super::manage_network::TestManageNetwork;
|
||||||
use util::log::RotatingLogger;
|
|
||||||
use v1::helpers::NetworkSettings;
|
|
||||||
|
|
||||||
fn miner_service() -> Arc<TestMinerService> {
|
fn miner_service() -> Arc<TestMinerService> {
|
||||||
Arc::new(TestMinerService::default())
|
Arc::new(TestMinerService::default())
|
||||||
@ -31,6 +34,13 @@ fn client_service() -> Arc<TestBlockChainClient> {
|
|||||||
Arc::new(TestBlockChainClient::default())
|
Arc::new(TestBlockChainClient::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sync_provider() -> Arc<TestSyncProvider> {
|
||||||
|
Arc::new(TestSyncProvider::new(Config {
|
||||||
|
network_id: U256::from(3),
|
||||||
|
num_peers: 120,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
fn logger() -> Arc<RotatingLogger> {
|
fn logger() -> Arc<RotatingLogger> {
|
||||||
Arc::new(RotatingLogger::new("rpc=trace".to_owned()))
|
Arc::new(RotatingLogger::new("rpc=trace".to_owned()))
|
||||||
}
|
}
|
||||||
@ -39,8 +49,6 @@ fn settings() -> Arc<NetworkSettings> {
|
|||||||
Arc::new(NetworkSettings {
|
Arc::new(NetworkSettings {
|
||||||
name: "mynode".to_owned(),
|
name: "mynode".to_owned(),
|
||||||
chain: "testchain".to_owned(),
|
chain: "testchain".to_owned(),
|
||||||
min_peers: 25,
|
|
||||||
max_peers: 25,
|
|
||||||
network_port: 30303,
|
network_port: 30303,
|
||||||
rpc_enabled: true,
|
rpc_enabled: true,
|
||||||
rpc_interface: "all".to_owned(),
|
rpc_interface: "all".to_owned(),
|
||||||
@ -48,16 +56,26 @@ fn settings() -> Arc<NetworkSettings> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ethcore_client(client: &Arc<TestBlockChainClient>, miner: &Arc<TestMinerService>) -> EthcoreClient<TestBlockChainClient, TestMinerService> {
|
fn network_service() -> Arc<ManageNetwork> {
|
||||||
EthcoreClient::new(client, miner, logger(), settings(), None)
|
Arc::new(TestManageNetwork)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ethcore_client(
|
||||||
|
client: &Arc<TestBlockChainClient>,
|
||||||
|
miner: &Arc<TestMinerService>,
|
||||||
|
sync: &Arc<TestSyncProvider>,
|
||||||
|
net: &Arc<ManageNetwork>) -> EthcoreClient<TestBlockChainClient, TestMinerService, TestSyncProvider> {
|
||||||
|
EthcoreClient::new(client, miner, sync, net, logger(), settings(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_ethcore_extra_data() {
|
fn rpc_ethcore_extra_data() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_extraData", "params": [], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"0x01020304","id":1}"#;
|
||||||
@ -72,8 +90,10 @@ fn rpc_ethcore_default_extra_data() {
|
|||||||
|
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_defaultExtraData", "params": [], "id": 1}"#;
|
||||||
let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex());
|
let response = format!(r#"{{"jsonrpc":"2.0","result":"0x{}","id":1}}"#, misc::version_data().to_hex());
|
||||||
@ -85,8 +105,10 @@ fn rpc_ethcore_default_extra_data() {
|
|||||||
fn rpc_ethcore_gas_floor_target() {
|
fn rpc_ethcore_gas_floor_target() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_gasFloorTarget", "params": [], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"0x3039","id":1}"#;
|
||||||
@ -98,8 +120,10 @@ fn rpc_ethcore_gas_floor_target() {
|
|||||||
fn rpc_ethcore_min_gas_price() {
|
fn rpc_ethcore_min_gas_price() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_minGasPrice", "params": [], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"0x01312d00","id":1}"#;
|
||||||
@ -111,10 +135,12 @@ fn rpc_ethcore_min_gas_price() {
|
|||||||
fn rpc_ethcore_dev_logs() {
|
fn rpc_ethcore_dev_logs() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let logger = logger();
|
let logger = logger();
|
||||||
logger.append("a".to_owned());
|
logger.append("a".to_owned());
|
||||||
logger.append("b".to_owned());
|
logger.append("b".to_owned());
|
||||||
let ethcore = EthcoreClient::new(&client, &miner, logger.clone(), settings(), None).to_delegate();
|
let ethcore = EthcoreClient::new(&client, &miner, &sync, &net, logger.clone(), settings(), None).to_delegate();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore);
|
io.add_delegate(ethcore);
|
||||||
|
|
||||||
@ -128,8 +154,10 @@ fn rpc_ethcore_dev_logs() {
|
|||||||
fn rpc_ethcore_dev_logs_levels() {
|
fn rpc_ethcore_dev_logs_levels() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_devLogsLevels", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"rpc=trace","id":1}"#;
|
||||||
@ -141,8 +169,10 @@ fn rpc_ethcore_dev_logs_levels() {
|
|||||||
fn rpc_ethcore_transactions_limit() {
|
fn rpc_ethcore_transactions_limit() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_transactionsLimit", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":1024,"id":1}"#;
|
||||||
@ -154,8 +184,10 @@ fn rpc_ethcore_transactions_limit() {
|
|||||||
fn rpc_ethcore_net_chain() {
|
fn rpc_ethcore_net_chain() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netChain", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"testchain","id":1}"#;
|
||||||
@ -164,14 +196,16 @@ fn rpc_ethcore_net_chain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_ethcore_net_max_peers() {
|
fn rpc_ethcore_net_peers() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netMaxPeers", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPeers", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":25,"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":{"active":0,"connected":120,"max":50},"id":1}"#;
|
||||||
|
|
||||||
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
assert_eq!(io.handle_request(request), Some(response.to_owned()));
|
||||||
}
|
}
|
||||||
@ -180,8 +214,10 @@ fn rpc_ethcore_net_max_peers() {
|
|||||||
fn rpc_ethcore_net_port() {
|
fn rpc_ethcore_net_port() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_netPort", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":30303,"id":1}"#;
|
||||||
@ -193,8 +229,10 @@ fn rpc_ethcore_net_port() {
|
|||||||
fn rpc_ethcore_rpc_settings() {
|
fn rpc_ethcore_rpc_settings() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_rpcSettings", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":{"enabled":true,"interface":"all","port":8545},"id":1}"#;
|
||||||
@ -206,8 +244,10 @@ fn rpc_ethcore_rpc_settings() {
|
|||||||
fn rpc_ethcore_node_name() {
|
fn rpc_ethcore_node_name() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_nodeName", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","result":"mynode","id":1}"#;
|
||||||
@ -219,9 +259,11 @@ fn rpc_ethcore_node_name() {
|
|||||||
fn rpc_ethcore_unsigned_transactions_count() {
|
fn rpc_ethcore_unsigned_transactions_count() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
let queue = Arc::new(ConfirmationsQueue::default());
|
let queue = Arc::new(ConfirmationsQueue::default());
|
||||||
let ethcore = EthcoreClient::new(&client, &miner, logger(), settings(), Some(queue)).to_delegate();
|
let ethcore = EthcoreClient::new(&client, &miner, &sync, &net, logger(), settings(), Some(queue)).to_delegate();
|
||||||
io.add_delegate(ethcore);
|
io.add_delegate(ethcore);
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
||||||
@ -234,8 +276,10 @@ fn rpc_ethcore_unsigned_transactions_count() {
|
|||||||
fn rpc_ethcore_unsigned_transactions_count_when_signer_disabled() {
|
fn rpc_ethcore_unsigned_transactions_count_when_signer_disabled() {
|
||||||
let miner = miner_service();
|
let miner = miner_service();
|
||||||
let client = client_service();
|
let client = client_service();
|
||||||
|
let sync = sync_provider();
|
||||||
|
let net = network_service();
|
||||||
let io = IoHandler::new();
|
let io = IoHandler::new();
|
||||||
io.add_delegate(ethcore_client(&client, &miner).to_delegate());
|
io.add_delegate(ethcore_client(&client, &miner, &sync, &net).to_delegate());
|
||||||
|
|
||||||
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
let request = r#"{"jsonrpc": "2.0", "method": "ethcore_unsignedTransactionsCount", "params":[], "id": 1}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available.","data":null},"id":1}"#;
|
let response = r#"{"jsonrpc":"2.0","error":{"code":-32030,"message":"Trusted Signer is disabled. This API is not available.","data":null},"id":1}"#;
|
||||||
|
@ -45,8 +45,8 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
|||||||
/// Returns chain name
|
/// Returns chain name
|
||||||
fn net_chain(&self, _: Params) -> Result<Value, Error>;
|
fn net_chain(&self, _: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
/// Returns max peers
|
/// Returns peers details
|
||||||
fn net_max_peers(&self, _: Params) -> Result<Value, Error>;
|
fn net_peers(&self, _: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
/// Returns network port
|
/// Returns network port
|
||||||
fn net_port(&self, _: Params) -> Result<Value, Error>;
|
fn net_port(&self, _: Params) -> Result<Value, Error>;
|
||||||
@ -85,7 +85,7 @@ pub trait Ethcore: Sized + Send + Sync + 'static {
|
|||||||
delegate.add_method("ethcore_devLogs", Ethcore::dev_logs);
|
delegate.add_method("ethcore_devLogs", Ethcore::dev_logs);
|
||||||
delegate.add_method("ethcore_devLogsLevels", Ethcore::dev_logs_levels);
|
delegate.add_method("ethcore_devLogsLevels", Ethcore::dev_logs_levels);
|
||||||
delegate.add_method("ethcore_netChain", Ethcore::net_chain);
|
delegate.add_method("ethcore_netChain", Ethcore::net_chain);
|
||||||
delegate.add_method("ethcore_netMaxPeers", Ethcore::net_max_peers);
|
delegate.add_method("ethcore_netPeers", Ethcore::net_peers);
|
||||||
delegate.add_method("ethcore_netPort", Ethcore::net_port);
|
delegate.add_method("ethcore_netPort", Ethcore::net_port);
|
||||||
delegate.add_method("ethcore_rpcSettings", Ethcore::rpc_settings);
|
delegate.add_method("ethcore_rpcSettings", Ethcore::rpc_settings);
|
||||||
delegate.add_method("ethcore_nodeName", Ethcore::node_name);
|
delegate.add_method("ethcore_nodeName", Ethcore::node_name);
|
||||||
|
@ -40,7 +40,7 @@ pub use self::filter::Filter;
|
|||||||
pub use self::hash::{H64, H160, H256, H520, H2048};
|
pub use self::hash::{H64, H160, H256, H520, H2048};
|
||||||
pub use self::index::Index;
|
pub use self::index::Index;
|
||||||
pub use self::log::Log;
|
pub use self::log::Log;
|
||||||
pub use self::sync::{SyncStatus, SyncInfo};
|
pub use self::sync::{SyncStatus, SyncInfo, Peers};
|
||||||
pub use self::transaction::Transaction;
|
pub use self::transaction::Transaction;
|
||||||
pub use self::transaction_request::TransactionRequest;
|
pub use self::transaction_request::TransactionRequest;
|
||||||
pub use self::receipt::Receipt;
|
pub use self::receipt::Receipt;
|
||||||
|
@ -31,6 +31,17 @@ pub struct SyncInfo {
|
|||||||
pub highest_block: U256,
|
pub highest_block: U256,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Peers info
|
||||||
|
#[derive(Default, Debug, Serialize, PartialEq)]
|
||||||
|
pub struct Peers {
|
||||||
|
/// Number of active peers
|
||||||
|
pub active: usize,
|
||||||
|
/// Number of connected peers
|
||||||
|
pub connected: usize,
|
||||||
|
/// Max number of peers
|
||||||
|
pub max: u32,
|
||||||
|
}
|
||||||
|
|
||||||
/// Sync status
|
/// Sync status
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum SyncStatus {
|
pub enum SyncStatus {
|
||||||
@ -53,7 +64,7 @@ impl Serialize for SyncStatus {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use super::{SyncInfo, SyncStatus};
|
use super::{SyncInfo, SyncStatus, Peers};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_sync_info() {
|
fn test_serialize_sync_info() {
|
||||||
@ -62,6 +73,13 @@ mod tests {
|
|||||||
assert_eq!(serialized, r#"{"startingBlock":"0x00","currentBlock":"0x00","highestBlock":"0x00"}"#);
|
assert_eq!(serialized, r#"{"startingBlock":"0x00","currentBlock":"0x00","highestBlock":"0x00"}"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serialize_peers() {
|
||||||
|
let t = Peers::default();
|
||||||
|
let serialized = serde_json::to_string(&t).unwrap();
|
||||||
|
assert_eq!(serialized, r#"{"active":0,"connected":0,"max":0}"#);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_sync_status() {
|
fn test_serialize_sync_status() {
|
||||||
let t = SyncStatus::None;
|
let t = SyncStatus::None;
|
||||||
|
@ -19,7 +19,7 @@ ws = { git = "https://github.com/ethcore/ws-rs.git", branch = "mio-upstream-stab
|
|||||||
ethcore-util = { path = "../util" }
|
ethcore-util = { path = "../util" }
|
||||||
ethcore-io = { path = "../util/io" }
|
ethcore-io = { path = "../util/io" }
|
||||||
ethcore-rpc = { path = "../rpc" }
|
ethcore-rpc = { path = "../rpc" }
|
||||||
parity-dapps-signer = { git = "https://github.com/ethcore/parity-ui.git", version = "0.6", optional = true}
|
parity-dapps-signer = { git = "https://github.com/ethcore/parity-ui.git", version = "1.4", optional = true}
|
||||||
|
|
||||||
clippy = { version = "0.0.80", optional = true}
|
clippy = { version = "0.0.80", optional = true}
|
||||||
|
|
||||||
|
@ -187,6 +187,15 @@ impl SyncStatus {
|
|||||||
pub fn is_major_syncing(&self) -> bool {
|
pub fn is_major_syncing(&self) -> bool {
|
||||||
self.state != SyncState::Idle && self.state != SyncState::NewBlocks
|
self.state != SyncState::Idle && self.state != SyncState::NewBlocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns max no of peers to display in informants
|
||||||
|
pub fn current_max_peers(&self, min_peers: u32, max_peers: u32) -> u32 {
|
||||||
|
if self.num_peers as u32 > min_peers {
|
||||||
|
max_peers
|
||||||
|
} else {
|
||||||
|
min_peers
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||||
|
Loading…
Reference in New Issue
Block a user