Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes account_history RPC to include receive blocks when filtering accounts. #2244

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,8 @@ class history_visitor : public nano::block_visitor
}
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 ();
return;
Expand All @@ -2147,7 +2148,7 @@ class history_visitor : public nano::block_visitor
{
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> ());
}
}
Expand Down
21 changes: 21 additions & 0 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ TEST (rpc, account_history)
ASSERT_NE (nullptr, send2);
auto receive2 (system.wallet (0)->receive_action (*send2, account2, system.nodes[0]->config.receive_minimum.number ()));
scoped_thread_name_io.renew ();
// Test filter for send blocks
ASSERT_NE (nullptr, receive2);
{
boost::property_tree::ptree request;
Expand All @@ -1577,6 +1578,26 @@ TEST (rpc, account_history)
auto history_node (response.json.get_child ("history"));
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)
Expand Down