merkle tree update - getIndexByElement

This commit is contained in:
Alexey 2019-07-18 00:25:16 +03:00
parent b0c896c681
commit 3f3e0534cc
2 changed files with 31 additions and 0 deletions

View file

@ -179,6 +179,16 @@ class MerkleTree {
current_index = Math.floor(current_index / 2)
}
}
getIndexByElement(element) {
for(let i = this.totalElements - 1; i >= 0; i--) {
const elementFromTree = this.storage.get(MerkleTree.index_to_key(this.prefix, 0, i))
if (elementFromTree === element) {
return i
}
}
return false
}
}
module.exports = MerkleTree