Sparse merkle tree with variants implementation for CosmWasm smart contract
Variants
Sparse Merkle Tree
Normal sparse merkle tree with customizable tree level and default leaf.
Sparse Merkle Tree With History
Like sparse merkle tree but able to check valid root hash with all previous root hashes.
Sparse Merkle Tree With History Bounded
Like sparse merkle tree but able to check valid root hash with previous root hashes upto specified history level.
Example Usage
Hasher
Implement the hasher trait for desired hasher struct.
;
Merkle Tree
First, instantiate the merkle tree by using new
constructor function and specify leaf and hasher type.
const TREE: =
new;
Then initialize the tree by invoking the init
function, preferably in instantiate
entry point.
Next, insert a leaf into next available index of the tree by invoking insert
function, insert
will return inserted index and the new root.
let leaf = Blake2.hash_two?;
let = TREE.insert?;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;