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) 2017-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_RPC_BLOCKCHAIN_H6#define BITCOIN_RPC_BLOCKCHAIN_H8#include <consensus/amount.h>9#include <sync.h>10#include <util/fs.h>11#include <validation.h>13#include <cstdint>14#include <optional>15#include <utility>16#include <vector>18class CBlock;19class CBlockIndex;20class CChain;21class UniValue;22class AutoFile;23class uint256;24enum class TxVerbosity;26namespace node {27class BlockManager;28struct NodeContext;29} // namespace node31inline constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;33/**34* Get the difficulty of the net wrt to the given block index.35*36* @return A floating point number that is a multiple of the main net minimum37* difficulty (4295032833 hashes).38*/39double GetDifficulty(const CBlockIndex& blockindex);41/** Block description to JSON */42UniValue blockToJSON(node::BlockManager& blockman, const CBlock& block, const CBlockIndex& tip, const CBlockIndex& blockindex, TxVerbosity verbosity, uint256 pow_limit) LOCKS_EXCLUDED(cs_main);44/** Block header to JSON */45UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, uint256 pow_limit) LOCKS_EXCLUDED(cs_main);47/** Used by getblockstats to get feerates at different percentiles by weight */48void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);50/**51* Helper to create UTXO snapshots given a chainstate and a file handle.52* @return a UniValue map containing metadata about the snapshot.53*/54UniValue CreateUTXOSnapshot(55node::NodeContext& node,56Chainstate& chainstate,57AutoFile&& afile,58const fs::path& path,59const fs::path& tmppath);61//! Return height of highest block that has been pruned, or std::nullopt if no blocks have been pruned62std::optional<int> GetPruneHeight(const node::BlockManager& blockman, const CChain& chain) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);63void CheckBlockDataAvailability(node::BlockManager& blockman, const CBlockIndex& blockindex, bool check_for_undo) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);65#endif // BITCOIN_RPC_BLOCKCHAIN_H