Imperative wrapper of MerkleTree
This module contains an imperative wrapper of the functional API provided by MerkleTree
.
This makes common usage pattern around these trees more convenient.
This module defines two types:
The Store
. This is meant to be your canister's single hash tree. It is separated
from the class providing functions so that it can be put in stable memory:
The Ops
class. This wraps such a Store
and offers all the operations you expect.
So this is the suggested idiom:
stable let cert_store : CertTree.Store = CertTree.newStore();
let ct = CertTree.Ops(cert_store);
public func newStore() : Store
public func put(ks : Path, v : Value)
Inserting a value at a given path into the tree.
An existing value (or subtree) under that path is overridden.
If there are values at any prefix of the given path, they will be removed.
public func delete(ks : Path)
Deleting a path from a tree.
This removes the given path from the tree, independently of whether there is a value at that path, or a whole subtree.
If there are values at any prefix of the given path, they will be removed.
public func lookup(ks : Path) : ?Value
Looking up a value at a path
This will return null
if the path does not exist, or if
there is a subtree (and not a value) at that key.
public func labelsAt(ks : Path) : Iter.Iter<Key>
Lookup up all labels at a path.
Returns an iterator, so you can use it with
for (k in ct.labelsAt(["some", "path"))) { … }
public func treeHash() : Hash
Root hash
public func setCertifiedData()
Sets the canister's certified data to the root hash Call this at the end of any update function that changed the certified data tree
public func reveal(path : Path) : Witness
Create a witness that reveals the value of the key k
in the tree tree
.
If k
is not in the tree, the witness will prove that fact.
public func encodeWitness(w : Witness) : Blob
Encodes a witness as CBOR, e.g. for certified assets