mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 02:17:58 +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:
@@ -30,7 +30,7 @@ use sp_runtime::traits::{self, Header as HeaderT};
|
||||
use self::error::Result;
|
||||
|
||||
pub use sc_rpc_api::system::*;
|
||||
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;
|
||||
|
||||
macro_rules! bail_if_unsafe {
|
||||
@@ -66,7 +66,9 @@ pub enum Request<B: traits::Block> {
|
||||
/// Must return any potential parse error.
|
||||
NetworkRemoveReservedPeer(String, oneshot::Sender<Result<()>>),
|
||||
/// Must return the node role.
|
||||
NodeRoles(oneshot::Sender<Vec<NodeRole>>)
|
||||
NodeRoles(oneshot::Sender<Vec<NodeRole>>),
|
||||
/// Must return the state of the node syncing.
|
||||
SyncState(oneshot::Sender<SyncState<<B::Header as HeaderT>::Number>>),
|
||||
}
|
||||
|
||||
impl<B: traits::Block> System<B> {
|
||||
@@ -189,4 +191,10 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
let _ = self.send_back.unbounded_send(Request::NodeRoles(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
}
|
||||
|
||||
fn system_sync_state(&self) -> Receiver<SyncState<<B::Header as HeaderT>::Number>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::SyncState(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,13 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
|
||||
Request::NodeRoles(sender) => {
|
||||
let _ = sender.send(vec![NodeRole::Authority]);
|
||||
}
|
||||
Request::SyncState(sender) => {
|
||||
let _ = sender.send(SyncState {
|
||||
starting_block: 1,
|
||||
current_block: 2,
|
||||
highest_block: Some(3),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
future::ready(())
|
||||
@@ -291,6 +298,18 @@ fn system_node_roles() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_sync_state() {
|
||||
assert_eq!(
|
||||
wait_receiver(api(None).system_sync_state()),
|
||||
SyncState {
|
||||
starting_block: 1,
|
||||
current_block: 2,
|
||||
highest_block: Some(3),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_network_add_reserved() {
|
||||
let good_peer_id = "/ip4/198.51.100.19/tcp/30333/p2p/QmSk5HQbn6LhUwDiNMseVUjuRYhEtYj4aUZ6WfWoGURpdV";
|
||||
|
||||
Reference in New Issue
Block a user