Skip to content

Commit

Permalink
block::populate() include prevout metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 23, 2024
1 parent a80fe93 commit 3c2ba9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/bitcoin/system/chain/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ class BC_API block
code connect(const context& ctx) const NOEXCEPT;
code confirm(const context& ctx) const NOEXCEPT;

/// Populate previous output metadata internal to the block.
/// Populate previous outputs and metadata internal to the block.
/// Does not populate forward references (consensus limited).
void populate() const NOEXCEPT;
/// Height of zero or prevout not found sets chain::prevout defaults
void populate(size_t height=0, uint32_t median_time_past=0) const NOEXCEPT;

protected:
block(const chain::header::cptr& header,
Expand Down
23 changes: 22 additions & 1 deletion src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ bool block::is_unspent_coinbase_collision() const NOEXCEPT
return !txs_->front()->inputs_ptr()->front()->metadata.spent;
}

void block::populate() const NOEXCEPT
void block::populate(size_t height, uint32_t median_time_past) const NOEXCEPT
{
// Coinbase, outputs only, inputs only.
if (txs_->size() < 3u)
Expand All @@ -579,6 +579,7 @@ void block::populate() const NOEXCEPT

// Skip coinbase tx.
auto tx = std::next(txs_->begin());
const auto metadata = !is_zero(height);
uint32_t index{};

// Outputs only (first tx).
Expand All @@ -592,7 +593,17 @@ void block::populate() const NOEXCEPT
{
const auto element = map.find(in->point());
if (element != map.end())
{
in->prevout = element->second;

if (metadata)
{
in->metadata.height = height;
in->metadata.median_time_past = median_time_past;
in->metadata.spent = false;
in->metadata.coinbase = false;
}
}
}

index = 0;
Expand All @@ -605,7 +616,17 @@ void block::populate() const NOEXCEPT
{
const auto element = map.find(in->point());
if (element != map.end())
{
in->prevout = element->second;

if (metadata)
{
in->metadata.height = height;
in->metadata.median_time_past = median_time_past;
in->metadata.spent = false;
in->metadata.coinbase = false;
}
}
}

BC_POP_WARNING()
Expand Down

0 comments on commit 3c2ba9e

Please sign in to comment.