MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Block

Method Block

src/test/validation_block_tests.cpp:78–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76};
77
78std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
79{
80 static int i = 0;
81 static uint64_t time = Params().GenesisBlock().nTime;
82
83 auto mining{interfaces::MakeMining(m_node)};
84 auto block_template{mining->createNewBlock({
85 .coinbase_output_script = CScript{} << i++ << OP_TRUE,
86 }, /*cooldown=*/false)};
87 BOOST_REQUIRE(block_template);
88 auto pblock = std::make_shared<CBlock>(block_template->getBlock());
89 pblock->hashPrevBlock = prev_hash;
90 pblock->nTime = ++time;
91
92 // Make the coinbase transaction with two outputs:
93 // One zero-value one that has a unique pubkey to make sure that blocks at the same height can have a different hash
94 // Another one that has the coinbase reward in a P2WSH with OP_TRUE as witness program to make it easy to spend
95 CMutableTransaction txCoinbase(*pblock->vtx[0]);
96 txCoinbase.vout.resize(2);
97 txCoinbase.vout[1].scriptPubKey = P2WSH_OP_TRUE;
98 txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue;
99 txCoinbase.vout[0].nValue = 0;
100 txCoinbase.vin[0].scriptWitness.SetNull();
101 // Always pad with OP_0 as dummy extraNonce (also avoids bad-cb-length error for block <=16)
102 const int prev_height{WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(prev_hash)->nHeight)};
103 txCoinbase.vin[0].scriptSig = CScript{} << prev_height + 1 << OP_0;
104 txCoinbase.nLockTime = static_cast<uint32_t>(prev_height);
105 pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
106
107 return pblock;
108}
109
110std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock> pblock)
111{

Callers

nothing calls this directly

Calls 7

MakeMiningFunction · 0.85
MakeTransactionRefFunction · 0.85
createNewBlockMethod · 0.80
getBlockMethod · 0.80
ParamsClass · 0.50
resizeMethod · 0.45
SetNullMethod · 0.45

Tested by

no test coverage detected