Fixed account_history RPC to include receive blocks. Previously receive blocks were filtered out as it was comparing link hash instead of link as account. Also added test case for receive blocks (#2244)
This commit is contained in:
parent
f689cff225
commit
102f8abfee
2 changed files with 24 additions and 2 deletions
|
|
@ -2134,7 +2134,8 @@ public:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (should_ignore_account (block_a.hashables.link))
|
auto account (handler.node.ledger.account (transaction, block_a.hashables.link));
|
||||||
|
if (should_ignore_account (account))
|
||||||
{
|
{
|
||||||
tree.clear ();
|
tree.clear ();
|
||||||
return;
|
return;
|
||||||
|
|
@ -2147,7 +2148,7 @@ public:
|
||||||
{
|
{
|
||||||
tree.put ("type", "receive");
|
tree.put ("type", "receive");
|
||||||
}
|
}
|
||||||
tree.put ("account", handler.node.ledger.account (transaction, block_a.hashables.link).to_account ());
|
tree.put ("account", account.to_account ());
|
||||||
tree.put ("amount", (balance - previous_balance).convert_to<std::string> ());
|
tree.put ("amount", (balance - previous_balance).convert_to<std::string> ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1558,6 +1558,7 @@ TEST (rpc, account_history)
|
||||||
ASSERT_NE (nullptr, send2);
|
ASSERT_NE (nullptr, send2);
|
||||||
auto receive2 (system.wallet (0)->receive_action (*send2, account2, system.nodes[0]->config.receive_minimum.number ()));
|
auto receive2 (system.wallet (0)->receive_action (*send2, account2, system.nodes[0]->config.receive_minimum.number ()));
|
||||||
scoped_thread_name_io.renew ();
|
scoped_thread_name_io.renew ();
|
||||||
|
// Test filter for send blocks
|
||||||
ASSERT_NE (nullptr, receive2);
|
ASSERT_NE (nullptr, receive2);
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree request;
|
boost::property_tree::ptree request;
|
||||||
|
|
@ -1577,6 +1578,26 @@ TEST (rpc, account_history)
|
||||||
auto history_node (response.json.get_child ("history"));
|
auto history_node (response.json.get_child ("history"));
|
||||||
ASSERT_EQ (history_node.size (), 1);
|
ASSERT_EQ (history_node.size (), 1);
|
||||||
}
|
}
|
||||||
|
// Test filter for receive blocks
|
||||||
|
ASSERT_NE (nullptr, receive2);
|
||||||
|
{
|
||||||
|
boost::property_tree::ptree request;
|
||||||
|
request.put ("action", "account_history");
|
||||||
|
request.put ("account", account2.to_account ());
|
||||||
|
boost::property_tree::ptree other_account;
|
||||||
|
other_account.put ("", nano::test_genesis_key.pub.to_account ());
|
||||||
|
boost::property_tree::ptree filtered_accounts;
|
||||||
|
filtered_accounts.push_back (std::make_pair ("", other_account));
|
||||||
|
request.add_child ("account_filter", filtered_accounts);
|
||||||
|
request.put ("count", 100);
|
||||||
|
test_response response (request, rpc.config.port, system.io_ctx);
|
||||||
|
while (response.status == 0)
|
||||||
|
{
|
||||||
|
ASSERT_NO_ERROR (system.poll ());
|
||||||
|
}
|
||||||
|
auto history_node (response.json.get_child ("history"));
|
||||||
|
ASSERT_EQ (history_node.size (), 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST (rpc, history_count)
|
TEST (rpc, history_count)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue