Inside Bitcoin
Opening the selected file…
Inside Bitcoin
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) 2019-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_TEST_UTIL_MINING_H6#define BITCOIN_TEST_UTIL_MINING_H8#include <cstddef>9#include <memory>10#include <string>11#include <vector>13class CBlock;14class CBlockIndex;15class CChainParams;16class COutPoint;17class CScript;18namespace node {19struct BlockCreateOptions;20struct NodeContext;21} // namespace node23/** Create a blockchain, starting from genesis */24std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const CChainParams& params);26/**27* Build a chain of `length` coinbase-only blocks on top of `pindex` (which need28* not be the active tip, allowing forks to be created) and submit their headers.29* The blocks themselves are returned in `chain` for the caller to process.30*/31bool BuildChain(const node::NodeContext& node, const CBlockIndex* pindex, const CScript& coinbase_script_pub_key, size_t length, std::vector<std::shared_ptr<CBlock>>& chain);33/** Returns the generated coin */34COutPoint MineBlock(const node::NodeContext&,35const node::BlockCreateOptions& assembler_options);37/**38* Returns the generated coin (or Null if the block was invalid).39* It is recommended to call RegenerateCommitments before mining the block to avoid merkle tree mismatches.40**/41COutPoint MineBlock(const node::NodeContext&, std::shared_ptr<CBlock>& block);43/**44* Returns the generated coin (or Null if the block was invalid).45*/46COutPoint ProcessBlock(const node::NodeContext&, const std::shared_ptr<CBlock>& block);48/** Prepare a block to be mined */49std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext& node,50const node::BlockCreateOptions& assembler_options);52/** RPC-like helper function, returns the generated coin */53COutPoint generatetoaddress(const node::NodeContext&, const std::string& address);55#endif // BITCOIN_TEST_UTIL_MINING_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.