Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge a3d8cd2 into 768eac1
Browse files Browse the repository at this point in the history
  • Loading branch information
zmitton committed Feb 26, 2019
2 parents 768eac1 + a3d8cd2 commit 7dc83f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/baseTrie.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = class Trie {
// retrieves a node from dbs by hash
_lookupNode (node, cb) {
if (TrieNode.isRawNode(node)) {
cb(new TrieNode(node))
cb(null, new TrieNode(node))
} else {
this.db.get(node, (err, value) => {
if (err) {
Expand All @@ -141,9 +141,11 @@ module.exports = class Trie {

if (value) {
value = new TrieNode(rlp.decode(value))
}else{
err = err || "Missing node in DB"
}

cb(value)
cb(err, value)
})
}
}
Expand Down Expand Up @@ -375,7 +377,8 @@ module.exports = class Trie {
return onDone()
}

this._lookupNode(root, node => {
this._lookupNode(root, (e, node) => {
if(e){ return onDone(e, node) }
processNode(root, node, null, err => {
if (err) {
return onDone(err)
Expand Down Expand Up @@ -421,7 +424,8 @@ module.exports = class Trie {
const childKey = key.concat(keyExtension)
const priority = childKey.length
taskExecutor.execute(priority, taskCallback => {
self._lookupNode(childRef, childNode => {
self._lookupNode(childRef, (e, childNode) => {
if(e){ return cb(e, node) }
taskCallback()
processNode(childRef, childNode, childKey, cb)
})
Expand All @@ -434,7 +438,8 @@ module.exports = class Trie {
childKey.push(childIndex)
const priority = childKey.length
taskExecutor.execute(priority, taskCallback => {
self._lookupNode(childRef, childNode => {
self._lookupNode(childRef, (e, childNode) => {
if(e){ return cb(e, node) }
taskCallback()
processNode(childRef, childNode, childKey, cb)
})
Expand Down Expand Up @@ -585,7 +590,7 @@ module.exports = class Trie {
const branchNodeKey = branchNodes[0][0]

// look up node
this._lookupNode(branchNode, foundNode => {
this._lookupNode(branchNode, (e, foundNode) => {
key = processBranchNode(key, branchNodeKey, foundNode, parentNode, stack, opStack)
this._saveStack(key, stack, opStack, cb)
})
Expand Down Expand Up @@ -694,7 +699,7 @@ module.exports = class Trie {
*/
checkRoot (root, cb) {
root = ethUtil.toBuffer(root)
this._lookupNode(root, value => {
this._lookupNode(root, (e, value) => {
cb(null, !!value)
})
}
Expand Down
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ tape('simple save and retrive', function (tester) {

trie.get('test', function (err, value) {
t.equal(value, null)
t.end(err)

t.notEqual(err, null)
t.end()
})
})

Expand Down

0 comments on commit 7dc83f4

Please sign in to comment.