7#include <chainparams.h>
27 BlockAssembler::Options assembler_options;
35 std::vector<std::shared_ptr<CBlock>>
ret{total_height};
37 for (
size_t height{0}; height < total_height; ++height) {
38 CBlock& block{*(
ret.at(height) = std::make_shared<CBlock>())};
41 coinbase_tx.
vin.resize(1);
42 coinbase_tx.
vin[0].prevout.SetNull();
43 coinbase_tx.
vout.resize(1);
50 block.hashPrevBlock = (height >= 1 ? *
ret.at(height - 1) : params.
GenesisBlock()).GetHash();
74 std::optional<BlockValidationState>
m_state;
96 const auto old_height =
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight());
99 node.validation_signals->RegisterValidationInterface(&bvsc);
100 const bool processed{chainman.ProcessNewBlock(block,
true,
true, &new_block)};
101 const bool duplicate{!new_block && processed};
103 node.validation_signals->UnregisterValidationInterface(&bvsc);
104 node.validation_signals->SyncWithValidationInterfaceQueue();
105 const bool was_valid{bvsc.m_state && bvsc.m_state->IsValid()};
106 assert(old_height + was_valid ==
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight()));
108 if (was_valid)
return {block->vtx[0]->GetHash(), 0};
113 const BlockAssembler::Options& assembler_options)
115 auto block = std::make_shared<CBlock>(
121 block->nTime =
Assert(
node.chainman)->ActiveChain().Tip()->GetMedianTimePast() + 1;
128 BlockAssembler::Options assembler_options;
129 assembler_options.coinbase_output_script = coinbase_scriptPubKey;
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.
Implement this to subscribe to events generated in validation and mempool.
Generate a new block, without valid proof-of-work.
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)
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
util::Result< void > ApplyArgsManOptions(const ArgsManager &args, BlockManager::Options &opts)
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)
BlockValidationStateCatcher(const uint256 &hash)
std::optional< BlockValidationState > m_state
void BlockChecked(const CBlock &block, const BlockValidationState &state) override
Notifies listeners of a block validation result.
A mutable version of CTransaction.
std::vector< CTxOut > vout
NodeContext struct containing references to chain state and connection state.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
COutPoint generatetoaddress(const NodeContext &node, const std::string &address)
RPC-like helper function, returns the generated coin.
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const BlockAssembler::Options &assembler_options)
std::vector< std::shared_ptr< CBlock > > CreateBlockChain(size_t total_height, const CChainParams ¶ms)
Create a blockchain, starting from genesis.
COutPoint MineBlock(const NodeContext &node, const node::BlockAssembler::Options &assembler_options)
Returns the generated coin.
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)