Merge pull request #4709 from clemahieu/state_open_account_history
Fix regression account history when querying open state blocks
This commit is contained in:
commit
be764b0408
2 changed files with 28 additions and 5 deletions
|
@ -2525,9 +2525,11 @@ public:
|
|||
tree.put ("previous", block_a.hashables.previous.to_string ());
|
||||
}
|
||||
auto balance (block_a.hashables.balance.number ());
|
||||
auto previous_balance = handler.node.ledger.any.block_balance (transaction, block_a.hashables.previous);
|
||||
if (!previous_balance)
|
||||
auto previous_balance_raw = handler.node.ledger.any.block_balance (transaction, block_a.hashables.previous);
|
||||
auto previous_balance = previous_balance_raw.value_or (0);
|
||||
if (!block_a.hashables.previous.is_zero () && !previous_balance_raw.has_value ())
|
||||
{
|
||||
// If previous hash is non-zero and we can't query the balance, e.g. it's pruned, we can't determine the block type
|
||||
if (raw)
|
||||
{
|
||||
tree.put ("subtype", "unknown");
|
||||
|
@ -2537,7 +2539,7 @@ public:
|
|||
tree.put ("type", "unknown");
|
||||
}
|
||||
}
|
||||
else if (balance < previous_balance.value ().number ())
|
||||
else if (balance < previous_balance.number ())
|
||||
{
|
||||
if (should_ignore_account (block_a.hashables.link.as_account ()))
|
||||
{
|
||||
|
@ -2553,7 +2555,7 @@ public:
|
|||
tree.put ("type", "send");
|
||||
}
|
||||
tree.put ("account", block_a.hashables.link.to_account ());
|
||||
tree.put ("amount", (previous_balance.value ().number () - balance).convert_to<std::string> ());
|
||||
tree.put ("amount", (previous_balance.number () - balance).convert_to<std::string> ());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2592,7 +2594,7 @@ public:
|
|||
{
|
||||
tree.put ("account", source_account.value ().to_account ());
|
||||
}
|
||||
tree.put ("amount", (balance - previous_balance.value ().number ()).convert_to<std::string> ());
|
||||
tree.put ("amount", (balance - previous_balance.number ()).convert_to<std::string> ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/secure/ledger_set_any.hpp>
|
||||
#include <nano/secure/ledger_set_confirmed.hpp>
|
||||
#include <nano/test_common/chains.hpp>
|
||||
#include <nano/test_common/network.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
#include <nano/test_common/telemetry.hpp>
|
||||
|
@ -1329,6 +1330,26 @@ TEST (rpc, history_pruning)
|
|||
ASSERT_EQ (usend->hash ().to_string (), entry.get<std::string> ("hash"));
|
||||
}
|
||||
|
||||
TEST (rpc, account_history_state_open)
|
||||
{
|
||||
nano::test::system system;
|
||||
nano::keypair key;
|
||||
auto node0 = add_ipc_enabled_node (system);
|
||||
auto blocks = nano::test::setup_new_account (system, *node0, 1, nano::dev::genesis_key, key, key.pub, true);
|
||||
auto const rpc_ctx = add_rpc (system, node0);
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "account_history");
|
||||
request.put ("account", key.pub.to_account ());
|
||||
request.put ("count", 1);
|
||||
auto response (wait_response (system, rpc_ctx, request, 10s));
|
||||
auto & history_node (response.get_child ("history"));
|
||||
ASSERT_EQ (1, history_node.size ());
|
||||
auto history0 = *history_node.begin ();
|
||||
ASSERT_EQ ("1", history0.second.get<std::string> ("height"));
|
||||
ASSERT_EQ ("receive", history0.second.get<std::string> ("type"));
|
||||
ASSERT_EQ (blocks.second->hash ().to_string (), history0.second.get<std::string> ("hash"));
|
||||
}
|
||||
|
||||
TEST (rpc, process_block)
|
||||
{
|
||||
nano::test::system system;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue