Adding RPC to find out how much representation an account has.

This commit is contained in:
clemahieu 2017-01-13 19:21:04 -06:00
commit 79e5be06d4
3 changed files with 43 additions and 0 deletions

View file

@ -1599,3 +1599,22 @@ TEST (rpc, representative)
thread1.join();
}
TEST (rpc, representation)
{
rai::system system (24000, 1);
auto pool (boost::make_shared <boost::network::utils::thread_pool> ());
rai::rpc rpc (system.service, pool, *system.nodes [0], rai::rpc_config (true));
rpc.start ();
std::thread thread1 ([&rpc] () {rpc.server.run();});
boost::property_tree::ptree request;
std::string wallet;
request.put ("account", rai::genesis_account.to_account ());
request.put ("action", "representation");
auto response (test_response (request, rpc, system.service));
ASSERT_EQ (boost::network::http::server <rai::rpc>::response::ok, static_cast <uint16_t> (boost::network::http::status (response.second)));
std::string amount_text1 (response.first.get <std::string> ("representation"));
ASSERT_EQ (amount_text1, rai::genesis_amount.convert_to <std::string> ());
rpc.stop();
thread1.join();
}

View file

@ -1031,6 +1031,25 @@ void rai::rpc_handler::rai_to_raw ()
}
}
void rai::rpc_handler::representation ()
{
std::string account_text (request.get <std::string> ("account"));
rai::account account;
auto error (account.decode_account (account_text));
if (!error)
{
rai::transaction transaction (rpc.node.store.environment, nullptr, false);
auto representation (rpc.node.store.representation_get (transaction, account));
boost::property_tree::ptree response_l;
response_l.put ("representation", representation.convert_to <std::string> ());
rpc.send_response (connection, response_l);
}
else
{
rpc.error_response (connection, "Bad account number");
}
}
void rai::rpc_handler::representative ()
{
std::string account_text (request.get <std::string> ("account"));
@ -1726,6 +1745,10 @@ void rai::rpc_handler::process_request ()
{
rai_to_raw ();
}
else if (action == "representation")
{
representation ();
}
else if (action == "representative")
{
representative ();

View file

@ -112,6 +112,7 @@ public:
void process ();
void rai_to_raw ();
void rai_from_raw ();
void representation ();
void representative ();
void search_pending ();
void send ();