MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GenerateCoinbaseCommitment

Method GenerateCoinbaseCommitment

src/validation.cpp:4007–4029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4005}
4006
4007void ChainstateManager::GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const
4008{
4009 int commitpos = GetWitnessCommitmentIndex(block);
4010 std::vector<unsigned char> ret(32, 0x00);
4011 if (commitpos == NO_WITNESS_COMMITMENT) {
4012 uint256 witnessroot = BlockWitnessMerkleRoot(block);
4013 CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
4014 CTxOut out;
4015 out.nValue = 0;
4016 out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
4017 out.scriptPubKey[0] = OP_RETURN;
4018 out.scriptPubKey[1] = 0x24;
4019 out.scriptPubKey[2] = 0xaa;
4020 out.scriptPubKey[3] = 0x21;
4021 out.scriptPubKey[4] = 0xa9;
4022 out.scriptPubKey[5] = 0xed;
4023 memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32);
4024 CMutableTransaction tx(*block.vtx[0]);
4025 tx.vout.push_back(out);
4026 block.vtx[0] = MakeTransactionRef(std::move(tx));
4027 }
4028 UpdateUncommittedBlockStructures(block, pindexPrev);
4029}
4030
4031bool HasValidProofOfWork(std::span<const CBlockHeader> headers, const Consensus::Params& consensusParams)
4032{

Callers 4

FinalizeBlockMethod · 0.80
cmpctblock.cppFile · 0.80
RegenerateCommitmentsFunction · 0.80
CreateNewBlockMethod · 0.80

Calls 9

BlockWitnessMerkleRootFunction · 0.85
CHash256Class · 0.85
MakeTransactionRefFunction · 0.85
FinalizeMethod · 0.45
WriteMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
push_backMethod · 0.45

Tested by 1

FinalizeBlockMethod · 0.64