MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / BuildMerkleTree

Method BuildMerkleTree

src/persistence/block.cpp:27–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27uint256 CBlock::BuildMerkleTree() const {
28 vMerkleTree.clear();
29 for (const auto& ptx : vptx) {
30 vMerkleTree.push_back(ptx->GetHash());
31 }
32 int32_t j = 0;
33 for (int32_t nSize = vptx.size(); nSize > 1; nSize = (nSize + 1) / 2) {
34 for (int32_t i = 0; i < nSize; i += 2) {
35 int32_t i2 = min(i + 1, nSize - 1);
36 vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j + i]), END(vMerkleTree[j + i]),
37 BEGIN(vMerkleTree[j + i2]), END(vMerkleTree[j + i2])));
38 }
39 j += nSize;
40 }
41 return (vMerkleTree.empty() ? uint256() : vMerkleTree.back());
42}
43
44vector<uint256> CBlock::GetMerkleBranch(int32_t index) const {
45 if (vMerkleTree.empty())

Callers 12

AppInitFunction · 0.80
CheckBlockFunction · 0.80
ProcessBlockFunction · 0.80
GetTxIndexInBlockMethod · 0.80
IsTxInTipBlockMethod · 0.80
getcontractregidFunction · 0.80
GetTxDetailJSONFunction · 0.80
CreateBlockRewardTxFunction · 0.80
VerifyRewardTxFunction · 0.80
CMainParamsMethod · 0.80
CTestNetParamsMethod · 0.80
CRegTestParamsMethod · 0.80

Calls 8

push_backMethod · 0.80
backMethod · 0.80
uint256Class · 0.70
HashFunction · 0.50
clearMethod · 0.45
GetHashMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by 2

GetTxIndexInBlockMethod · 0.64
IsTxInTipBlockMethod · 0.64