Bitcoin ABC 0.31.1
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <kernel/coinstats.h>
13
14struct Amount;
15
16static constexpr bool DEFAULT_COINSTATSINDEX{false};
17
21class CoinStatsIndex final : public BaseIndex {
22private:
23 std::unique_ptr<BaseIndex::DB> m_db;
24
27 uint64_t m_bogo_size{0};
38
39 bool ReverseBlock(const CBlock &block, const CBlockIndex *pindex);
40
41 bool AllowPrune() const override { return true; }
42
43protected:
44 bool CustomInit(const std::optional<interfaces::BlockKey> &block) override;
45
46 bool CustomCommit(CDBBatch &batch) override;
47
48 bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override;
49
50 bool Rewind(const CBlockIndex *current_tip,
51 const CBlockIndex *new_tip) override;
52
53 BaseIndex::DB &GetDB() const override { return *m_db; }
54
55public:
56 // Constructs the index, which becomes available to be queried.
57 explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain,
58 size_t n_cache_size, bool f_memory = false,
59 bool f_wipe = false);
60
61 // Look up stats for a specific block using CBlockIndex
62 std::optional<kernel::CCoinsStats>
63 LookUpStats(const CBlockIndex *block_index) const;
64};
65
67extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
68
69#endif // BITCOIN_INDEX_COINSTATSINDEX_H
The database stores a block locator of the chain the database is synced to so that the TxIndex can ef...
Definition: base.h:46
Base class for indices of blockchain data.
Definition: base.h:37
Definition: block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:78
CoinStatsIndex maintains statistics on the UTXO set.
Amount m_total_amount
Amount m_total_prevout_spent_amount
Amount m_total_unspendables_bip30
bool AllowPrune() const override
Amount m_total_unspendables_genesis_block
CoinStatsIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
uint64_t m_bogo_size
uint64_t m_transaction_output_count
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
Amount m_total_coinbase_amount
bool ReverseBlock(const CBlock &block, const CBlockIndex *pindex)
MuHash3072 m_muhash
std::unique_ptr< BaseIndex::DB > m_db
std::optional< kernel::CCoinsStats > LookUpStats(const CBlockIndex *block_index) const
bool CustomCommit(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
Amount m_total_unspendables_scripts
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
bool CustomInit(const std::optional< interfaces::BlockKey > &block) override
Initialize internal state from the database and block index.
Amount m_total_new_outputs_ex_coinbase_amount
Amount m_total_unspendable_amount
Amount m_total_unspendables_unclaimed_rewards
BaseIndex::DB & GetDB() const override
Amount m_total_subsidy
A class representing MuHash sets.
Definition: muhash.h:96
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
static constexpr bool DEFAULT_COINSTATSINDEX
Definition: amount.h:19
static constexpr Amount zero() noexcept
Definition: amount.h:32