fix a bug

This commit is contained in:
Alexey 2019-07-23 00:19:50 +03:00
parent 13b9a948dc
commit 754172a5a4

View File

@ -26,9 +26,9 @@ class MerkleTree {
this.storage.put(MerkleTree.index_to_key(prefix, level, i), element) this.storage.put(MerkleTree.index_to_key(prefix, level, i), element)
}) })
level++ level++
let numberOfElementInRow = Math.ceil(defaultElements.length / 2) let numberOfElementsInLevel = Math.ceil(defaultElements.length / 2)
for (level; level <= this.n_levels; level++) { for (level; level <= this.n_levels; level++) {
for(let i = 0; i < numberOfElementInRow; i++) { for(let i = 0; i < numberOfElementsInLevel; i++) {
const leftKey = MerkleTree.index_to_key(prefix, level - 1, 2 * i) const leftKey = MerkleTree.index_to_key(prefix, level - 1, 2 * i)
const rightKey = MerkleTree.index_to_key(prefix, level - 1, 2 * i + 1) const rightKey = MerkleTree.index_to_key(prefix, level - 1, 2 * i + 1)
@ -38,7 +38,7 @@ class MerkleTree {
const subRoot = this.hasher.hash(null, left, right) const subRoot = this.hasher.hash(null, left, right)
this.storage.put(MerkleTree.index_to_key(prefix, level, i), subRoot) this.storage.put(MerkleTree.index_to_key(prefix, level, i), subRoot)
} }
numberOfElementInRow = Math.max(Math.ceil(numberOfElementInRow / 2), 1) numberOfElementsInLevel = Math.ceil(numberOfElementsInLevel / 2)
} }
} }
} }