Create a new block with just given transactions, coinbase paying to scriptPubKey, and try to add it to the current chain.
| 145 | // scriptPubKey, and try to add it to the current chain. |
| 146 | // |
| 147 | CBlock |
| 148 | TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey) |
| 149 | { |
| 150 | const CChainParams& chainparams = Params(); |
| 151 | std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey); |
| 152 | CBlock& block = pblocktemplate->block; |
| 153 | |
| 154 | // Replace mempool-selected txns with just coinbase plus passed-in txns: |
| 155 | block.vtx.resize(1); |
| 156 | for (const CMutableTransaction& tx : txns) |
| 157 | block.vtx.push_back(MakeTransactionRef(tx)); |
| 158 | // IncrementExtraNonce creates a valid coinbase and merkleRoot |
| 159 | { |
| 160 | LOCK(cs_main); |
| 161 | unsigned int extraNonce = 0; |
| 162 | IncrementExtraNonce(&block, chainActive.Tip(), extraNonce); |
| 163 | } |
| 164 | |
| 165 | // TODO(h4x3rotab): Generate Equihash solution if applicable. |
| 166 | while (!CheckProofOfWork(block.GetHash(), block.nBits, false, chainparams.GetConsensus())) { |
| 167 | block.nNonce = ArithToUint256(UintToArith256(block.nNonce) + 1); |
| 168 | } |
| 169 | |
| 170 | std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block); |
| 171 | ProcessNewBlock(chainparams, shared_pblock, true, nullptr); |
| 172 | |
| 173 | CBlock result = block; |
| 174 | return result; |
| 175 | } |
| 176 | |
| 177 | TestChain100Setup::~TestChain100Setup() |
| 178 | { |
no test coverage detected