Bitcoin Core  22.99.0
P2P Digital Currency
coinstats.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_NODE_COINSTATS_H
7 #define BITCOIN_NODE_COINSTATS_H
8 
9 #include <chain.h>
10 #include <coins.h>
11 #include <consensus/amount.h>
12 #include <streams.h>
13 #include <uint256.h>
14 
15 #include <cstdint>
16 #include <functional>
17 
18 class CCoinsView;
19 namespace node {
20 class BlockManager;
21 } // namespace node
22 
23 namespace node {
24 enum class CoinStatsHashType {
26  MUHASH,
27  NONE,
28 };
29 
30 struct CCoinsStats {
33 
34  int nHeight{0};
36  uint64_t nTransactions{0};
37  uint64_t nTransactionOutputs{0};
38  uint64_t nBogoSize{0};
40  uint64_t nDiskSize{0};
42  std::optional<CAmount> total_amount{0};
43 
45  uint64_t coins_count{0};
46 
48  bool index_requested{true};
50  bool index_used{false};
51 
52  // Following values are only available from coinstats index
53 
72 
73  CCoinsStats(CoinStatsHashType hash_type) : m_hash_type(hash_type) {}
74 };
75 
77 bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr);
78 
79 uint64_t GetBogoSize(const CScript& script_pub_key);
80 
81 CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
82 } // namespace node
83 
84 #endif // BITCOIN_NODE_COINSTATS_H
node::GetUTXOStats
static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point, const CBlockIndex *pindex)
Calculate statistics about the unspent transaction output set.
Definition: coinstats.cpp:96
node::CCoinsStats::CCoinsStats
CCoinsStats(CoinStatsHashType hash_type)
Definition: coinstats.h:73
node::CCoinsStats
Definition: coinstats.h:30
streams.h
node::CCoinsStats::hashSerialized
uint256 hashSerialized
Definition: coinstats.h:39
node::CCoinsStats::index_requested
bool index_requested
Signals if the coinstatsindex should be used (when available).
Definition: coinstats.h:48
node::CCoinsStats::nTransactionOutputs
uint64_t nTransactionOutputs
Definition: coinstats.h:37
uint256.h
node::CCoinsStats::total_prevout_spent_amount
CAmount total_prevout_spent_amount
Total cumulative amount of prevouts spent up to and including this block.
Definition: coinstats.h:59
node::CoinStatsHashType::HASH_SERIALIZED
@ HASH_SERIALIZED
node::CCoinsStats::total_amount
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
Definition: coinstats.h:42
node::CCoinsStats::nHeight
int nHeight
Definition: coinstats.h:34
node::CCoinsStats::total_unspendables_unclaimed_rewards
CAmount total_unspendables_unclaimed_rewards
Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block.
Definition: coinstats.h:71
node::CoinStatsHashType::NONE
@ NONE
node::CCoinsStats::nBogoSize
uint64_t nBogoSize
Definition: coinstats.h:38
node::CCoinsStats::coins_count
uint64_t coins_count
The number of coins contained.
Definition: coinstats.h:45
node::TxOutSer
CDataStream TxOutSer(const COutPoint &outpoint, const Coin &coin)
Definition: coinstats.cpp:32
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:157
node::CCoinsStats::nDiskSize
uint64_t nDiskSize
Definition: coinstats.h:40
node::BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:65
node::CCoinsStats::total_unspendables_scripts
CAmount total_unspendables_scripts
Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and incl...
Definition: coinstats.h:69
Coin
A UTXO entry.
Definition: coins.h:30
node::CCoinsStats::nTransactions
uint64_t nTransactions
Definition: coinstats.h:36
node::CCoinsStats::total_unspendable_amount
CAmount total_unspendable_amount
Total cumulative amount of unspendable coins up to and including this block.
Definition: coinstats.h:57
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
node::CoinStatsHashType
CoinStatsHashType
Definition: coinstats.h:24
node::CCoinsStats::total_coinbase_amount
CAmount total_coinbase_amount
Total cumulative amount of coinbase outputs up to and including this block.
Definition: coinstats.h:63
uint256
256-bit opaque blob.
Definition: uint256.h:124
node::CCoinsStats::total_unspendables_genesis_block
CAmount total_unspendables_genesis_block
The unspendable coinbase amount from the genesis block.
Definition: coinstats.h:65
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
coins.h
node::CCoinsStats::total_subsidy
CAmount total_subsidy
Total cumulative amount of block subsidies up to and including this block.
Definition: coinstats.h:55
node::CCoinsStats::m_hash_type
const CoinStatsHashType m_hash_type
Which hash type to use.
Definition: coinstats.h:32
node::CCoinsStats::total_unspendables_bip30
CAmount total_unspendables_bip30
The two unspendable coinbase outputs total amount caused by BIP30.
Definition: coinstats.h:67
node::CoinStatsHashType::MUHASH
@ MUHASH
node::CCoinsStats::total_new_outputs_ex_coinbase_amount
CAmount total_new_outputs_ex_coinbase_amount
Total cumulative amount of outputs created up to and including this block.
Definition: coinstats.h:61
node::GetBogoSize
uint64_t GetBogoSize(const CScript &script_pub_key)
Definition: coinstats.cpp:22
node::CCoinsStats::hashBlock
uint256 hashBlock
Definition: coinstats.h:35
node
Definition: init.h:22
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:184
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:148
amount.h
node::CCoinsStats::index_used
bool index_used
Signals if the coinstatsindex was used to retrieve the statistics.
Definition: coinstats.h:50