| 3407 | } |
| 3408 | |
| 3409 | std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams) |
| 3410 | { |
| 3411 | std::vector<unsigned char> commitment; |
| 3412 | int commitpos = GetWitnessCommitmentIndex(block); |
| 3413 | std::vector<unsigned char> ret(32, 0x00); |
| 3414 | if (consensusParams.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) { |
| 3415 | if (commitpos == -1) { |
| 3416 | uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr); |
| 3417 | CHash256().Write(witnessroot.begin(), 32).Write(ret.data(), 32).Finalize(witnessroot.begin()); |
| 3418 | CTxOut out; |
| 3419 | out.nValue = 0; |
| 3420 | out.scriptPubKey.resize(38); |
| 3421 | out.scriptPubKey[0] = OP_RETURN; |
| 3422 | out.scriptPubKey[1] = 0x24; |
| 3423 | out.scriptPubKey[2] = 0xaa; |
| 3424 | out.scriptPubKey[3] = 0x21; |
| 3425 | out.scriptPubKey[4] = 0xa9; |
| 3426 | out.scriptPubKey[5] = 0xed; |
| 3427 | memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32); |
| 3428 | commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end()); |
| 3429 | CMutableTransaction tx(*block.vtx[0]); |
| 3430 | tx.vout.push_back(out); |
| 3431 | block.vtx[0] = MakeTransactionRef(std::move(tx)); |
| 3432 | } |
| 3433 | } |
| 3434 | UpdateUncommittedBlockStructures(block, pindexPrev, consensusParams); |
| 3435 | return commitment; |
| 3436 | } |
| 3437 | |
| 3438 | /** Context-dependent validity checks. |
| 3439 | * By "context", we mean only the previous block headers, but not the UTXO |
no test coverage detected