RPC pending with threshold as array
This commit is contained in:
parent
a0577bf480
commit
a8f7c3828c
2 changed files with 42 additions and 23 deletions
|
@ -1267,8 +1267,16 @@ TEST (rpc, pending)
|
|||
ASSERT_EQ (200, response0.status);
|
||||
blocks_node = response0.json.get_child ("blocks");
|
||||
ASSERT_EQ (1, blocks_node.size ());
|
||||
auto amount (blocks_node.begin ()->second.get <std::string> (block1->hash ().to_string ()));
|
||||
ASSERT_EQ ("100", amount);
|
||||
std::unordered_map <rai::block_hash, rai::uint128_union> blocks;
|
||||
for (auto i (blocks_node.begin ()), j (blocks_node.end ()); i != j; ++i)
|
||||
{
|
||||
rai::block_hash hash;
|
||||
hash.decode_hex (i->first);
|
||||
rai::uint128_union amount;
|
||||
amount.decode_dec (i->second.get <std::string> (""));
|
||||
blocks [hash] = amount;
|
||||
}
|
||||
ASSERT_EQ (blocks[block1->hash ()], 100);
|
||||
request.put ("threshold", "101");
|
||||
test_response response1 (request, rpc, system.service);
|
||||
while (response1.status == 0)
|
||||
|
@ -2157,12 +2165,20 @@ TEST (rpc, accounts_pending)
|
|||
system.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
for (auto & blocks : response1.json.get_child("blocks"))
|
||||
for (auto & pending : response1.json.get_child("blocks"))
|
||||
{
|
||||
std::string account_text (blocks.first);
|
||||
std::string account_text (pending.first);
|
||||
ASSERT_EQ (key1.pub.to_account (), account_text);
|
||||
auto amount (blocks.second.begin ()->second.get <std::string> (block1->hash ().to_string ()));
|
||||
ASSERT_EQ ("100", amount);
|
||||
std::unordered_map <rai::block_hash, rai::uint128_union> blocks;
|
||||
for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i)
|
||||
{
|
||||
rai::block_hash hash;
|
||||
hash.decode_hex (i->first);
|
||||
rai::uint128_union amount;
|
||||
amount.decode_dec (i->second.get <std::string> (""));
|
||||
blocks [hash] = amount;
|
||||
}
|
||||
ASSERT_EQ (blocks[block1->hash ()], 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2292,7 +2308,7 @@ TEST (rpc, wallet_pending)
|
|||
system0.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
for (auto & pending : response.json.get_child("pending"))
|
||||
for (auto & pending : response.json.get_child("blocks"))
|
||||
{
|
||||
std::string account_text (pending.first);
|
||||
ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text);
|
||||
|
@ -2308,14 +2324,20 @@ TEST (rpc, wallet_pending)
|
|||
system0.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response0.status);
|
||||
for (auto & pending : response0.json.get_child("pending"))
|
||||
for (auto & pending : response0.json.get_child("blocks"))
|
||||
{
|
||||
std::string account_text (pending.first);
|
||||
ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text);
|
||||
auto & blocks_node (pending.second.get_child (rai::test_genesis_key.pub.to_account ()));
|
||||
ASSERT_EQ (1, blocks_node.size ());
|
||||
rai::block_hash hash1 (blocks_node.begin ()->second.get <std::string> (""));
|
||||
ASSERT_EQ (block1->hash (), hash1);
|
||||
std::unordered_map <rai::block_hash, rai::uint128_union> blocks;
|
||||
for (auto i (pending.second.begin ()), j (pending.second.end ()); i != j; ++i)
|
||||
{
|
||||
rai::block_hash hash;
|
||||
hash.decode_hex (i->first);
|
||||
rai::uint128_union amount;
|
||||
amount.decode_dec (i->second.get <std::string> (""));
|
||||
blocks [hash] = amount;
|
||||
}
|
||||
ASSERT_EQ (blocks[block1->hash ()], 100);
|
||||
}
|
||||
request.put ("threshold", "101");
|
||||
test_response response1 (request, rpc, system0.service);
|
||||
|
@ -2324,7 +2346,7 @@ TEST (rpc, wallet_pending)
|
|||
system0.poll ();
|
||||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
auto & pending1 (response1.json.get_child ("pending"));
|
||||
auto & pending1 (response1.json.get_child ("blocks"));
|
||||
ASSERT_EQ (0, pending1.size ());
|
||||
}
|
||||
|
||||
|
|
|
@ -630,9 +630,9 @@ void rai::rpc_handler::accounts_pending ()
|
|||
for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (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;
|
||||
if (threshold.is_zero ())
|
||||
{
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", key.hash.to_string ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
|
@ -641,8 +641,7 @@ void rai::rpc_handler::accounts_pending ()
|
|||
rai::pending_info info (i->second);
|
||||
if (info.amount.number () >= threshold.number ())
|
||||
{
|
||||
entry.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1384,9 +1383,9 @@ void rai::rpc_handler::pending ()
|
|||
for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (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;
|
||||
if (threshold.is_zero ())
|
||||
{
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", key.hash.to_string ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
|
@ -1395,8 +1394,7 @@ void rai::rpc_handler::pending ()
|
|||
rai::pending_info info (i->second);
|
||||
if (info.amount.number () >= threshold.number ())
|
||||
{
|
||||
entry.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2471,9 +2469,9 @@ void rai::rpc_handler::wallet_pending ()
|
|||
for (auto ii (node.store.pending_begin (transaction, rai::pending_key (account, 0))), nn (node.store.pending_begin (transaction, rai::pending_key (end, 0))); ii != nn && peers_l.size ()< count; ++ii)
|
||||
{
|
||||
rai::pending_key key (ii->first);
|
||||
boost::property_tree::ptree entry;
|
||||
if (threshold.is_zero ())
|
||||
{
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", key.hash.to_string ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
}
|
||||
|
@ -2482,8 +2480,7 @@ void rai::rpc_handler::wallet_pending ()
|
|||
rai::pending_info info (ii->second);
|
||||
if (info.amount.number () >= threshold.number ())
|
||||
{
|
||||
entry.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
peers_l.push_back (std::make_pair ("", entry));
|
||||
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to <std::string> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2492,7 +2489,7 @@ void rai::rpc_handler::wallet_pending ()
|
|||
pending.add_child (account.to_account (), peers_l);
|
||||
}
|
||||
}
|
||||
response_l.add_child ("pending", pending);
|
||||
response_l.add_child ("blocks", pending);
|
||||
response (response_l);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue