MCPcopy Create free account
hub / github.com/ElementsProject/elements / GenerateCoinbaseCommitment

Function GenerateCoinbaseCommitment

src/validation.cpp:3657–3695  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3655}
3656
3657std::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

Callers 3

FinalizeBlockMethod · 0.85
RegenerateCommitmentsFunction · 0.85
CreateNewBlockMethod · 0.85

Calls 12

BlockWitnessMerkleRootFunction · 0.85
CHash256Class · 0.85
CTxOutClass · 0.50
MakeTransactionRefFunction · 0.50
push_backMethod · 0.45
FinalizeMethod · 0.45
WriteMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

FinalizeBlockMethod · 0.68