expose peer information via rpc (#1362)

* expose peer information via rpc

* fixes tests

* cleanup

Co-Authored-By: xlc <xlchen1291@gmail.com>

* Update docs

Co-Authored-By: xlc <xlchen1291@gmail.com>

* Add missing docs

* keep original type for PeerInfo best_hash/best_number

* cleanup

* Update mod.rs
This commit is contained in:
Xiliang Chen
2019-01-10 00:18:24 +13:00
committed by Gav Wood
parent 43269f0dbc
commit eb3503b0c7
8 changed files with 91 additions and 9 deletions
+27 -1
View File
@@ -16,8 +16,10 @@
use super::*;
use network::{self, SyncState, SyncStatus, ProtocolStatus};
use network::{self, SyncState, SyncStatus, ProtocolStatus, NodeIndex, PeerId, PeerInfo as NetworkPeerInfo, PublicKey};
use network::config::Roles;
use test_client::runtime::Block;
use primitives::H256;
#[derive(Default)]
struct Status {
@@ -37,6 +39,15 @@ impl network::SyncProvider<Block> for Status {
num_active_peers: 0,
}
}
fn peers(&self) -> Vec<(NodeIndex, Option<PeerId>, NetworkPeerInfo<Block>)> {
vec![(1, Some(PublicKey::Ed25519((0 .. 32).collect::<Vec<u8>>()).into()), NetworkPeerInfo {
roles: Roles::FULL,
protocol_version: 1,
best_hash: Default::default(),
best_number: 1
})]
}
}
@@ -129,3 +140,18 @@ fn system_health() {
}
);
}
#[test]
fn system_peers() {
assert_eq!(
api(None).system_peers().unwrap(),
vec![PeerInfo {
index: 1,
peer_id: "QmS5oyTmdjwBowwAH1D9YQnoe2HyWpVemH8qHiU5RqWPh4".into(),
roles: "FULL".into(),
protocol_version: 1,
best_hash: Default::default(),
best_number: 1u64,
}]
);
}