refactor: Pass reference to LookUpStats

This commit is contained in:
MacroFake
2022-05-26 17:06:07 +02:00
parent 0897b189e4
commit faa3d38ec6
4 changed files with 18 additions and 13 deletions

View File

@@ -6,6 +6,7 @@
#include <coins.h>
#include <crypto/muhash.h>
#include <index/coinstatsindex.h>
#include <kernel/coinstats.h>
#include <node/blockstorage.h>
#include <serialize.h>
#include <txdb.h>
@@ -322,13 +323,13 @@ static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, D
return db.Read(DBHashKey(block.hash), result);
}
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex& block_index) const
{
CCoinsStats stats{Assert(block_index)->nHeight, block_index->GetBlockHash()};
CCoinsStats stats{block_index.nHeight, block_index.GetBlockHash()};
stats.index_used = true;
DBVal entry;
if (!LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) {
if (!LookUpOne(*m_db, {block_index.GetBlockHash(), block_index.nHeight}, entry)) {
return std::nullopt;
}

View File

@@ -5,11 +5,14 @@
#ifndef BITCOIN_INDEX_COINSTATSINDEX_H
#define BITCOIN_INDEX_COINSTATSINDEX_H
#include <chain.h>
#include <crypto/muhash.h>
#include <flatfile.h>
#include <index/base.h>
#include <kernel/coinstats.h>
class CBlockIndex;
class CDBBatch;
namespace kernel {
struct CCoinsStats;
}
/**
* CoinStatsIndex maintains statistics on the UTXO set.
@@ -56,7 +59,7 @@ public:
explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
// Look up stats for a specific block using CBlockIndex
std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex* block_index) const;
std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;
};
/// The global UTXO set hash object.