Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MerklePatriciaTree<K, V>

A Merkle Patricia Tree, as defined in the Ethereum Yellow Paper.

Type parameters

  • K

  • V

Hierarchy

Implements

Index

Constructors

constructor

Properties

options

rootNode

The root node of the tree.

Accessors

root

  • get root(): Buffer
  • A Buffer representing the root hash of the tree. Always 256-bits (32 bytes).

    Returns Buffer

rootHash

  • get rootHash(): bigint
  • The root hash of the tree, as a bigint. Reading this property is more efficient than obtaining a buffer.

    Returns bigint

Methods

batch

  • batch(putOps: Array<BatchPut<K, V>>, delOps?: K[]): Buffer
  • Execute a batch of put and delete operations. The execution is batched, so calling this function with multiple updates provides more opportunities for optimization and can be faster than call put() and del() multiple times.

    Parameters

    • putOps: Array<BatchPut<K, V>>

      An array of put operations on the tree, of type BatchPut.

    • Default value delOps: K[] = []

      An optional array of keys to delete from the tree.

    Returns Buffer

    The root that results from this set of operations.

batchCOW

  • Execute a batch of put and delete operations. The execution of batch operations are performed in a copy on write (cow) fashion.

    Parameters

    • putOps: Array<BatchPut<K, V>>

      An array of put operations on the tree, of type BatchPut.

    • Default value delOps: K[] = []

      An optional array of keys to delete from the tree.

    Returns MerklePatriciaTree<K, V>

    A new MerklePatriciaTree updated in a cow manner.

batchGet

  • batchGet(keys: K[]): Array<Witness<V>>
  • Reads multiple keys and returns a concise reply of witnesses

    Parameters

    • keys: K[]

      : bulk keys to be read

    Returns Array<Witness<V>>

    : Array of witnesses

copyTreePaths

del

  • del(key: K): void
  • Given a key, delete any mapping that exists for that key.

    Parameters

    • key: K

      The key to unmap.

    Returns void

get

  • Given a key, retrieve a Witness for the mapping.

    Parameters

    • key: K

      The key to retrieve the Witness for.

    Returns Witness<V>

    A Witness, with a proof of the value read (or a null value, with a proof of the value's nonexistence).

getNodeCopy

insert

  • Insert a node with the given value after a search.

    Parameters

    • stack: Array<MerklePatriciaTreeNode<V>>

      The stack as a result of the search

    • remainder: number[]

      The remainder as a result of the search

    • value: V

      The value to insert.

    Returns void

multiSearch

  • multiSearch(putOps: Array<BatchPut<K, V>>, delOps: K[], flag: boolean): void
  • multiSearch searches the tree for all keys and marks nodes for copy

    Parameters

    • putOps: Array<BatchPut<K, V>>

      : List of key, value pairs

    • delOps: K[]

      : List of keys

    • flag: boolean

      : True if we want to mark the nodes for copy

    Returns void

nodeCount

  • nodeCount(count?: number): number
  • Counts the number of nodes in the tree

    Parameters

    • Default value count: number = 0

    Returns number

put

  • put(key: K, val: V): void
  • Insert a new mapping into the tree. If the key is already mapped in the tree, it is updated with the new value.

    Parameters

    • key: K

      The key to insert.

    • val: V

      A Buffer representing the value.

    Returns void

rlpSerializeWitness

  • Serialize a witness into RLP format.

    Parameters

    • witness: Witness<V>

      A witness returned from a get() operation on a Merkle Patricia Tree

    Returns RlpWitness

    An RLP serialized witness, with non-essential nodes removed.

search

  • Search for the given key, returning a SearchResult which contains the path traversed to search for the key.

    Parameters

    • key: K

      The key to search for.

    • Default value markForCopy: boolean = false

    Returns SearchResult<V>

    A SearchResult containing the path to the key, and the value if it was present.

size

  • size(): number
  • Returns the sum of lengths of rlpEncodings of all the nodes in the tree

    Returns number

Generated using TypeDoc