Changeset View
Changeset View
Standalone View
Standalone View
src/node/coinstats.cpp
Show All 32 Lines | for (const auto &output : outputs) { | ||||
VarIntMode::NONNEGATIVE_SIGNED); | VarIntMode::NONNEGATIVE_SIGNED); | ||||
stats.nTransactionOutputs++; | stats.nTransactionOutputs++; | ||||
stats.nTotalAmount += output.second.GetTxOut().nValue; | stats.nTotalAmount += output.second.GetTxOut().nValue; | ||||
stats.nBogoSize += GetBogoSize(output.second.GetTxOut().scriptPubKey); | stats.nBogoSize += GetBogoSize(output.second.GetTxOut().scriptPubKey); | ||||
} | } | ||||
ss << VARINT(0u); | ss << VARINT(0u); | ||||
} | } | ||||
static void ApplyStats(CCoinsStats &stats, std::nullptr_t, const uint256 &hash, | |||||
const std::map<uint32_t, Coin> &outputs) { | |||||
assert(!outputs.empty()); | |||||
stats.nTransactions++; | |||||
for (const auto &output : outputs) { | |||||
stats.nTransactionOutputs++; | |||||
stats.nTotalAmount += output.second.GetTxOut().nValue; | |||||
stats.nBogoSize += GetBogoSize(output.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, 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); | ||||
Show All 37 Lines | |||||
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, | bool GetUTXOStats(CCoinsView *view, 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, stats, ss, interruption_point); | ||||
} | } | ||||
case (CoinStatsHashType::NONE): { | |||||
return GetUTXOStats(view, 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, CCoinsStats &stats) { | static void PrepareHash(CHashWriter &ss, CCoinsStats &stats) { | ||||
ss << stats.hashBlock; | ss << stats.hashBlock; | ||||
} | } | ||||
static void PrepareHash(std::nullptr_t, CCoinsStats &stats) {} | |||||
static void FinalizeHash(CHashWriter &ss, CCoinsStats &stats) { | static void FinalizeHash(CHashWriter &ss, CCoinsStats &stats) { | ||||
stats.hashSerialized = ss.GetHash(); | stats.hashSerialized = ss.GetHash(); | ||||
} | } | ||||
static void FinalizeHash(std::nullptr_t, CCoinsStats &stats) {} |