Skip to content

Commit

Permalink
Add system health rpc (#510)
Browse files Browse the repository at this point in the history
* add system_health rpc

* fmt
  • Loading branch information
yjhmelody committed Apr 13, 2022
1 parent 9330ba0 commit b9650a5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions subxt/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?)
Expand Down

0 comments on commit b9650a5

Please sign in to comment.