| 29 | } |
| 30 | |
| 31 | std::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 | |
| 62 | CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) |
| 63 | { |
no test coverage detected