@@ -15,7 +15,7 @@ uint256 CBlockHeader::GetHash() const
1515 return SerializeHash (*this );
1616}
1717
18- uint256 CBlock::BuildMerkleTree (bool * fMutated ) const
18+ uint256 CBlock::ComputeMerkleRoot (bool * fMutated ) const
1919{
2020 /* WARNING! If you're reading this because you're learning about crypto
2121 and/or designing a new system that will use merkle trees, keep in mind
@@ -52,7 +52,7 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
5252 known ways of changing the transactions without affecting the merkle
5353 root.
5454 */
55- vMerkleTree. clear () ;
55+ std::vector<uint256> vMerkleTree;
5656 vMerkleTree.reserve (vtx.size () * 2 + 16 ); // Safe upper bound for the number of total nodes.
5757 for (std::vector<CTransaction>::const_iterator it (vtx.begin ()); it != vtx.end (); ++it)
5858 vMerkleTree.push_back (it->GetHash ());
@@ -78,37 +78,6 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
7878 return (vMerkleTree.empty () ? uint256 () : vMerkleTree.back ());
7979}
8080
81- std::vector<uint256> CBlock::GetMerkleBranch (int nIndex) const
82- {
83- if (vMerkleTree.empty ())
84- BuildMerkleTree ();
85- std::vector<uint256> vMerkleBranch;
86- int j = 0 ;
87- for (int nSize = vtx.size (); nSize > 1 ; nSize = (nSize + 1 ) / 2 )
88- {
89- int i = std::min (nIndex^1 , nSize-1 );
90- vMerkleBranch.push_back (vMerkleTree[j+i]);
91- nIndex >>= 1 ;
92- j += nSize;
93- }
94- return vMerkleBranch;
95- }
96-
97- uint256 CBlock::CheckMerkleBranch (uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
98- {
99- if (nIndex == -1 )
100- return uint256 ();
101- for (std::vector<uint256>::const_iterator it (vMerkleBranch.begin ()); it != vMerkleBranch.end (); ++it)
102- {
103- if (nIndex & 1 )
104- hash = Hash (BEGIN (*it), END (*it), BEGIN (hash), END (hash));
105- else
106- hash = Hash (BEGIN (hash), END (hash), BEGIN (*it), END (*it));
107- nIndex >>= 1 ;
108- }
109- return hash;
110- }
111-
11281std::string CBlock::ToString () const
11382{
11483 std::stringstream s;
@@ -123,9 +92,5 @@ std::string CBlock::ToString() const
12392 {
12493 s << " " << vtx[i].ToString () << " \n " ;
12594 }
126- s << " vMerkleTree: " ;
127- for (unsigned int i = 0 ; i < vMerkleTree.size (); i++)
128- s << " " << vMerkleTree[i].ToString ();
129- s << " \n " ;
13095 return s.str ();
13196}
0 commit comments