@@ -84,8 +84,9 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
8484}
8585
8686/* 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 ();
8990 if (leaves.size () == 0 ) {
9091 if (pmutated) *pmutated = false ;
9192 if (proot) *proot = uint256 ();
@@ -105,18 +106,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
105106 // First process all leaves into 'inner' values.
106107 while (count < leaves.size ()) {
107108 uint256 h = leaves[count];
108- bool matchh = count == branchpos ;
109+ bool matchh = count == leaf_pos ;
109110 count++;
110111 int level;
111112 // For each of the lower bits in count that are 0, do 1 step. Each
112113 // corresponds to an inner value that existed before processing the
113114 // current leaf, and each needs a hash to combine it.
114115 for (level = 0 ; !(count & ((uint32_t {1 }) << level)); level++) {
115- if (pbranch ) {
116+ if (path ) {
116117 if (matchh) {
117- pbranch ->push_back (inner[level]);
118+ path ->push_back (inner[level]);
118119 } else if (matchlevel == level) {
119- pbranch ->push_back (h);
120+ path ->push_back (h);
120121 matchh = true ;
121122 }
122123 }
@@ -144,8 +145,8 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
144145 // If we reach this point, h is an inner value that is not the top.
145146 // We combine it with itself (Bitcoin's special rule for odd levels in
146147 // 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);
149150 }
150151 h = Hash (h, h);
151152 // 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
154155 level++;
155156 // And propagate the result upwards accordingly.
156157 while (!(count & ((uint32_t {1 }) << level))) {
157- if (pbranch ) {
158+ if (path ) {
158159 if (matchh) {
159- pbranch ->push_back (inner[level]);
160+ path ->push_back (inner[level]);
160161 } else if (matchlevel == level) {
161- pbranch ->push_back (h);
162+ path ->push_back (h);
162163 matchh = true ;
163164 }
164165 }
@@ -171,18 +172,18 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
171172 if (proot) *proot = h;
172173}
173174
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) {
175176 std::vector<uint256> ret;
176177 MerkleComputation (leaves, nullptr , nullptr , position, &ret);
177178 return ret;
178179}
179180
180- std::vector<uint256> BlockMerkleBranch (const CBlock& block, uint32_t position)
181+ std::vector<uint256> TransactionMerklePath (const CBlock& block, uint32_t position)
181182{
182183 std::vector<uint256> leaves;
183184 leaves.resize (block.vtx .size ());
184185 for (size_t s = 0 ; s < block.vtx .size (); s++) {
185186 leaves[s] = block.vtx [s]->GetHash ();
186187 }
187- return ComputeMerkleBranch (leaves, position);
188+ return ComputeMerklePath (leaves, position);
188189}
0 commit comments