witness_from_tree minor refactor

This commit is contained in:
andri lim 2020-04-22 11:28:16 +07:00
parent c33fb4deed
commit ef038c6125
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 8 additions and 14 deletions

View File

@ -106,20 +106,14 @@ proc getBranchRecurseAux(wb: var WitnessBuilder; db: DB, node: openArray[byte],
of 17: of 17:
let branchMask = rlpListToBitmask(nodeRlp) let branchMask = rlpListToBitmask(nodeRlp)
writeBranchNode(wb, branchMask) writeBranchNode(wb, branchMask)
let notLeaf = path.len != 0
if path.len != 0: for i in 0..<16:
for i in 0..<16: if branchMask.branchMaskBitIsSet(i):
if branchMask.branchMaskBitIsSet(i): var branch = nodeRlp.listElem(i)
var branch = nodeRlp.listElem(i) if notLeaf and i == path[0].int:
if i == path[0].int: let nextLookup = branch.getNode
let nextLookup = branch.getNode getBranchRecurseAux(wb, db, nextLookup, path.slice(1))
getBranchRecurseAux(wb, db, nextLookup, path.slice(1)) else:
else:
writeHashNode(wb, branch.expectHash)
else:
for i in 0..<16:
if branchMask.branchMaskBitIsSet(i):
var branch = nodeRlp.listElem(i)
writeHashNode(wb, branch.expectHash) writeHashNode(wb, branch.expectHash)
# put 17th elem # put 17th elem