Merkle tree - Mintlayer
An implementation of merkle tree, and related tooling, such as inclusion proofs, done for the Mintlayer blockchain.
Introduction
This library was separated from the mintlayer-core repository because it is stable and to benefit the community, by providing a simple, and robust implementation of a merkle tree.
Advantages
- Heavily tested
- Simplistic
- Made to be extensible
- Minimal amount of dependencies
You can include scale-codec dependency for serialization, but it can be disabled too, in which case you choose your own serialization method, if needed.
Special assumptions
This library doesn't hash the leaves.
Examples
You can find examples for how to get started with this library in the examples directory. However, this is a quick example:
use ;
use ;
// You can use any hashing function you like, we use blake2b here as an example
type Blake2bHasher = Blake2b;
// A helper function that hashes data, not necessary for your application
// You can use any node type you like, as long as you use it consistently in the tree
// See the PairHasher implementation
type TreeNode = ;
// You have to define a type that implements `PairHasher` trait, which will tell the tree how to combine different nodes
;
// This is the important part, your hasher has to implement PairHasher