Branch data Line data Source code
# 1 : : // Copyright (c) 2020-2021 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_INDEX_COINSTATSINDEX_H # 6 : : #define BITCOIN_INDEX_COINSTATSINDEX_H # 7 : : # 8 : : #include <chain.h> # 9 : : #include <crypto/muhash.h> # 10 : : #include <flatfile.h> # 11 : : #include <index/base.h> # 12 : : #include <node/coinstats.h> # 13 : : # 14 : : /** # 15 : : * CoinStatsIndex maintains statistics on the UTXO set. # 16 : : */ # 17 : : class CoinStatsIndex final : public BaseIndex # 18 : : { # 19 : : private: # 20 : : std::string m_name; # 21 : : std::unique_ptr<BaseIndex::DB> m_db; # 22 : : # 23 : : MuHash3072 m_muhash; # 24 : : uint64_t m_transaction_output_count{0}; # 25 : : uint64_t m_bogo_size{0}; # 26 : : CAmount m_total_amount{0}; # 27 : : CAmount m_total_subsidy{0}; # 28 : : CAmount m_total_unspendable_amount{0}; # 29 : : CAmount m_total_prevout_spent_amount{0}; # 30 : : CAmount m_total_new_outputs_ex_coinbase_amount{0}; # 31 : : CAmount m_total_coinbase_amount{0}; # 32 : : CAmount m_total_unspendables_genesis_block{0}; # 33 : : CAmount m_total_unspendables_bip30{0}; # 34 : : CAmount m_total_unspendables_scripts{0}; # 35 : : CAmount m_total_unspendables_unclaimed_rewards{0}; # 36 : : # 37 : : bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex); # 38 : : # 39 : : protected: # 40 : : bool Init() override; # 41 : : # 42 : : bool CommitInternal(CDBBatch& batch) override; # 43 : : # 44 : : bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override; # 45 : : # 46 : : bool Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip) override; # 47 : : # 48 : 208 : BaseIndex::DB& GetDB() const override { return *m_db; } # 49 : : # 50 : 354 : const char* GetName() const override { return "coinstatsindex"; } # 51 : : # 52 : : public: # 53 : : // Constructs the index, which becomes available to be queried. # 54 : : explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false); # 55 : : # 56 : : // Look up stats for a specific block using CBlockIndex # 57 : : bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const; # 58 : : }; # 59 : : # 60 : : /// The global UTXO set hash object. # 61 : : extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index; # 62 : : # 63 : : #endif // BITCOIN_INDEX_COINSTATSINDEX_H