Changeset View
Changeset View
Standalone View
Standalone View
src/node/coinstats.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <node/coinstats.h> | #include <node/coinstats.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <map> | #include <map> | ||||
static uint64_t GetBogoSize(const CScript &scriptPubKey) { | |||||
return 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + | |||||
8 /* amount */ + 2 /* scriptPubKey len */ + | |||||
scriptPubKey.size() /* scriptPubKey */; | |||||
} | |||||
static void ApplyStats(CCoinsStats &stats, CHashWriter &ss, const uint256 &hash, | static void ApplyStats(CCoinsStats &stats, CHashWriter &ss, const uint256 &hash, | ||||
const std::map<uint32_t, Coin> &outputs) { | const std::map<uint32_t, Coin> &outputs) { | ||||
assert(!outputs.empty()); | assert(!outputs.empty()); | ||||
ss << hash; | ss << hash; | ||||
ss << VARINT(outputs.begin()->second.GetHeight() * 2 + | ss << VARINT(outputs.begin()->second.GetHeight() * 2 + | ||||
outputs.begin()->second.IsCoinBase()); | outputs.begin()->second.IsCoinBase()); | ||||
stats.nTransactions++; | stats.nTransactions++; | ||||
for (const auto &output : outputs) { | for (const auto &output : outputs) { | ||||
ss << VARINT(output.first + 1); | ss << VARINT(output.first + 1); | ||||
ss << output.second.GetTxOut().scriptPubKey; | ss << output.second.GetTxOut().scriptPubKey; | ||||
ss << VARINT_MODE(output.second.GetTxOut().nValue / SATOSHI, | ss << VARINT_MODE(output.second.GetTxOut().nValue / SATOSHI, | ||||
VarIntMode::NONNEGATIVE_SIGNED); | VarIntMode::NONNEGATIVE_SIGNED); | ||||
stats.nTransactionOutputs++; | stats.nTransactionOutputs++; | ||||
stats.nTotalAmount += output.second.GetTxOut().nValue; | stats.nTotalAmount += output.second.GetTxOut().nValue; | ||||
stats.nBogoSize += | stats.nBogoSize += GetBogoSize(output.second.GetTxOut().scriptPubKey); | ||||
32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + | |||||
8 /* amount */ + 2 /* scriptPubKey len */ + | |||||
output.second.GetTxOut().scriptPubKey.size() /* scriptPubKey */; | |||||
} | } | ||||
ss << VARINT(0u); | ss << VARINT(0u); | ||||
} | } | ||||
//! Calculate statistics about the unspent transaction output set | //! Calculate statistics about the unspent transaction output set | ||||
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, | bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, | ||||
const std::function<void()> &interruption_point) { | const std::function<void()> &interruption_point) { | ||||
stats = CCoinsStats(); | stats = CCoinsStats(); | ||||
Show All 36 Lines |