| 61 | }; |
| 62 | |
| 63 | std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash) |
| 64 | { |
| 65 | static int i = 0; |
| 66 | static uint64_t time = Params().GenesisBlock().nTime; |
| 67 | |
| 68 | auto ptemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), *m_node.mempool, Params()).CreateNewBlock(CScript{} << i++ << OP_TRUE); |
| 69 | auto pblock = std::make_shared<CBlock>(ptemplate->block); |
| 70 | pblock->hashPrevBlock = prev_hash; |
| 71 | pblock->nTime = ++time; |
| 72 | |
| 73 | // Make the coinbase transaction with two outputs: |
| 74 | // One zero-value one that has a unique pubkey to make sure that blocks at the same height can have a different hash |
| 75 | // Another one that has the coinbase reward in a P2WSH with OP_TRUE as witness program to make it easy to spend |
| 76 | CMutableTransaction txCoinbase(*pblock->vtx[0]); |
| 77 | txCoinbase.vout.resize(2); |
| 78 | txCoinbase.witness.vtxoutwit.resize(2); |
| 79 | txCoinbase.vout[1].scriptPubKey = P2WSH_OP_TRUE; |
| 80 | txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue; |
| 81 | txCoinbase.vout[0].nValue = 0; |
| 82 | txCoinbase.witness.vtxinwit.resize(1); |
| 83 | txCoinbase.witness.vtxinwit[0].scriptWitness.SetNull(); |
| 84 | // Always pad with OP_0 at the end to avoid bad-cb-length error |
| 85 | txCoinbase.vin[0].scriptSig = CScript{} << WITH_LOCK(::cs_main, return m_node.chainman->m_blockman.LookupBlockIndex(prev_hash)->nHeight + 1) << OP_0; |
| 86 | pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); |
| 87 | |
| 88 | return pblock; |
| 89 | } |
| 90 | |
| 91 | std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock> pblock) |
| 92 | { |
nothing calls this directly
no test coverage detected