mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-30 08:49:29 +02:00
index, refactor: deduplicate LookUpOne
LookUpOne is used by both coinstatsindex and blockfilterindex, the two implementations had already started to deviate slightly for no apparent reason.
This commit is contained in:
@@ -234,25 +234,6 @@ bool CoinStatsIndex::CustomRemove(const interfaces::BlockInfo& block)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockRef& block, DBVal& result)
|
||||
{
|
||||
// First check if the result is stored under the height index and the value
|
||||
// there matches the block hash. This should be the case if the block is on
|
||||
// the active chain.
|
||||
std::pair<uint256, DBVal> read_out;
|
||||
if (!db.Read(DBHeightKey(block.height), read_out)) {
|
||||
return false;
|
||||
}
|
||||
if (read_out.first == block.hash) {
|
||||
result = std::move(read_out.second);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If value at the height index corresponds to an different block, the
|
||||
// result will be stored in the hash index.
|
||||
return db.Read(DBHashKey(block.hash), result);
|
||||
}
|
||||
|
||||
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex& block_index) const
|
||||
{
|
||||
CCoinsStats stats{block_index.nHeight, block_index.GetBlockHash()};
|
||||
|
||||
Reference in New Issue
Block a user