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

Commit

Permalink
Add typedoc for CheckpointTrie._formatNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Apr 14, 2020
1 parent 2944386 commit ae4a3b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/baseTrie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ export class Trie {
* @param {TrieNode} node - the node to format
* @param {Boolean} topLevel - if the node is at the top level
* @param {BatchDBOp[]} opStack - the opStack to push the node's data
* @param {Boolean} remove - whether to remove the node (pushes `del` operation to the opStack)
* @param {Boolean} remove - whether to remove the node (only used for CheckpointTrie)
* @returns {Buffer | (EmbeddedNode | null)[]} - the node's hash used as the key or the rawNode
*/
_formatNode(
Expand Down
39 changes: 38 additions & 1 deletion src/checkpointTrie.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Trie as BaseTrie } from './baseTrie'
import { ScratchReadStream } from './scratchReadStream'
import { ScratchDB } from './scratch'
import { DB } from './db'
import { DB, BatchDBOp } from './db'
import { TrieNode } from './trieNode'
const WriteStream = require('level-ws')

export class CheckpointTrie extends BaseTrie {
Expand Down Expand Up @@ -142,4 +143,40 @@ export class CheckpointTrie extends BaseTrie {
trie.db = scratch
return new ScratchReadStream(trie)
}

/**
* Formats node to be saved by levelup.batch.
* @method _formatNode
* @private
* @param {TrieNode} node - the node to format
* @param {Boolean} topLevel - if the node is at the top level
* @param {BatchDBOp[]} opStack - the opStack to push the node's data
* @param {Boolean} remove - whether to remove the node (only used for CheckpointTrie)
* @returns {Buffer | (EmbeddedNode | null)[]} - the node's hash used as the key or the rawNode
*/
_formatNode(node: TrieNode, topLevel: boolean, opStack: BatchDBOp[], remove: boolean = false) {
console.log('ENTERING HERE')
const rlpNode = node.serialize()

if (rlpNode.length >= 32 || topLevel) {
const hashRoot = node.hash()

if (remove && this.isCheckpoint) {
opStack.push({
type: 'del',
key: hashRoot,
})
} else {
opStack.push({
type: 'put',
key: hashRoot,
value: rlpNode,
})
}

return hashRoot
}

return node.raw()
}
}

0 comments on commit ae4a3b9

Please sign in to comment.