9#include <chainparams.h>
45 std::vector<std::shared_ptr<CBlock>>
ret{total_height};
48 for (
size_t height{0}; height < total_height; ++height) {
49 CBlock& block{*(
ret.at(height) = std::make_shared<CBlock>())};
52 coinbase_tx.
nLockTime =
static_cast<uint32_t
>(height);
53 coinbase_tx.
vin.resize(1);
54 coinbase_tx.
vin[0].prevout.SetNull();
56 coinbase_tx.
vout.resize(1);
64 block.hashPrevBlock = (height >= 1 ? *
ret.at(height - 1) : params.
GenesisBlock()).GetHash();
88 std::optional<BlockValidationState>
m_state;
97 if (block->GetHash() !=
m_hash)
return;
115 const auto old_height =
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight());
118 node.validation_signals->RegisterValidationInterface(&bvsc);
119 const bool processed{chainman.ProcessNewBlock(block,
true,
true, &new_block)};
120 const bool duplicate{!new_block && processed};
122 node.validation_signals->UnregisterValidationInterface(&bvsc);
123 node.validation_signals->SyncWithValidationInterfaceQueue();
124 const bool was_valid{bvsc.m_state && bvsc.m_state->IsValid()};
125 assert(old_height + was_valid ==
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight()));
127 if (was_valid)
return {block->vtx[0]->GetHash(), 0};
135 auto block_template = mining->createNewBlock(assembler_options,
false);
136 auto block = std::make_shared<CBlock>(
Assert(block_template)->getBlock());
139 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.
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.
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
Implement this to subscribe to events generated in validation and mempool.
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)
std::unique_ptr< Mining > MakeMining(const node::NodeContext &node, bool wait_loaded=true)
Return implementation of Mining interface.
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)
void BlockChecked(const std::shared_ptr< const CBlock > &block, const BlockValidationState &state) override
Notifies listeners of a block validation result.
BlockValidationStateCatcher(const uint256 &hash)
std::optional< BlockValidationState > m_state
A mutable version of CTransaction.
std::vector< CTxOut > vout
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 generatetoaddress(const NodeContext &node, const std::string &address)
RPC-like helper function, returns the generated coin.
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.
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
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)