Bitcoin Core  25.99.0
P2P Digital Currency
coinstats.h
Go to the documentation of this file.
1 // Copyright (c) 2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_KERNEL_COINSTATS_H
6 #define BITCOIN_KERNEL_COINSTATS_H
7 
8 #include <consensus/amount.h>
9 #include <streams.h>
10 #include <uint256.h>
11 
12 #include <cstdint>
13 #include <functional>
14 #include <optional>
15 
16 class CCoinsView;
17 class Coin;
18 class COutPoint;
19 class CScript;
20 namespace node {
21 class BlockManager;
22 } // namespace node
23 
24 namespace kernel {
25 enum class CoinStatsHashType {
27  MUHASH,
28  NONE,
29 };
30 
31 struct CCoinsStats {
32  int nHeight{0};
34  uint64_t nTransactions{0};
35  uint64_t nTransactionOutputs{0};
36  uint64_t nBogoSize{0};
38  uint64_t nDiskSize{0};
40  std::optional<CAmount> total_amount{0};
41 
43  uint64_t coins_count{0};
44 
46  bool index_used{false};
47 
48  // Following values are only available from coinstats index
49 
68 
69  CCoinsStats() = default;
70  CCoinsStats(int block_height, const uint256& block_hash);
71 };
72 
73 uint64_t GetBogoSize(const CScript& script_pub_key);
74 
75 DataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
76 
77 std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point = {});
78 } // namespace kernel
79 
80 #endif // BITCOIN_KERNEL_COINSTATS_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
Abstract view on the open txout dataset.
Definition: coins.h:174
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:411
A UTXO entry.
Definition: coins.h:32
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:186
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:79
256-bit opaque blob.
Definition: uint256.h:105
static bool ComputeUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point)
Calculate statistics about the unspent transaction output set.
Definition: coinstats.cpp:116
CoinStatsHashType
Definition: coinstats.h:25
DataStream TxOutSer(const COutPoint &outpoint, const Coin &coin)
Definition: coinstats.cpp:51
uint64_t GetBogoSize(const CScript &script_pub_key)
Definition: coinstats.cpp:41
Definition: init.h:25
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
Definition: coinstats.h:40
uint64_t nDiskSize
Definition: coinstats.h:38
CAmount total_unspendable_amount
Total cumulative amount of unspendable coins up to and including this block.
Definition: coinstats.h:53
CAmount total_unspendables_scripts
Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and incl...
Definition: coinstats.h:65
uint64_t coins_count
The number of coins contained.
Definition: coinstats.h:43
CAmount total_new_outputs_ex_coinbase_amount
Total cumulative amount of outputs created up to and including this block.
Definition: coinstats.h:57
uint64_t nTransactions
Definition: coinstats.h:34
uint64_t nTransactionOutputs
Definition: coinstats.h:35
CAmount total_coinbase_amount
Total cumulative amount of coinbase outputs up to and including this block.
Definition: coinstats.h:59
uint64_t nBogoSize
Definition: coinstats.h:36
bool index_used
Signals if the coinstatsindex was used to retrieve the statistics.
Definition: coinstats.h:46
CAmount total_unspendables_bip30
The two unspendable coinbase outputs total amount caused by BIP30.
Definition: coinstats.h:63
CAmount total_unspendables_genesis_block
The unspendable coinbase amount from the genesis block.
Definition: coinstats.h:61
CAmount total_prevout_spent_amount
Total cumulative amount of prevouts spent up to and including this block.
Definition: coinstats.h:55
uint256 hashSerialized
Definition: coinstats.h:37
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:67
CAmount total_subsidy
Total cumulative amount of block subsidies up to and including this block.
Definition: coinstats.h:51