StateBoundedMerkleTree
@midnight-ntwrk/compact-runtime v0.14.0
@midnight-ntwrk/compact-runtime / StateBoundedMerkleTree
Class: StateBoundedMerkleTree
Represents a fixed-depth Merkle tree storing hashed data, whose preimages are unknown
Constructorsβ
Constructorβ
new StateBoundedMerkleTree(height): StateBoundedMerkleTree;
Create a blank tree with the given height
Parametersβ
heightβ
number
Returnsβ
StateBoundedMerkleTree
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β
StateBoundedMerkleTree
Throwsβ
If the indices are out-of-bounds for the tree, or end < start
findPathForLeaf()β
findPathForLeaf(leaf): AlignedValue | undefined;
Internal
Internal implementation of the finding path primitive. Returns undefined if the leaf is not in the tree.
Parametersβ
leafβ
Returnsβ
AlignedValue | undefined
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β
StateBoundedMerkleTree
root()β
root(): AlignedValue | undefined;
Internal
Internal implementation of the merkle tree root primitive. Returns undefined if the tree has not been fully hashed.
Returnsβ
AlignedValue | undefined
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β
StateBoundedMerkleTree
Throwsβ
If the index is out-of-bounds for the tree