Skip to content
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
37 changes: 37 additions & 0 deletions include/bitcoin/database/impl/query/properties_block.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,27 @@ bool CLASS::get_work(uint256_t& work, const header_link& link) const NOEXCEPT
return result;
}

// TODO: optimize with stored aggregate.
TEMPLATE
bool CLASS::get_branch_work(uint256_t& work, const header_link& link) const NOEXCEPT
{
uint256_t proof{};
auto parent = link;
work = zero;

while (get_work(proof, parent))
{
work += proof;
parent = to_parent(parent);

// Genesis parent link is terminal.
if (parent.is_terminal())
return true;
}

return false;
}

TEMPLATE
bool CLASS::get_bits(uint32_t& bits, const header_link& link) const NOEXCEPT
{
Expand Down Expand Up @@ -248,6 +269,22 @@ size_t CLASS::get_tx_count(const header_link& link) const NOEXCEPT
return txs.number;
}

// TODO: optimize with stored aggregate.
TEMPLATE
size_t CLASS::get_branch_tx_count(const header_link& link) const NOEXCEPT
{
size_t count{};
auto parent = link;

while (!parent.is_terminal())
{
count += get_tx_count(parent);
parent = to_parent(parent);
}

return count;
}

TEMPLATE
tx_link CLASS::get_position_tx(const header_link& link,
size_t position) const NOEXCEPT
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ class query
hash_digest get_top_candidate_hash() const NOEXCEPT;
hashes get_tx_keys(const header_link& link) const NOEXCEPT;
size_t get_tx_count(const header_link& link) const NOEXCEPT;
size_t get_branch_tx_count(const header_link& link) const NOEXCEPT;
inline hash_digest get_header_key(const header_link& link) const NOEXCEPT;
inline hash_digest get_tx_key(const tx_link& link) const NOEXCEPT;
inline ins_key get_point_key(const ins_link& link) const NOEXCEPT;
Expand Down Expand Up @@ -570,6 +571,7 @@ class query
bool get_timestamp(uint32_t& timestamp, const header_link& link) const NOEXCEPT;
bool get_version(uint32_t& version, const header_link& link) const NOEXCEPT;
bool get_work(uint256_t& work, const header_link& link) const NOEXCEPT;
bool get_branch_work(uint256_t& work, const header_link& link) const NOEXCEPT;
bool get_bits(uint32_t& bits, const header_link& link) const NOEXCEPT;
bool get_context(context& ctx, const header_link& link) const NOEXCEPT;
bool get_context(chain_context& ctx,
Expand Down
Loading