Changeset View
Changeset View
Standalone View
Standalone View
src/node/coinstats.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | for (auto it = outputs.begin(); it != outputs.end(); ++it) { | ||||
stats.nTransactionOutputs++; | stats.nTransactionOutputs++; | ||||
stats.nTotalAmount += it->second.GetTxOut().nValue; | stats.nTotalAmount += it->second.GetTxOut().nValue; | ||||
stats.nBogoSize += GetBogoSize(it->second.GetTxOut().scriptPubKey); | stats.nBogoSize += GetBogoSize(it->second.GetTxOut().scriptPubKey); | ||||
} | } | ||||
} | } | ||||
//! Calculate statistics about the unspent transaction output set | //! Calculate statistics about the unspent transaction output set | ||||
template <typename T> | template <typename T> | ||||
static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, | static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, | ||||
CCoinsStats &stats, T hash_obj, | |||||
const std::function<void()> &interruption_point) { | const std::function<void()> &interruption_point) { | ||||
stats = CCoinsStats(); | stats = CCoinsStats(); | ||||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | ||||
assert(pcursor); | assert(pcursor); | ||||
stats.hashBlock = pcursor->GetBestBlock(); | stats.hashBlock = pcursor->GetBestBlock(); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *block = | assert(std::addressof(g_chainman.m_blockman) == | ||||
g_chainman.m_blockman.LookupBlockIndex(stats.hashBlock); | std::addressof(blockman)); | ||||
const CBlockIndex *block = blockman.LookupBlockIndex(stats.hashBlock); | |||||
stats.nHeight = Assert(block)->nHeight; | stats.nHeight = Assert(block)->nHeight; | ||||
} | } | ||||
PrepareHash(hash_obj, stats); | PrepareHash(hash_obj, stats); | ||||
TxId prevkey; | TxId prevkey; | ||||
std::map<uint32_t, Coin> outputs; | std::map<uint32_t, Coin> outputs; | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
Show All 18 Lines | static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, | ||||
} | } | ||||
FinalizeHash(hash_obj, stats); | FinalizeHash(hash_obj, stats); | ||||
stats.nDiskSize = view->EstimateSize(); | stats.nDiskSize = view->EstimateSize(); | ||||
return true; | return true; | ||||
} | } | ||||
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, | bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, CCoinsStats &stats, | ||||
CoinStatsHashType hash_type, | CoinStatsHashType hash_type, | ||||
const std::function<void()> &interruption_point) { | const std::function<void()> &interruption_point) { | ||||
switch (hash_type) { | switch (hash_type) { | ||||
case (CoinStatsHashType::HASH_SERIALIZED): { | case (CoinStatsHashType::HASH_SERIALIZED): { | ||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | ||||
return GetUTXOStats(view, stats, ss, interruption_point); | return GetUTXOStats(view, blockman, stats, ss, interruption_point); | ||||
} | } | ||||
case (CoinStatsHashType::MUHASH): { | case (CoinStatsHashType::MUHASH): { | ||||
MuHash3072 muhash; | MuHash3072 muhash; | ||||
return GetUTXOStats(view, stats, muhash, interruption_point); | return GetUTXOStats(view, blockman, stats, muhash, | ||||
interruption_point); | |||||
} | } | ||||
case (CoinStatsHashType::NONE): { | case (CoinStatsHashType::NONE): { | ||||
return GetUTXOStats(view, stats, nullptr, interruption_point); | return GetUTXOStats(view, blockman, stats, nullptr, | ||||
interruption_point); | |||||
} | } | ||||
} // no default case, so the compiler can warn about missing cases | } // no default case, so the compiler can warn about missing cases | ||||
assert(false); | assert(false); | ||||
} | } | ||||
// The legacy hash serializes the hashBlock | // The legacy hash serializes the hashBlock | ||||
static void PrepareHash(CHashWriter &ss, const CCoinsStats &stats) { | static void PrepareHash(CHashWriter &ss, const CCoinsStats &stats) { | ||||
ss << stats.hashBlock; | ss << stats.hashBlock; | ||||
Show All 14 Lines |