MCPcopy Create free account
hub / github.com/ElementsProject/elements / CreateBlockChain

Function CreateBlockChain

src/test/util/mining.cpp:31–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31std::vector<std::shared_ptr<CBlock>> CreateBlockChain(size_t total_height, const CChainParams& params)
32{
33 std::vector<std::shared_ptr<CBlock>> ret{total_height};
34 auto time{params.GenesisBlock().nTime};
35 for (size_t height{0}; height < total_height; ++height) {
36 CBlock& block{*(ret.at(height) = std::make_shared<CBlock>())};
37
38 CMutableTransaction coinbase_tx;
39 coinbase_tx.vin.resize(1);
40 coinbase_tx.vin[0].prevout.SetNull();
41 coinbase_tx.vout.resize(1);
42 coinbase_tx.vout[0].scriptPubKey = P2WSH_OP_TRUE;
43 coinbase_tx.vout[0].nValue = GetBlockSubsidy(height + 1, params.GetConsensus());
44 coinbase_tx.vin[0].scriptSig = CScript() << (height + 1) << OP_0;
45 block.vtx = {MakeTransactionRef(std::move(coinbase_tx))};
46
47 block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
48 block.hashPrevBlock = (height >= 1 ? *ret.at(height - 1) : params.GenesisBlock()).GetHash();
49 block.hashMerkleRoot = BlockMerkleRoot(block);
50 block.nTime = ++time;
51 block.nBits = params.GenesisBlock().nBits;
52 block.nNonce = 0;
53
54 while (!CheckProofOfWork(block.GetHash(), block.nBits, params.GetConsensus())) {
55 ++block.nNonce;
56 assert(block.nNonce);
57 }
58 }
59 return ret;
60}
61
62CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
63{

Callers 1

initialize_chainFunction · 0.85

Calls 8

GetBlockSubsidyFunction · 0.85
BlockMerkleRootFunction · 0.85
CheckProofOfWorkFunction · 0.85
CScriptClass · 0.70
MakeTransactionRefFunction · 0.50
resizeMethod · 0.45
SetNullMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected