From e905a3c9e12709f2403e9d72a25d2f0757341aa5 Mon Sep 17 00:00:00 2001 From: Samer Afach Date: Thu, 18 Apr 2024 16:51:56 +0400 Subject: [PATCH] Update readme example --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0939c58..ac9b427 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ You can find examples for how to get started with this library in the [examples ```rust use blake2::{digest::typenum, Digest}; -use merkletree::{hasher::PairHasher, tree::MerkleTree}; +use merkletree_mintlayer::{hasher::PairHasher, tree::MerkleTree}; // You can use any hashing function you like, we use blake2b here as an example type Blake2bHasher = blake2::Blake2b; @@ -61,16 +61,16 @@ impl HashAlgo { // This is the important part, your hasher has to implement PairHasher impl PairHasher for HashAlgo { - type Type = TreeNode; + type NodeType = TreeNode; - fn hash_pair(left: &Self::Type, right: &Self::Type) -> Self::Type { + fn hash_pair(left: &Self::NodeType, right: &Self::NodeType) -> Self::NodeType { let mut h = Blake2bHasher::new(); Digest::update(&mut h, left); Digest::update(&mut h, right); h.finalize_reset().into() } - fn hash_single(data: &Self::Type) -> Self::Type { + fn hash_single(data: &Self::NodeType) -> Self::NodeType { let mut h = Blake2bHasher::new(); Digest::update(&mut h, data); h.finalize_reset().into() @@ -79,14 +79,14 @@ impl PairHasher for HashAlgo { fn main() { // You have to hash the leaves or create them (any way you like) - let leaf1 = hash_data("0"); - let leaf2 = hash_data("1"); - let leaf3 = hash_data("2"); - let leaf4 = hash_data("3"); + let leaf0 = hash_data("0"); + let leaf1 = hash_data("1"); + let leaf2 = hash_data("2"); + let leaf3 = hash_data("3"); // The tree is defined from a vector of leaves, from left to right let tree = - MerkleTree::::from_leaves(vec![leaf1, leaf2, leaf3, leaf4]).unwrap(); + MerkleTree::::from_leaves(vec![leaf0, leaf1, leaf2, leaf3]).unwrap(); // Let's get the root let tree_root = tree.root(); @@ -102,12 +102,12 @@ fn main() { // We attempt to recreate the expected root manually let mut node10 = HashAlgo::new(); + node10.write(leaf0); node10.write(leaf1); - node10.write(leaf2); let mut node11 = HashAlgo::new(); + node11.write(leaf2); node11.write(leaf3); - node11.write(leaf4); let mut node00 = HashAlgo::new(); let n10 = node10.finalize();