9#include <chainparams.h>
50 for (
size_t height{0}; height <
total_height; ++height) {
51 CBlock& block{*(
ret.at(height) = std::make_shared<CBlock>())};
68 block.hashPrevBlock = (height >= 1 ? *
ret.at(height - 1) : params.
GenesisBlock()).GetHash();
85 std::vector<std::shared_ptr<CBlock>>& chain)
87 auto& block_template_manager{*
Assert(
node.block_template_manager)};
101 block.nTime = pindex->
nTime + 1;
110 while (!
CheckProofOfWork(block.GetHash(), block.nBits, consensus)) ++block.nNonce;
112 chain_block = std::make_shared<CBlock>(std::move(block));
115 if (!
Assert(
node.chainman)->ProcessNewBlockHeaders({{*chain_block}},
true, state, &pindex)) {
147 node.validation_signals->RegisterValidationInterface(&
bvsc);
151 node.validation_signals->UnregisterValidationInterface(&
bvsc);
152 node.validation_signals->SyncWithValidationInterfaceQueue();
156 if (
was_valid)
return {block->vtx[0]->GetHash(), 0};
163 auto& block_template_manager = *
Assert(
node.block_template_manager);
168 block->nTime =
Assert(
node.chainman)->ActiveChain().Tip()->GetMedianTimePast() + 1;
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const CBlock & GenesisBlock() const
const Consensus::Params & GetConsensus() const
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
An input of a transaction.
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
An output of a transaction.
Captures the validation state reported for a specific block.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
static RPCMethod generatetoaddress()
A mutable version of CTransaction.
Parameters that influence chain consensus.
Block template creation options.
NodeContext struct containing references to chain state and connection state.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const node::BlockCreateOptions &assembler_options)
Prepare a block to be mined.
COutPoint ProcessBlock(const NodeContext &node, const std::shared_ptr< CBlock > &block)
Returns the generated coin (or Null if the block was invalid).
COutPoint MineBlock(const NodeContext &node, const node::BlockCreateOptions &assembler_options)
Returns the generated coin.
bool BuildChain(const NodeContext &node, const CBlockIndex *pindex, const CScript &coinbase_script_pub_key, size_t length, std::vector< std::shared_ptr< CBlock > > &chain)
Build a chain of length coinbase-only blocks on top of pindex (which need not be the active tip,...
std::vector< std::shared_ptr< CBlock > > CreateBlockChain(size_t total_height, const CChainParams ¶ms)
Create a blockchain, starting from genesis.
static const CScript P2WSH_OP_TRUE
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
constexpr int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)