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:
let branchMask = rlpListToBitmask(nodeRlp)
writeBranchNode(wb, branchMask)
if path.len != 0:
for i in 0..<16:
if branchMask.branchMaskBitIsSet(i):
var branch = nodeRlp.listElem(i)
if i == path[0].int:
let nextLookup = branch.getNode
getBranchRecurseAux(wb, db, nextLookup, path.slice(1))
else:
writeHashNode(wb, branch.expectHash)
else:
for i in 0..<16:
if branchMask.branchMaskBitIsSet(i):
var branch = nodeRlp.listElem(i)
let notLeaf = path.len != 0
for i in 0..<16:
if branchMask.branchMaskBitIsSet(i):
var branch = nodeRlp.listElem(i)
if notLeaf and i == path[0].int:
let nextLookup = branch.getNode
getBranchRecurseAux(wb, db, nextLookup, path.slice(1))
else:
writeHashNode(wb, branch.expectHash)
# put 17th elem