| 3655 | } |
| 3656 | |
| 3657 | std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams) |
| 3658 | { |
| 3659 | std::vector<unsigned char> commitment; |
| 3660 | int commitpos = GetWitnessCommitmentIndex(block); |
| 3661 | std::vector<unsigned char> ret(32, 0x00); |
| 3662 | if (commitpos == NO_WITNESS_COMMITMENT) { |
| 3663 | // ELEMENTS: Shim in blank coinbase output for witness output hash |
| 3664 | // Previous iterations of CA could have allowed witness data |
| 3665 | // in coinbase transactions, and this witness data must be committed |
| 3666 | // to here. |
| 3667 | // |
| 3668 | // Is No-op in Bitcoin |
| 3669 | CMutableTransaction tx0(*block.vtx[0]); |
| 3670 | tx0.vout.push_back(CTxOut()); |
| 3671 | block.vtx[0] = MakeTransactionRef(std::move(tx0)); |
| 3672 | // END |
| 3673 | uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr); |
| 3674 | CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot); |
| 3675 | CTxOut out; |
| 3676 | out.nValue = 0; |
| 3677 | out.nAsset = policyAsset; |
| 3678 | out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT); |
| 3679 | out.scriptPubKey[0] = OP_RETURN; |
| 3680 | out.scriptPubKey[1] = 0x24; |
| 3681 | out.scriptPubKey[2] = 0xaa; |
| 3682 | out.scriptPubKey[3] = 0x21; |
| 3683 | out.scriptPubKey[4] = 0xa9; |
| 3684 | out.scriptPubKey[5] = 0xed; |
| 3685 | memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32); |
| 3686 | commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end()); |
| 3687 | CMutableTransaction tx(*block.vtx[0]); |
| 3688 | // Elements: replace shimmed output with real coinbase rather than push |
| 3689 | tx.vout.back() = out; |
| 3690 | // END |
| 3691 | block.vtx[0] = MakeTransactionRef(std::move(tx)); |
| 3692 | } |
| 3693 | UpdateUncommittedBlockStructures(block, pindexPrev, consensusParams); |
| 3694 | return commitment; |
| 3695 | } |
| 3696 | |
| 3697 | // ELEMENTS |
| 3698 | |