Class StandardTree

A Merkle tree implementation that uses a LevelDB database to store the tree.

Hierarchy

  • TreeBase
    • StandardTree

Implements

Constructors

Properties

cachedSize?: bigint
db: Level<string, Buffer>
hasher: Hasher
maxIndex: bigint
size: bigint = ...

Methods

  • Adds a leaf and all the hashes above it to the cache.

    Parameters

    • leaf: Field

      Leaf to add to cache.

    • index: bigint

      Index of the leaf (used to derive the cache key).

    Returns Promise<void>

  • Gets the value at the given index.

    Parameters

    • index: bigint

      The index of the leaf.

    • includeUncommitted: boolean

      Indicates whether to include uncommitted changes.

    Returns Promise<undefined | Field>

    Leaf value at the given index or undefined.

  • Returns the number of leaves in the tree.

    Parameters

    • includeUncommitted: boolean

      If true, the returned number of leaves includes uncomitted changes.

    Returns bigint

    The number of leaves in the tree.

  • Returns the root of the tree.

    Parameters

    • includeUncommitted: boolean

      If true, root incorporating uncomitted changes is returned.

    Returns Field

    The root of the tree.

  • Returns a sibling path for the element at the given index.

    Parameters

    • index: bigint

      The index of the element.

    • includeUncommitted: boolean

      Indicates whether to get a sibling path incorporating uncommitted changes.

    Returns Promise<BaseSiblingPath>

    A sibling path for the element at the given index. Note: The sibling path is an array of sibling hashes, with the lowest hash (leaf hash) first, and the highest hash last.

  • Initializes the tree.

    Parameters

    • prefilledSize: number

      A number of leaves that are prefilled with values.

    Returns Promise<void>

    Empty promise.

  • Writes meta data to the provided batch.

    Parameters

    • Optional batch: ChainedBatch<Level<string, Buffer>, string, Buffer>

      The batch to which to write the meta data.

    Returns Promise<void>