7#include <chainparams.h>
39 std::vector<std::shared_ptr<CBlock>>
ret{total_height};
42 for (
size_t height{0}; height < total_height; ++height) {
43 CBlock& block{*(
ret.at(height) = std::make_shared<CBlock>())};
46 coinbase_tx.
nLockTime =
static_cast<uint32_t
>(height);
47 coinbase_tx.
vin.resize(1);
48 coinbase_tx.
vin[0].prevout.SetNull();
50 coinbase_tx.
vout.resize(1);
82 std::optional<BlockValidationState>
m_state;
91 if (block->GetHash() !=
m_hash)
return;
109 const auto old_height =
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight());
112 node.validation_signals->RegisterValidationInterface(&bvsc);
113 const bool processed{chainman.ProcessNewBlock(block,
true,
true, &new_block)};
114 const bool duplicate{!new_block && processed};
116 node.validation_signals->UnregisterValidationInterface(&bvsc);
117 node.validation_signals->SyncWithValidationInterfaceQueue();
119 assert(old_height + was_valid ==
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight()));
121 if (was_valid)
return {block->vtx[0]->GetHash(), 0};
128 auto block = std::make_shared<CBlock>(
134 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.
std::vector< CTransactionRef > vtx
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.
Generate a new block, without valid proof-of-work.
std::unique_ptr< CBlockTemplate > CreateNewBlock()
Construct a new block template.
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)
util::Result< void > ApplyArgsManOptions(const ArgsManager &argsman, const CChainParams &chainparams, MemPoolOptions &mempool_opts)
Overlay the options set in argsman on top of corresponding members in mempool_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)
static RPCHelpMan generatetoaddress()
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
bool include_dummy_extranonce
Whether to include an OP_0 as a dummy extraNonce in the template's coinbase.
CScript coinbase_output_script
Script to put in the coinbase transaction.
#define WITH_LOCK(cs, code)
COutPoint ProcessBlock(const NodeContext &node, const std::shared_ptr< CBlock > &block)
Returns the generated coin (or Null if the block was invalid).
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).