6 #ifndef KAGOME_API_SYSTEM_REQUEST_PEERS 7 #define KAGOME_API_SYSTEM_REQUEST_PEERS 25 explicit Peers(std::shared_ptr<SystemApi> &api) :
api_(api) {
29 outcome::result<Return>
execute()
override {
30 auto &peer_manager = *
api_->getPeerManager();
32 jsonrpc::Value::Array result;
33 result.reserve(peer_manager.activePeersNumber());
35 peer_manager.forEachPeer([&](
auto &peer_id) {
36 auto status_opt = peer_manager.getPeerState(peer_id);
37 if (status_opt.has_value()) {
38 auto &status = status_opt.value();
40 jsonrpc::Value::Struct peer;
41 peer.emplace(
"PeerId", peer_id.toBase58());
44 status.get().roles.flags.authority
46 : status.get().roles.flags.full
48 : status.get().roles.flags.light ?
"LIGHT" :
"NONE");
49 peer.emplace(
"bestHash",
makeValue(status.get().best_block.hash));
50 peer.emplace(
"bestNumber",
makeValue(status.get().best_block.number));
52 result.emplace_back(std::move(peer));
60 std::shared_ptr<SystemApi>
api_;
65 #endif // KAGOME_API_SYSTEM_REQUEST_PEERS Peers(std::shared_ptr< SystemApi > &api)
std::shared_ptr< SystemApi > api_
Returns currently connected peers.
outcome::result< Return > execute() override
jsonrpc::Value makeValue(const uint32_t &)