-
Notifications
You must be signed in to change notification settings - Fork 89
Merge checkpoint and secure interface with their ES6 classes #73
Conversation
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
5f89177
to
7fa1ca3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, really happy with these changes, this slowly gets to a readable library again! 😄
super(...args) | ||
this._scratch = null | ||
this._checkpoints = [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this one is the constructor
from the old trie class in index.js
together with the checkpointInterface
instantiation and the isCheckpoint
getter from below, looks good.
|
||
static verifyProof (...args) { | ||
return proof.verifyProof(...args) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This completes the functionality from the trie class, ok.
if (!wasCheckpoint && this.isCheckpoint) { | ||
this._enterCpMode() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
throw new Error('trying to commit when not checkpointed') | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
|
||
cb() | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
trie._scratch = this._scratch | ||
// trie._checkpoints = this._checkpoints.slice() | ||
return trie | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was a bit shaky here, but think this is equivalent. Just for the protocol: this method is not tested, we should add a test case at some point.
trie._getDBs = [scratch] | ||
trie._scratch = scratch | ||
return new ScratchReadStream(trie) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
this.__putDBs = this._putDBs | ||
this._putDBs = [this._scratch] | ||
this._putRaw = this.putRaw | ||
this.putRaw = this._overridePutRaw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The former putRaw
method in here has been replaced by this _overridePutRaw
method, better differentiated, good.
|
||
del (key, cb) { | ||
const hash = ethUtil.keccak256(key) | ||
super.del(hash, cb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Secure trie functionality also equivalent, ok.
One note: this |
This PR merges
checkpointInterface
withCheckpointTrie
andsecureInterface
withSecureTrie
, uses ES6 syntax, and adds some additional comments.CheckpointTrie
is moved to its own file, andindex.js
simply exportsCheckpointTrie
.