mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
WIP: Node role RPC call (#3719)
* Add a Node Role RPC call * Formatting * Fix tests * Change tests to use NodeRole::Authority so I don't forget to update the test * Improve role checking * return a vec instead * fix tests
This commit is contained in:
@@ -25,7 +25,7 @@ use sr_primitives::traits::{self, Header as HeaderT};
|
||||
use self::error::Result;
|
||||
|
||||
pub use api::system::*;
|
||||
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo};
|
||||
pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo, NodeRole};
|
||||
pub use self::gen_client::Client as SystemClient;
|
||||
|
||||
/// System API implementation
|
||||
@@ -42,6 +42,8 @@ pub enum Request<B: traits::Block> {
|
||||
Peers(oneshot::Sender<Vec<PeerInfo<B::Hash, <B::Header as HeaderT>::Number>>>),
|
||||
/// Must return the state of the network.
|
||||
NetworkState(oneshot::Sender<rpc::Value>),
|
||||
/// Must return the node role.
|
||||
NodeRoles(oneshot::Sender<Vec<NodeRole>>)
|
||||
}
|
||||
|
||||
impl<B: traits::Block> System<B> {
|
||||
@@ -94,4 +96,10 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
let _ = self.send_back.unbounded_send(Request::NetworkState(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
}
|
||||
|
||||
fn system_node_roles(&self) -> Receiver<Vec<NodeRole>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let _ = self.send_back.unbounded_send(Request::NodeRoles(tx));
|
||||
Receiver(Compat::new(rx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,9 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> {
|
||||
average_upload_per_sec: 0,
|
||||
peerset: serde_json::Value::Null,
|
||||
}).unwrap());
|
||||
},
|
||||
Request::NodeRoles(sender) => {
|
||||
let _ = sender.send(vec![NodeRole::Authority]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -221,3 +224,11 @@ fn system_network_state() {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_node_roles() {
|
||||
assert_eq!(
|
||||
wait_receiver(api(None).system_node_roles()),
|
||||
vec![NodeRole::Authority]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user