Add system health rpc (#510)

* add system_health rpc

* fmt
This commit is contained in:
yjh
2022-04-13 17:30:48 +08:00
committed by GitHub
parent 9330ba067d
commit b9650a59b0
+19
View File
@@ -222,6 +222,20 @@ pub struct BlockStats {
pub num_extrinsics: u64,
}
/// Health struct returned by the RPC
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Health {
/// Number of connected peers
pub peers: usize,
/// Is the node syncing
pub is_syncing: bool,
/// Should this node have any peers
///
/// Might be false for local chains or when running without discovery.
pub should_have_peers: bool,
}
/// Client for substrate rpc interfaces
pub struct Rpc<T: Config> {
/// Rpc client for sending requests.
@@ -329,6 +343,11 @@ impl<T: Config> Rpc<T> {
.await?)
}
/// Fetch system health
pub async fn system_health(&self) -> Result<Health, BasicError> {
Ok(self.client.request("system_health", rpc_params![]).await?)
}
/// Fetch system chain
pub async fn system_chain(&self) -> Result<String, BasicError> {
Ok(self.client.request("system_chain", rpc_params![]).await?)