@@ -84,8 +84,9 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
84
84
}
85
85
86
86
/* This implements a constant-space merkle root/path calculator, limited to 2^32 leaves. */
87
- static void MerkleComputation (const std::vector<uint256>& leaves, uint256* proot, bool * pmutated, uint32_t branchpos, std::vector<uint256>* pbranch) {
88
- if (pbranch) pbranch->clear ();
87
+ static void MerkleComputation (const std::vector<uint256>& leaves, uint256* proot, bool * pmutated, uint32_t leaf_pos, std::vector<uint256>* path)
88
+ {
89
+ if (path) path->clear ();
89
90
if (leaves.size () == 0 ) {
90
91
if (pmutated) *pmutated = false ;
91
92
if (proot) *proot = uint256 ();
@@ -105,18 +106,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
105
106
// First process all leaves into 'inner' values.
106
107
while (count < leaves.size ()) {
107
108
uint256 h = leaves[count];
108
- bool matchh = count == branchpos ;
109
+ bool matchh = count == leaf_pos ;
109
110
count++;
110
111
int level;
111
112
// For each of the lower bits in count that are 0, do 1 step. Each
112
113
// corresponds to an inner value that existed before processing the
113
114
// current leaf, and each needs a hash to combine it.
114
115
for (level = 0 ; !(count & ((uint32_t {1 }) << level)); level++) {
115
- if (pbranch ) {
116
+ if (path ) {
116
117
if (matchh) {
117
- pbranch ->push_back (inner[level]);
118
+ path ->push_back (inner[level]);
118
119
} else if (matchlevel == level) {
119
- pbranch ->push_back (h);
120
+ path ->push_back (h);
120
121
matchh = true ;
121
122
}
122
123
}
@@ -144,8 +145,8 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
144
145
// If we reach this point, h is an inner value that is not the top.
145
146
// We combine it with itself (Bitcoin's special rule for odd levels in
146
147
// the tree) to produce a higher level one.
147
- if (pbranch && matchh) {
148
- pbranch ->push_back (h);
148
+ if (path && matchh) {
149
+ path ->push_back (h);
149
150
}
150
151
h = Hash (h, h);
151
152
// Increment count to the value it would have if two entries at this
@@ -154,11 +155,11 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
154
155
level++;
155
156
// And propagate the result upwards accordingly.
156
157
while (!(count & ((uint32_t {1 }) << level))) {
157
- if (pbranch ) {
158
+ if (path ) {
158
159
if (matchh) {
159
- pbranch ->push_back (inner[level]);
160
+ path ->push_back (inner[level]);
160
161
} else if (matchlevel == level) {
161
- pbranch ->push_back (h);
162
+ path ->push_back (h);
162
163
matchh = true ;
163
164
}
164
165
}
@@ -171,18 +172,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
171
172
if (proot) *proot = h;
172
173
}
173
174
174
- static std::vector<uint256> ComputeMerkleBranch (const std::vector<uint256>& leaves, uint32_t position) {
175
+ static std::vector<uint256> ComputeMerklePath (const std::vector<uint256>& leaves, uint32_t position) {
175
176
std::vector<uint256> ret;
176
177
MerkleComputation (leaves, nullptr , nullptr , position, &ret);
177
178
return ret;
178
179
}
179
180
180
- std::vector<uint256> BlockMerkleBranch (const CBlock& block, uint32_t position)
181
+ std::vector<uint256> TransactionMerklePath (const CBlock& block, uint32_t position)
181
182
{
182
183
std::vector<uint256> leaves;
183
184
leaves.resize (block.vtx .size ());
184
185
for (size_t s = 0 ; s < block.vtx .size (); s++) {
185
186
leaves[s] = block.vtx [s]->GetHash ();
186
187
}
187
- return ComputeMerkleBranch (leaves, position);
188
+ return ComputeMerklePath (leaves, position);
188
189
}
0 commit comments