Bitcoin Core  22.99.0
P2P Digital Currency
coinstatsindex.h
Go to the documentation of this file.
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 
17 class CoinStatsIndex final : public BaseIndex
18 {
19 private:
20  std::string m_name;
21  std::unique_ptr<BaseIndex::DB> m_db;
22 
25  uint64_t m_bogo_size{0};
36 
37  bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex);
38 
39 protected:
40  bool Init() override;
41 
42  bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) override;
43 
44  bool Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip) override;
45 
46  BaseIndex::DB& GetDB() const override { return *m_db; }
47 
48  const char* GetName() const override { return "coinstatsindex"; }
49 
50 public:
51  // Constructs the index, which becomes available to be queried.
52  explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
53 
54  // Look up stats for a specific block using CBlockIndex
55  bool LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const;
56 };
57 
59 extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
60 
61 #endif // BITCOIN_INDEX_COINSTATSINDEX_H
CoinStatsIndex::m_total_unspendable_amount
CAmount m_total_unspendable_amount
Definition: coinstatsindex.h:28
CoinStatsIndex::m_muhash
MuHash3072 m_muhash
Definition: coinstatsindex.h:23
CoinStatsIndex::m_total_unspendables_bip30
CAmount m_total_unspendables_bip30
Definition: coinstatsindex.h:33
CoinStatsIndex::GetName
const char * GetName() const override
Get the name of the index for display in logs.
Definition: coinstatsindex.h:48
CoinStatsIndex::WriteBlock
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Definition: coinstatsindex.cpp:106
flatfile.h
CCoinsStats
Definition: coinstats.h:27
CoinStatsIndex::m_total_unspendables_genesis_block
CAmount m_total_unspendables_genesis_block
Definition: coinstatsindex.h:32
CoinStatsIndex::m_bogo_size
uint64_t m_bogo_size
Definition: coinstatsindex.h:25
base.h
BaseIndex
Base class for indices of blockchain data.
Definition: base.h:27
CoinStatsIndex::m_db
std::unique_ptr< BaseIndex::DB > m_db
Definition: coinstatsindex.h:21
CoinStatsIndex::m_total_amount
CAmount m_total_amount
Definition: coinstatsindex.h:26
muhash.h
CoinStatsIndex::m_total_new_outputs_ex_coinbase_amount
CAmount m_total_new_outputs_ex_coinbase_amount
Definition: coinstatsindex.h:30
CoinStatsIndex::Rewind
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
Definition: coinstatsindex.cpp:257
CoinStatsIndex::m_total_subsidy
CAmount m_total_subsidy
Definition: coinstatsindex.h:27
CoinStatsIndex::GetDB
BaseIndex::DB & GetDB() const override
Definition: coinstatsindex.h:46
CoinStatsIndex::m_name
std::string m_name
Definition: coinstatsindex.h:20
CoinStatsIndex::Init
bool Init() override
Initialize internal state from the database and block index.
Definition: coinstatsindex.cpp:338
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
g_coin_stats_index
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
Definition: coinstatsindex.cpp:94
CoinStatsIndex::CoinStatsIndex
CoinStatsIndex(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Definition: coinstatsindex.cpp:98
coinstats.h
CBlock
Definition: block.h:62
CoinStatsIndex::m_total_unspendables_unclaimed_rewards
CAmount m_total_unspendables_unclaimed_rewards
Definition: coinstatsindex.h:35
CoinStatsIndex::m_total_unspendables_scripts
CAmount m_total_unspendables_scripts
Definition: coinstatsindex.h:34
BaseIndex::DB
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:37
CoinStatsIndex::m_total_coinbase_amount
CAmount m_total_coinbase_amount
Definition: coinstatsindex.h:31
CoinStatsIndex
CoinStatsIndex maintains statistics on the UTXO set.
Definition: coinstatsindex.h:17
CoinStatsIndex::ReverseBlock
bool ReverseBlock(const CBlock &block, const CBlockIndex *pindex)
Definition: coinstatsindex.cpp:378
CoinStatsIndex::m_transaction_output_count
uint64_t m_transaction_output_count
Definition: coinstatsindex.h:24
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
CoinStatsIndex::m_total_prevout_spent_amount
CAmount m_total_prevout_spent_amount
Definition: coinstatsindex.h:29
MuHash3072
A class representing MuHash sets.
Definition: muhash.h:94
CoinStatsIndex::LookUpStats
bool LookUpStats(const CBlockIndex *block_index, CCoinsStats &coins_stats) const
Definition: coinstatsindex.cpp:314