Add ledger::head_block query which returns the head block for a given account. (#4121)
This commit is contained in:
parent
1b99696e6b
commit
004ffe5d6d
3 changed files with 20 additions and 0 deletions
|
|
@ -5673,3 +5673,12 @@ TEST (ledger, is_send_legacy)
|
|||
ASSERT_TRUE (ledger.is_send (tx, *ctx.blocks ()[0]));
|
||||
ASSERT_FALSE (ledger.is_send (tx, *ctx.blocks ()[1]));
|
||||
}
|
||||
|
||||
TEST (ledger, head_block)
|
||||
{
|
||||
auto ctx = nano::test::context::ledger_empty ();
|
||||
auto & ledger = ctx.ledger ();
|
||||
auto & store = ctx.store ();
|
||||
auto tx = store.tx_begin_read ();
|
||||
ASSERT_EQ (*nano::dev::genesis, *ledger.head_block (tx, nano::dev::genesis->account ()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1343,6 +1343,16 @@ std::shared_ptr<nano::block> nano::ledger::forked_block (nano::transaction const
|
|||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<nano::block> nano::ledger::head_block (nano::transaction const & transaction, nano::account const & account)
|
||||
{
|
||||
auto info = store.account.get (transaction, account);
|
||||
if (info)
|
||||
{
|
||||
return store.block.get (transaction, info->head);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool nano::ledger::block_confirmed (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const
|
||||
{
|
||||
if (store.pruned.exists (transaction_a, hash_a))
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public:
|
|||
nano::uint128_t weight (nano::account const &);
|
||||
std::shared_ptr<nano::block> successor (nano::transaction const &, nano::qualified_root const &);
|
||||
std::shared_ptr<nano::block> forked_block (nano::transaction const &, nano::block const &);
|
||||
std::shared_ptr<nano::block> head_block (nano::transaction const &, nano::account const &);
|
||||
bool block_confirmed (nano::transaction const &, nano::block_hash const &) const;
|
||||
nano::block_hash latest (nano::transaction const &, nano::account const &);
|
||||
nano::root latest_root (nano::transaction const &, nano::account const &);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue