Adding RPC to query online reps.
This commit is contained in:
parent
facbab4d69
commit
b8dbbbf158
5 changed files with 60 additions and 0 deletions
|
@ -3408,3 +3408,33 @@ TEST (rpc, wallet_add_watch)
|
|||
ASSERT_TRUE (success.empty ());
|
||||
ASSERT_TRUE (system.wallet (0)->exists (rai::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
TEST (rpc, online_reps)
|
||||
{
|
||||
rai::system system (24000, 2);
|
||||
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
|
||||
ASSERT_TRUE (system.nodes[1]->online_reps.online_stake ().is_zero ());
|
||||
system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, rai::Gxrb_ratio);
|
||||
auto iterations (0);
|
||||
while (system.nodes[1]->online_reps.online_stake ().is_zero ())
|
||||
{
|
||||
system.poll ();
|
||||
++iterations;
|
||||
ASSERT_LT (iterations, 200);
|
||||
}
|
||||
rai::rpc rpc (system.service, *system.nodes[1], rai::rpc_config (true));
|
||||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "representatives_online");
|
||||
test_response response (request, rpc, system.service);
|
||||
while (response.status == 0)
|
||||
{
|
||||
system.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
auto representatives (response.json.get_child ("representatives"));
|
||||
auto item (representatives.begin ());
|
||||
ASSERT_NE (representatives.end (), item);
|
||||
ASSERT_EQ (rai::test_genesis_key.pub.to_account (), item->first);
|
||||
system.nodes [1]->stop ();
|
||||
}
|
||||
|
|
|
@ -2506,6 +2506,17 @@ rai::uint128_t rai::online_reps::online_stake ()
|
|||
return online_stake_total;
|
||||
}
|
||||
|
||||
std::deque<rai::account> rai::online_reps::list()
|
||||
{
|
||||
std::deque<rai::account> result;
|
||||
std::lock_guard <std::mutex> lock (mutex);
|
||||
for (auto i (reps.begin ()), n (reps.end ()); i != n; ++i)
|
||||
{
|
||||
result.push_back (i->representative);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unordered_set<rai::endpoint> rai::peer_container::random_set (size_t count_a)
|
||||
{
|
||||
std::unordered_set<rai::endpoint> result;
|
||||
|
|
|
@ -310,6 +310,7 @@ public:
|
|||
void vote (std::shared_ptr<rai::vote> const &);
|
||||
void recalculate_stake ();
|
||||
rai::uint128_t online_stake ();
|
||||
std::deque<rai::account> list();
|
||||
boost::multi_index_container<
|
||||
rai::rep_last_heard_info,
|
||||
boost::multi_index::indexed_by<
|
||||
|
|
|
@ -2811,6 +2811,19 @@ void rai::rpc_handler::representatives ()
|
|||
response (response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::representatives_online()
|
||||
{
|
||||
boost::property_tree::ptree response_l;
|
||||
boost::property_tree::ptree representatives;
|
||||
auto reps (node.online_reps.list ());
|
||||
for (auto & i : reps)
|
||||
{
|
||||
representatives.put (i.to_account (), "");
|
||||
}
|
||||
response_l.add_child ("representatives", representatives);
|
||||
response (response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::republish ()
|
||||
{
|
||||
uint64_t count (1024U);
|
||||
|
@ -4686,6 +4699,10 @@ void rai::rpc_handler::process_request ()
|
|||
{
|
||||
representatives ();
|
||||
}
|
||||
else if (action == "representatives_online")
|
||||
{
|
||||
representatives_online ();
|
||||
}
|
||||
else if (action == "republish")
|
||||
{
|
||||
republish ();
|
||||
|
|
|
@ -173,6 +173,7 @@ public:
|
|||
void receive_minimum ();
|
||||
void receive_minimum_set ();
|
||||
void representatives ();
|
||||
void representatives_online ();
|
||||
void republish ();
|
||||
void search_pending ();
|
||||
void search_pending_all ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue