46 static void MerkleComputation(
const std::vector<uint256>& leaves,
uint256* proot,
bool* pmutated, uint32_t branchpos, std::vector<uint256>* pbranch) {
47 if (pbranch) pbranch->clear();
48 if (leaves.size() == 0) {
49 if (pmutated) *pmutated =
false;
65 while (count < leaves.size()) {
67 bool matchh = count == branchpos;
73 for (level = 0; !(count & (((uint32_t)1) << level)); level++) {
76 pbranch->push_back(inner[level]);
77 }
else if (matchlevel == level) {
78 pbranch->push_back(h);
82 mutated |= (inner[level] ==
h);
97 while (!(count & (((uint32_t)1) << level))) {
101 bool matchh = matchlevel == level;
102 while (count != (((uint32_t)1) << level)) {
106 if (pbranch && matchh) {
107 pbranch->push_back(h);
112 count += (((uint32_t)1) << level);
115 while (!(count & (((uint32_t)1) << level))) {
118 pbranch->push_back(inner[level]);
119 }
else if (matchlevel == level) {
120 pbranch->push_back(h);
129 if (pmutated) *pmutated = mutated;
130 if (proot) *proot =
h;
135 MerkleComputation(leaves, &hash, mutated, -1,
nullptr);
140 std::vector<uint256> ret;
141 MerkleComputation(leaves,
nullptr,
nullptr, position, &ret);
147 for (std::vector<uint256>::const_iterator it = vMerkleBranch.begin(); it != vMerkleBranch.end(); ++it) {
160 std::vector<uint256> leaves;
161 leaves.resize(block.
vtx.size());
162 for (
size_t s = 0; s < block.
vtx.size(); s++) {
163 leaves[s] = block.
vtx[s]->GetHash();
170 std::vector<uint256> leaves;
171 leaves.resize(block.
vtx.size());
173 for (
size_t s = 1; s < block.
vtx.size(); s++) {
174 leaves[s] = block.
vtx[s]->GetWitnessHash();
181 std::vector<uint256> leaves;
182 leaves.resize(block.
vtx.size());
183 for (
size_t s = 0; s < block.
vtx.size(); s++) {
184 leaves[s] = block.
vtx[s]->GetHash();
CHash256 & Write(const unsigned char *data, size_t len)
std::vector< uint256 > BlockMerkleBranch(const CBlock &block, uint32_t position)
std::vector< uint256 > ComputeMerkleBranch(const std::vector< uint256 > &leaves, uint32_t position)
uint256 ComputeMerkleRootFromBranch(const uint256 &leaf, const std::vector< uint256 > &vMerkleBranch, uint32_t nIndex)
uint256 BlockWitnessMerkleRoot(const CBlock &block, bool *mutated)
A hasher class for Fabcoin's 256-bit hash (double SHA-256).
uint256 ComputeMerkleRoot(const std::vector< uint256 > &leaves, bool *mutated)
#define BEGIN(a)
Utilities for converting data from/to strings.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
uint256 Hash(const T1 pbegin, const T1 pend)
Compute the 256-bit hash of an object.
std::vector< CTransactionRef > vtx