Line data Source code
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 <chain.h> 9 : #include <coins.h> 10 : #include <consensus/amount.h> 11 : #include <streams.h> 12 : #include <uint256.h> 13 : 14 : #include <cstdint> 15 : #include <functional> 16 : #include <optional> 17 : 18 : class CCoinsView; 19 : namespace node { 20 : class BlockManager; 21 : } // namespace node 22 : 23 : namespace kernel { 24 : enum class CoinStatsHashType : uint8_t { 25 : HASH_SERIALIZED, 26 : MUHASH, 27 : NONE, 28 : }; 29 : 30 : struct CCoinsStats { 31 0 : int nHeight{0}; 32 0 : uint256 hashBlock{}; 33 0 : uint64_t nTransactions{0}; 34 0 : uint64_t nTransactionOutputs{0}; 35 0 : uint64_t nBogoSize{0}; 36 0 : uint256 hashSerialized{}; 37 0 : uint64_t nDiskSize{0}; 38 : //! The total amount, or nullopt if an overflow occurred calculating it 39 0 : std::optional<CAmount> total_amount{0}; 40 : 41 : //! The number of coins contained. 42 0 : uint64_t coins_count{0}; 43 : 44 : //! Signals if the coinstatsindex was used to retrieve the statistics. 45 0 : bool index_used{false}; 46 : 47 : // Following values are only available from coinstats index 48 : 49 : //! Total cumulative amount of block subsidies up to and including this block 50 0 : CAmount total_subsidy{0}; 51 : //! Total cumulative amount of unspendable coins up to and including this block 52 0 : CAmount total_unspendable_amount{0}; 53 : //! Total cumulative amount of prevouts spent up to and including this block 54 0 : CAmount total_prevout_spent_amount{0}; 55 : //! Total cumulative amount of outputs created up to and including this block 56 0 : CAmount total_new_outputs_ex_coinbase_amount{0}; 57 : //! Total cumulative amount of coinbase outputs up to and including this block 58 0 : CAmount total_coinbase_amount{0}; 59 : //! The unspendable coinbase amount from the genesis block 60 0 : CAmount total_unspendables_genesis_block{0}; 61 : //! The two unspendable coinbase outputs total amount caused by BIP30 62 0 : CAmount total_unspendables_bip30{0}; 63 : //! Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and including this block 64 0 : CAmount total_unspendables_scripts{0}; 65 : //! Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block 66 0 : CAmount total_unspendables_unclaimed_rewards{0}; 67 : 68 0 : CCoinsStats() = default; 69 : CCoinsStats(int block_height, const uint256& block_hash); 70 : }; 71 : 72 : uint64_t GetBogoSize(const CScript& script_pub_key); 73 : 74 : CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin); 75 : 76 : std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point = {}); 77 : } // namespace kernel 78 : 79 : #endif // BITCOIN_KERNEL_COINSTATS_H