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

Function GenerateCoinbaseCommitment

src/validation.cpp:3409–3436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3407}
3408
3409std::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

Callers 1

CreateNewBlockMethod · 0.85

Calls 13

BlockWitnessMerkleRootFunction · 0.85
CHash256Class · 0.85
memcpyFunction · 0.85
MakeTransactionRefFunction · 0.85
FinalizeMethod · 0.45
WriteMethod · 0.45
beginMethod · 0.45
dataMethod · 0.45
resizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected