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

Commit

Permalink
Merge 0cd83dc into 768eac1
Browse files Browse the repository at this point in the history
  • Loading branch information
zmitton committed Mar 18, 2019
2 parents 768eac1 + 0cd83dc commit 50694ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
23 changes: 12 additions & 11 deletions .gitignore
Expand Up @@ -2,14 +2,15 @@ package-lock.json
node_modules
dist/

baseTrie.js
checkpoint-interface.js
index.js
prioritizedTaskExecutor.js
proof.js
readStream.js
secure-interface.js
secure.js
scratchReadStream.js
trieNode.js
util.js
/baseTrie.js
/checkpointTrie.js
/db.js
/index.js
/prioritizedTaskExecutor.js
/proof.js
/readStream.js
/scratch.js
/scratchReadStream.js
/secure.js
/trieNode.js
/util/
32 changes: 23 additions & 9 deletions src/baseTrie.js
Expand Up @@ -31,7 +31,7 @@ module.exports = class Trie {
this.db = db || new DB()

Object.defineProperty(this, 'root', {
set(value) {
set (value) {
if (value) {
value = ethUtil.toBuffer(value)
assert(value.length === 32, 'Invalid root length. Roots are 32 bytes')
Expand All @@ -41,7 +41,7 @@ module.exports = class Trie {

this._root = value
},
get() {
get () {
return this._root
}
})
Expand Down 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 = new Error('Missing node in DB')
}

cb(value)
cb(err, value)
})
}
}
Expand Down Expand Up @@ -375,7 +377,10 @@ 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 +426,10 @@ 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 +442,10 @@ 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 +596,10 @@ module.exports = class Trie {
const branchNodeKey = branchNodes[0][0]

// look up node
this._lookupNode(branchNode, foundNode => {
this._lookupNode(branchNode, (e, foundNode) => {
if (e) {
return cb(e, foundNode)
}
key = processBranchNode(key, branchNodeKey, foundNode, parentNode, stack, opStack)
this._saveStack(key, stack, opStack, cb)
})
Expand Down Expand Up @@ -694,7 +708,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
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
1 change: 0 additions & 1 deletion test/secure.js
Expand Up @@ -2,7 +2,6 @@ const Trie = require('../src/secure.js')
const async = require('async')
const tape = require('tape')


tape('SecureTrie', function (t) {
const trie = new Trie()
const k = Buffer.from('foo')
Expand Down

0 comments on commit 50694ee

Please sign in to comment.