StateBoundedMerkleTree
@midnight-ntwrk/onchain-runtime v2.0.1
@midnight-ntwrk/onchain-runtime / StateBoundedMerkleTree
Class: StateBoundedMerkleTree
Represents a fixed-depth Merkle tree storing hashed data, whose preimages are unknown
Constructors
new StateBoundedMerkleTree()
new StateBoundedMerkleTree(height): StateBoundedMerkleTree
Create a blank tree with the given height
Parameters
height
number
Returns
Properties
height
readonly height: number;
Methods
collapse()
collapse(start, end): StateBoundedMerkleTree
Internal
Erases all but necessary hashes between, and inclusive of, start and
end inidices
Parameters
start
bigint
end
bigint
Returns
Throws
If the indices are out-of-bounds for the tree, or end < start
findPathForLeaf()
findPathForLeaf(leaf): undefined | AlignedValue
Internal
Internal implementation of the finding path primitive. Returns undefined if the leaf is not in the tree.
Parameters
leaf
Returns
undefined | AlignedValue
pathForLeaf()
pathForLeaf(index, leaf): AlignedValue
Internal
Internal implementation of the path construction primitive
Parameters
index
bigint
leaf
Returns
Throws
If the index is out-of-bounds for the tree
rehash()
rehash(): StateBoundedMerkleTree
Rehashes the tree, updating all internal hashes and ensuring all node hashes are present. Necessary because the onchain runtime does not automatically rehash trees.
Returns
root()
root(): undefined | AlignedValue
Internal
Internal implementation of the merkle tree root primitive. Returns undefined if the tree has not been fully hashed.
Returns
undefined | AlignedValue
toString()
toString(compact?): string
Parameters
compact?
boolean
Returns
string
update()
update(index, leaf): StateBoundedMerkleTree
Inserts a value into the Merkle tree, returning the updated tree
Parameters
index
bigint
leaf
Returns
Throws
If the index is out-of-bounds for the tree