Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system health rpc #510

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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