mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 07:37:57 +00:00
Add an system_syncState RPC method (#7315)
* Add system_syncState RPC method * Update client/rpc-api/src/system/helpers.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -86,6 +86,18 @@ pub enum NodeRole {
|
||||
Sentry,
|
||||
}
|
||||
|
||||
/// The state of the syncing of the node.
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SyncState<Number> {
|
||||
/// Height of the block at which syncing started.
|
||||
pub starting_block: Number,
|
||||
/// Height of the current best block of the node.
|
||||
pub current_block: Number,
|
||||
/// Height of the highest block learned from the network. Missing if no block is known yet.
|
||||
#[serde(default = "Default::default", skip_serializing_if = "Option::is_none")]
|
||||
pub highest_block: Option<Number>,
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -114,4 +126,25 @@ mod tests {
|
||||
r#"{"peerId":"2","roles":"a","bestHash":5,"bestNumber":6}"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_serialize_sync_state() {
|
||||
assert_eq!(
|
||||
::serde_json::to_string(&SyncState {
|
||||
starting_block: 12u32,
|
||||
current_block: 50u32,
|
||||
highest_block: Some(128u32),
|
||||
}).unwrap(),
|
||||
r#"{"startingBlock":12,"currentBlock":50,"highestBlock":128}"#,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
::serde_json::to_string(&SyncState {
|
||||
starting_block: 12u32,
|
||||
current_block: 50u32,
|
||||
highest_block: None,
|
||||
}).unwrap(),
|
||||
r#"{"startingBlock":12,"currentBlock":50}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use futures::{future::BoxFuture, compat::Compat};
|
||||
|
||||
use self::error::Result as SystemResult;
|
||||
|
||||
pub use self::helpers::{SystemInfo, Health, PeerInfo, NodeRole};
|
||||
pub use self::helpers::{SystemInfo, Health, PeerInfo, NodeRole, SyncState};
|
||||
pub use self::gen_client::Client as SystemClient;
|
||||
|
||||
/// Substrate system RPC API
|
||||
@@ -103,4 +103,9 @@ pub trait SystemApi<Hash, Number> {
|
||||
/// Returns the roles the node is running as.
|
||||
#[rpc(name = "system_nodeRoles", returns = "Vec<NodeRole>")]
|
||||
fn system_node_roles(&self) -> Receiver<Vec<NodeRole>>;
|
||||
|
||||
/// Returns the state of the syncing of the node: starting block, current best block, highest
|
||||
/// known block.
|
||||
#[rpc(name = "system_syncState", returns = "SyncState<Number>")]
|
||||
fn system_sync_state(&self) -> Receiver<SyncState<Number>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user