acca/collections/hash_tree
Types
Data structure similar to Merkle Tree called colloquially Hash Tree
. Contrary to the original
it doesn’t store the original element.
Alias
Proof<a> = List<ProofItem<a>>
Constructors
-
Left { hash: Hash<Sha2_256, a> }
-
Right { hash: Hash<Sha2_256, a> }
Functions
element_hash (self: HashTree<a>) -> Hash<Sha2_256, a>
from_hashes_list (items: List<Hash<Sha2_256, a>>) -> HashTree<a>
Construct a ‘HashTree’ from a list of hashes. Note that, while this operation is doable on-chain, it is expensive and preferably done off-chain.
from_list (items: List<a>, serialise_fn: fn(a) -> ByteArray) -> HashTree<a>
Construct a ‘HashTree’ from a list of elements. Note that, while this operation is doable on-chain, it is expensive and preferably done off-chain.
get_proof (
self: HashTree<a>,
item: a,
serialise_fn: fn(a) -> ByteArray,
) -> Option<Proof<a>>
Construct a membership ‘Proof’ from an element and a ‘HashTree’. Returns ‘None’ if the element isn’t a member of the tree to begin with. Note function will return Some([]) in case root of the tree is also it’s only one and only element
is_empty (self: HashTree<a>) -> Bool
Function that returns whether merkle tree has any elements
is_equal (left: HashTree<a>, right: HashTree<a>) -> Bool
Function atests whether two Hash Tress are equal, this is the case when their root hashes match.
member(
item: a,
element_hash: Hash<Sha2_256, a>,
proof: Proof<a>,
serialise_fn: fn(a) -> ByteArray,
) -> Bool
member_from_hash (
item_hash: Hash<Sha2_256, a>,
element_hash: Hash<Sha2_256, a>,
proof: Proof<a>,
serialise_fn: fn(a) -> ByteArray,
) -> Bool
member_from_tree (
tree: HashTree<a>,
item: a,
serialise_fn: fn(a) -> ByteArray,
) -> Bool
size(self: HashTree<a>) -> Int
Function returns a total numbers of leaves in the tree.