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

Function FetchAndClearCommitmentSection

src/signet.cpp:32–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30static constexpr script_verify_flags BLOCK_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_NULLDUMMY;
31
32static bool FetchAndClearCommitmentSection(const std::span<const uint8_t> header, CScript& witness_commitment, std::vector<uint8_t>& result)
33{
34 CScript replacement;
35 bool found_header = false;
36 result.clear();
37
38 opcodetype opcode;
39 CScript::const_iterator pc = witness_commitment.begin();
40 std::vector<uint8_t> pushdata;
41 while (witness_commitment.GetOp(pc, opcode, pushdata)) {
42 if (pushdata.size() > 0) {
43 if (!found_header && pushdata.size() > header.size() && std::ranges::equal(std::span{pushdata}.first(header.size()), header)) {
44 // pushdata only counts if it has the header _and_ some data
45 result.insert(result.end(), pushdata.begin() + header.size(), pushdata.end());
46 pushdata.erase(pushdata.begin() + header.size(), pushdata.end());
47 found_header = true;
48 }
49 replacement << pushdata;
50 } else {
51 replacement << opcode;
52 }
53 }
54
55 if (found_header) witness_commitment = replacement;
56 return found_header;
57}
58
59static uint256 ComputeModifiedMerkleRoot(const CMutableTransaction& cb, const CBlock& block)
60{

Callers 1

CreateMethod · 0.85

Calls 7

GetOpMethod · 0.80
clearMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected