Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2022-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_KERNEL_COINSTATS_H6#define BITCOIN_KERNEL_COINSTATS_H8#include <arith_uint256.h>9#include <consensus/amount.h>10#include <uint256.h>12#include <cstdint>13#include <functional>14#include <optional>16class CCoinsViewDB;17class Coin;18class COutPoint;19class CScript;20class MuHash3072;21namespace node {22class BlockManager;23} // namespace node25namespace kernel {26enum class CoinStatsHashType {27HASH_SERIALIZED,28MUHASH,29NONE,30};32struct CCoinsStats {33int nHeight{0};34uint256 hashBlock{};35uint64_t nTransactions{0};36uint64_t nTransactionOutputs{0};37uint64_t nBogoSize{0};38uint256 hashSerialized{};39uint64_t nDiskSize{0};40//! The total amount, or nullopt if an overflow occurred calculating it41std::optional<CAmount> total_amount{0};43//! The number of coins contained.44uint64_t coins_count{0};46//! Signals if the coinstatsindex was used to retrieve the statistics.47bool index_used{false};49// Following values are only available from coinstats index51//! Total cumulative amount of block subsidies up to and including this block52CAmount total_subsidy{0};53//! The unspendable coinbase amount from the genesis block54CAmount total_unspendables_genesis_block{0};55//! The two unspendable coinbase outputs total amount caused by BIP3056CAmount total_unspendables_bip30{0};57//! Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and including this block58CAmount total_unspendables_scripts{0};59//! Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block60CAmount total_unspendables_unclaimed_rewards{0};62// Despite containing amounts the following values use a uint256 type to prevent overflowing64//! Total cumulative amount of prevouts spent up to and including this block65arith_uint256 total_prevout_spent_amount{0};66//! Total cumulative amount of outputs created up to and including this block67arith_uint256 total_new_outputs_ex_coinbase_amount{0};68//! Total cumulative amount of coinbase outputs up to and including this block69arith_uint256 total_coinbase_amount{0};71CCoinsStats() = default;72CCoinsStats(int block_height, const uint256& block_hash);73};75uint64_t GetBogoSize(const CScript& script_pub_key);77void ApplyCoinHash(MuHash3072& muhash, const COutPoint& outpoint, const Coin& coin);78void RemoveCoinHash(MuHash3072& muhash, const COutPoint& outpoint, const Coin& coin);80std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, const CCoinsViewDB& view, node::BlockManager& blockman, const std::function<void()>& interruption_point = {});81} // namespace kernel83#endif // BITCOIN_KERNEL_COINSTATS_H