Skip to content

Commit

Permalink
add get tree node helper from @chm-diederichs
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Aug 16, 2023
1 parent c134b43 commit 8fb53ef
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/merkle-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ class MerkleTreeBatch {
return caps.treeSignableLegacy(hash, this.length, this.fork)
}

get (index) {
if (index >= this.length * 2) return null
if (index < this.treeLength) return this.tree.get(index)

for (const n of this.nodes) {
if (n.index === index) return n
}

return null
}

append (buf) {
const head = this.length * 2
const ite = flat.iterator(head)
Expand Down

0 comments on commit 8fb53ef

Please sign in to comment.