7 #include <chainparams.h>
34 std::vector<std::shared_ptr<CBlock>>
ret{total_height};
36 for (
size_t height{0}; height < total_height; ++height) {
37 CBlock& block{*(
ret.at(height) = std::make_shared<CBlock>())};
40 coinbase_tx.
vin.resize(1);
41 coinbase_tx.
vin[0].prevout.SetNull();
42 coinbase_tx.
vout.resize(1);
49 block.hashPrevBlock = (height >= 1 ? *
ret.at(height - 1) : params.
GenesisBlock()).GetHash();
73 std::optional<BlockValidationState>
m_state;
95 const auto old_height =
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight());
98 node.validation_signals->RegisterValidationInterface(&bvsc);
99 const bool processed{chainman.ProcessNewBlock(block,
true,
true, &new_block)};
100 const bool duplicate{!new_block && processed};
102 node.validation_signals->UnregisterValidationInterface(&bvsc);
103 node.validation_signals->SyncWithValidationInterfaceQueue();
104 const bool was_valid{bvsc.m_state && bvsc.m_state->IsValid()};
105 assert(old_height + was_valid ==
WITH_LOCK(chainman.GetMutex(),
return chainman.ActiveHeight()));
107 if (was_valid)
return {block->vtx[0]->GetHash(), 0};
112 const BlockAssembler::Options& assembler_options)
114 auto block = std::make_shared<CBlock>(
116 .CreateNewBlock(coinbase_scriptPubKey)
120 block->nTime =
Assert(
node.chainman)->ActiveChain().Tip()->GetMedianTimePast() + 1;
127 BlockAssembler::Options assembler_options;
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 Consensus::Params & GetConsensus() const
const CBlock & GenesisBlock() 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.
COutPoint MineBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey)
Returns the generated coin.
std::vector< std::shared_ptr< CBlock > > CreateBlockChain(size_t total_height, const CChainParams ¶ms)
Create a blockchain, starting from genesis.
std::shared_ptr< CBlock > PrepareBlock(const NodeContext &node, const CScript &coinbase_scriptPubKey, const BlockAssembler::Options &assembler_options)
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)