Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
coinstats.cpp
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-2019 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include <node/coinstats.h>
7
8#include <coins.h>
10#include <optional>
11#include <validation.h>
12
13namespace node {
14
15std::optional<kernel::CCoinsStats>
18 const std::function<void()> &interruption_point,
19 const CBlockIndex *pindex, bool index_requested) {
20 // Use CoinStatsIndex if it is requested and available and a hash_type of
21 // Muhash or None was requested
25 if (pindex) {
26 return g_coin_stats_index->LookUpStats(pindex);
27 } else {
30 return blockman.LookupBlockIndex(view->GetBestBlock()));
31 return g_coin_stats_index->LookUpStats(block_index);
32 }
33 }
34
35 // If the coinstats index isn't requested or is otherwise not usable, the
36 // pindex should either be null or equal to the view's best block. This is
37 // because without the coinstats index we can only get coinstats about the
38 // best block.
39 assert(!pindex || pindex->GetBlockHash() == view->GetBestBlock());
40
43}
44} // namespace node
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition blockindex.h:25
BlockHash GetBlockHash() const
Definition blockindex.h:146
Abstract view on the open txout dataset.
Definition coins.h:163
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:7
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:92
CoinStatsHashType
Definition coinstats.h:23
Definition init.h:28
std::optional< kernel::CCoinsStats > GetUTXOStats(CCoinsView *view, BlockManager &blockman, kernel::CoinStatsHashType hash_type, const std::function< void()> &interruption_point, const CBlockIndex *pindex, bool index_requested)
Calculate statistics about the unspent transaction output set.
Definition coinstats.cpp:16
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition sync.h:357
assert(!tx.IsCoinBase())