mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 14:17:56 +00:00
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:
@@ -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)]
|
||||
|
||||
@@ -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>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user