Add pending RPC to query for blocks that can be received by an account.
This commit is contained in:
parent
1b308d8234
commit
7cde941f2e
3 changed files with 64 additions and 2 deletions
|
@ -1200,8 +1200,32 @@ TEST (rpc, peers)
|
|||
system.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
auto & frontiers_node (response.json.get_child ("peers"));
|
||||
ASSERT_EQ (1, frontiers_node.size ());
|
||||
auto & peers_node (response.json.get_child ("peers"));
|
||||
ASSERT_EQ (1, peers_node.size ());
|
||||
}
|
||||
|
||||
TEST (rpc, pending)
|
||||
{
|
||||
rai::system system (24000, 1);
|
||||
rai::keypair key1;
|
||||
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
|
||||
auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100));
|
||||
rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true));
|
||||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "pending");
|
||||
request.put ("account", key1.pub.to_account ());
|
||||
request.put ("count", "100");
|
||||
test_response response (request, rpc, system.service);
|
||||
while (response.status == 0)
|
||||
{
|
||||
system.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
auto & blocks_node (response.json.get_child ("blocks"));
|
||||
ASSERT_EQ (1, blocks_node.size ());
|
||||
rai::block_hash hash1 (blocks_node.begin ()->second.get <std::string> (""));
|
||||
ASSERT_EQ (block1->hash (), hash1);
|
||||
}
|
||||
|
||||
TEST (rpc_config, serialization)
|
||||
|
|
|
@ -847,6 +847,39 @@ void rai::rpc_handler::peers ()
|
|||
rpc.send_response (response, response_l);
|
||||
}
|
||||
|
||||
void rai::rpc_handler::pending ()
|
||||
{
|
||||
std::string account_text (request.get <std::string> ("account"));
|
||||
rai::account account;
|
||||
if (!account.decode_account(account_text))
|
||||
{
|
||||
std::string count_text (request.get <std::string> ("count"));
|
||||
uint64_t count;
|
||||
if (!rpc.decode_unsigned (count_text, count))
|
||||
{
|
||||
boost::property_tree::ptree response_l;
|
||||
boost::property_tree::ptree peers_l;
|
||||
{
|
||||
rai::transaction transaction (rpc.node.store.environment, nullptr, false);
|
||||
rai::account end (account.number () + 1);
|
||||
for (auto i (rpc.node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (rpc.node.store.pending_begin (transaction, rai::pending_key (end, 0))); i != n && peers_l.size ()< count; ++i)
|
||||
{
|
||||
rai::pending_key key (i->first);
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", key.hash.to_string ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
}
|
||||
response_l.add_child ("blocks", peers_l);
|
||||
rpc.send_response (response, response_l);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rpc.error_response (response, "Bad account number");
|
||||
}
|
||||
}
|
||||
|
||||
void rai::rpc_handler::payment_begin ()
|
||||
{
|
||||
std::string id_text (request.get <std::string> ("wallet"));
|
||||
|
@ -1753,6 +1786,10 @@ void rai::rpc_handler::process_request ()
|
|||
{
|
||||
peers ();
|
||||
}
|
||||
else if (action == "pending")
|
||||
{
|
||||
pending ();
|
||||
}
|
||||
else if (action == "process")
|
||||
{
|
||||
process ();
|
||||
|
|
|
@ -109,6 +109,7 @@ public:
|
|||
void payment_end ();
|
||||
void payment_wait ();
|
||||
void peers ();
|
||||
void pending ();
|
||||
void process ();
|
||||
void rai_to_raw ();
|
||||
void rai_from_raw ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue