Adding account_block_count RPC.
This commit is contained in:
parent
bb10027287
commit
6dc7d23676
3 changed files with 49 additions and 0 deletions
|
|
@ -97,6 +97,24 @@ TEST (rpc, account_balance)
|
||||||
ASSERT_EQ ("0", pending_text);
|
ASSERT_EQ ("0", pending_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST (rpc, account_block_count)
|
||||||
|
{
|
||||||
|
rai::system system (24000, 1);
|
||||||
|
rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true));
|
||||||
|
rpc.start ();
|
||||||
|
boost::property_tree::ptree request;
|
||||||
|
request.put ("action", "account_block_count");
|
||||||
|
request.put ("account", rai::test_genesis_key.pub.to_account ());
|
||||||
|
test_response response (request, rpc, system.service);
|
||||||
|
while (response.status == 0)
|
||||||
|
{
|
||||||
|
system.poll ();
|
||||||
|
}
|
||||||
|
ASSERT_EQ (200, response.status);
|
||||||
|
std::string block_count_text (response.json.get <std::string> ("block_count"));
|
||||||
|
ASSERT_EQ ("1", block_count_text);
|
||||||
|
}
|
||||||
|
|
||||||
TEST (rpc, account_create)
|
TEST (rpc, account_create)
|
||||||
{
|
{
|
||||||
rai::system system (24000, 1);
|
rai::system system (24000, 1);
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,32 @@ void rai::rpc_handler::account_balance ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rai::rpc_handler::account_block_count ()
|
||||||
|
{
|
||||||
|
std::string account_text (request.get <std::string> ("account"));
|
||||||
|
rai::uint256_union account;
|
||||||
|
auto error (account.decode_account (account_text));
|
||||||
|
if (!error)
|
||||||
|
{
|
||||||
|
rai::transaction transaction (node.store.environment, nullptr, false);
|
||||||
|
rai::account_info info;
|
||||||
|
if (!node.store.account_get (transaction, account, info))
|
||||||
|
{
|
||||||
|
boost::property_tree::ptree response_l;
|
||||||
|
response_l.put ("block_count", std::to_string (info.block_count));
|
||||||
|
response (response_l);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_response (response, "Account not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error_response (response, "Bad account number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void rai::rpc_handler::account_create ()
|
void rai::rpc_handler::account_create ()
|
||||||
{
|
{
|
||||||
if (rpc.config.enable_control)
|
if (rpc.config.enable_control)
|
||||||
|
|
@ -1794,6 +1820,10 @@ void rai::rpc_handler::process_request ()
|
||||||
{
|
{
|
||||||
account_balance ();
|
account_balance ();
|
||||||
}
|
}
|
||||||
|
else if (action == "account_block_count")
|
||||||
|
{
|
||||||
|
account_block_count ();
|
||||||
|
}
|
||||||
else if (action == "account_create")
|
else if (action == "account_create")
|
||||||
{
|
{
|
||||||
account_create ();
|
account_create ();
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public:
|
||||||
rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function <void (boost::property_tree::ptree const &)> const &);
|
rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function <void (boost::property_tree::ptree const &)> const &);
|
||||||
void process_request ();
|
void process_request ();
|
||||||
void account_balance ();
|
void account_balance ();
|
||||||
|
void account_block_count ();
|
||||||
void account_create ();
|
void account_create ();
|
||||||
void account_get ();
|
void account_get ();
|
||||||
void account_key ();
|
void account_key ();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue