@ethereumjs/mpt / MerklePatriciaTrie
Defined in: packages/mpt/src/mpt.ts:55
The basic trie interface, use with import { MerklePatriciaTrie } from '@ethereumjs/mpt'
.
new MerklePatriciaTrie(
opts?
):MerklePatriciaTrie
Defined in: packages/mpt/src/mpt.ts:86
Creates a new trie.
Options for instantiating the trie
Note: in most cases, createMPT constructor should be used. It uses the same API but provides sensible defaults
MerklePatriciaTrie
EMPTY_TRIE_ROOT:
Uint8Array
Defined in: packages/mpt/src/mpt.ts:67
The root for an empty trie
walkTrieIterable: (…
args
) =>AsyncIterable
Defined in: packages/mpt/src/mpt.ts:464
…[Uint8Array
<ArrayBufferLike
>, number
[], OnFound
, NodeFilter
, Set
<string
>]
AsyncIterable
batch(
ops
,skipKeyTransform?
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:872
The given hash of operations (key additions or deletions) are executed on the trie
(delete operations are only executed on DB with deleteFromDB
set to true
)
BatchDBOp
[]
boolean
Promise
<void
>
const ops = [
{ type: 'del', key: Uint8Array.from('father') }
, { type: 'put', key: Uint8Array.from('name'), value: Uint8Array.from('Yuri Irsenovich Kim') } // cspell:disable-line
, { type: 'put', key: Uint8Array.from('dob'), value: Uint8Array.from('16 February 1941') }
, { type: 'put', key: Uint8Array.from('spouse'), value: Uint8Array.from('Kim Young-sook') } // cspell:disable-line
, { type: 'put', key: Uint8Array.from('occupation'), value: Uint8Array.from('Clown') }
]
await trie.batch(ops)
checkpoint():
void
Defined in: packages/mpt/src/mpt.ts:1036
Creates a checkpoint that can later be reverted to or committed.
After this is called, all changes can be reverted until commit
is called.
void
checkRoot(
root
):Promise
<boolean
>
Defined in: packages/mpt/src/mpt.ts:172
Checks if a given root exists.
Uint8Array
Promise
<boolean
>
commit():
Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:1046
Commits a checkpoint to disk, if current checkpoint is not nested. If nested, only sets the parent checkpoint as current checkpoint.
Promise
<void
>
If not during a checkpoint phase
database(
db?
,valueEncoding?
):CheckpointDB
Defined in: packages/mpt/src/mpt.ts:137
DB
<string
, string
| Uint8Array
<ArrayBufferLike
>>
ValueEncoding
del(
key
,skipKeyTransform
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:278
Deletes a value given a key
from the trie
(delete operations are only executed on DB with deleteFromDB
set to true
)
Uint8Array
boolean
= false
Promise
<void
>
A Promise that resolves once value is deleted.
findPath(
key
,throwIfMissing
,partialPath
):Promise
<Path
>
Defined in: packages/mpt/src/mpt.ts:321
Tries to find a path to the node for the given key.
It returns a stack
of nodes to the closest node.
Uint8Array
the search key
boolean
= false
if true, throws if any nodes are missing. Used for verifying proofs. (default: false)
MPTNode
[]
Promise
<Path
>
flushCheckpoints():
void
Defined in: packages/mpt/src/mpt.ts:1078
Flushes all checkpoints, restoring the initial checkpoint state.
void
get(
key
,throwIfMissing
):Promise
<null
|Uint8Array
<ArrayBufferLike
>>
Defined in: packages/mpt/src/mpt.ts:191
Gets a value given a key
Uint8Array
the key to search for
boolean
= false
if true, throws if any nodes are missing. Used for verifying proofs. (default: false)
Promise
<null
| Uint8Array
<ArrayBufferLike
>>
A Promise that resolves to Uint8Array
if a value was found or null
if no value was found.
getValueMap(
startKey
,limit?
):Promise
<{nextKey
:null
|string
;values
: {[key
:string
]:string
; }; }>
Defined in: packages/mpt/src/mpt.ts:1090
Returns a list of values stored in the trie
bigint
= BIGINT_0
first unhashed key in the range to be returned (defaults to 0). Note, all keys must be of the same length or undefined behavior will result
number
the number of keys to be returned (undefined means all keys)
Promise
<{ nextKey
: null
| string
; values
: {[key
: string
]: string
; }; }>
an object with two properties (a map of all key/value pairs in the trie - or in the specified range) and then a nextKey
reference if a range is specified
hasCheckpoints():
boolean
Defined in: packages/mpt/src/mpt.ts:1028
Is the trie during a checkpoint phase?
boolean
lookupNode(
node
):Promise
<MPTNode
>
Defined in: packages/mpt/src/mpt.ts:515
Retrieves a node from db by hash.
Uint8Array <ArrayBufferLike > |
Uint8Array <ArrayBufferLike >[] |
Promise
<MPTNode
>
persistRoot():
Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:975
Persists the root hash in the underlying database
Promise
<void
>
put(
key
,value
,skipKeyTransform
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:209
Stores a given value
at the given key
or do a delete if value
is empty
(delete operations are only executed on DB with deleteFromDB
set to true
)
Uint8Array
null |
Uint8Array <ArrayBufferLike > |
boolean
= false
Promise
<void
>
A Promise that resolves once value is stored.
revert():
Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:1062
Reverts the trie to the state it was at when checkpoint
was first called.
If during a nested checkpoint, sets root to most recent checkpoint, and sets
parent checkpoint as current.
Promise
<void
>
root(
value?
):Uint8Array
Defined in: packages/mpt/src/mpt.ts:152
Gets and/or Sets the current root of the trie
null |
Uint8Array <ArrayBufferLike > |
Uint8Array
saveStack(
key
,stack
,opStack
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:786
Saves a stack of nodes to the database.
the key. Should follow the stack
MPTNode
[]
a stack of nodes to the value given by the key
BatchDBOp
[]
a stack of levelup operations to commit at the end of this function
Promise
<void
>
shallowCopy(
includeCheckpoints
,opts?
):MerklePatriciaTrie
Defined in: packages/mpt/src/mpt.ts:958
Returns a copy of the underlying trie.
Note on db: the copy will create a reference to the same underlying database.
Note on cache: for memory reasons a copy will by default
not recreate a new LRU cache but initialize with cache
being deactivated. This behavior can be overwritten by
explicitly setting cacheSize
as an option on the method.
boolean
= true
If true and during a checkpoint, the copy will contain the checkpointing metadata and will use the same scratch as underlying db.
MerklePatriciaTrie
verifyPrunedIntegrity():
Promise
<boolean
>
Defined in: packages/mpt/src/mpt.ts:890
Promise
<boolean
>
walkAllNodes(
onFound
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:471
Executes a callback for each node in the trie.
OnFound
callback to call when a node is found.
Promise
<void
>
Resolves when finished walking trie.
walkAllValueNodes(
onFound
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:482
Executes a callback for each value node in the trie.
OnFound
callback to call when a node is found.
Promise
<void
>
Resolves when finished walking trie.
walkTrie(
root
,onFound
):Promise
<void
>
Defined in: packages/mpt/src/mpt.ts:460
Walks a trie until finished.
Uint8Array
callback to call when a node is found. This schedules new tasks. If no tasks are available, the Promise resolves.
Promise
<void
>
Resolves when finished walking trie.