WIP: Node role RPC call (#3719)

* Add a Node Role RPC call

* Formatting

* Fix tests

* Change tests to use NodeRole::Authority so I don't forget to update the test

* Improve role checking

* return a vec instead

* fix tests
This commit is contained in:
Ashley
2019-10-16 10:59:25 +01:00
committed by Bastian Köcher
parent 8ef20a5534
commit 642c8504c4
5 changed files with 62 additions and 9 deletions
+19 -6
View File
@@ -50,6 +50,14 @@ pub struct Health {
pub should_have_peers: bool,
}
impl fmt::Display for Health {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} peers ({})", self.peers, if self.is_syncing {
"syncing"
} else { "idle" })
}
}
/// Network Peer information
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -66,12 +74,17 @@ pub struct PeerInfo<Hash, Number> {
pub best_number: Number,
}
impl fmt::Display for Health {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} peers ({})", self.peers, if self.is_syncing {
"syncing"
} else { "idle" })
}
/// The role the node is running as
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub enum NodeRole {
/// The node is a full node
Full,
/// The node is a light client
LightClient,
/// The node is an authority
Authority,
/// An unknown role with a bit number
UnknownRole(u8)
}
#[cfg(test)]
+5 -1
View File
@@ -24,7 +24,7 @@ use jsonrpc_derive::rpc;
use self::error::Result;
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo};
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo, NodeRole};
pub use self::gen_client::Client as SystemClient;
/// Substrate system RPC API
@@ -64,4 +64,8 @@ pub trait SystemApi<Hash, Number> {
// TODO: make this stable and move structs https://github.com/paritytech/substrate/issues/1890
#[rpc(name = "system_networkState", returns = "jsonrpc_core::Value")]
fn system_network_state(&self) -> Receiver<jsonrpc_core::Value>;
/// Returns the roles the node is running as.
#[rpc(name = "system_nodeRoles", returns = "Vec<NodeRole>")]
fn system_node_roles(&self) -> Receiver<Vec<NodeRole>>;
}