Module rustreexo::accumulator::node_hash
source · Expand description
NodeHash is an internal type for representing Hashes in an utreexo accumulator. It’s just a wrapper around [[u8; 32]] but with some useful methods.
Examples
Building from a str
use std::str::FromStr;
use rustreexo::accumulator::node_hash::NodeHash;
let hash =
NodeHash::from_str("0000000000000000000000000000000000000000000000000000000000000000")
.unwrap();
assert_eq!(
hash.to_string().as_str(),
"0000000000000000000000000000000000000000000000000000000000000000"
);
Building from a slice
use std::str::FromStr;
use rustreexo::accumulator::node_hash::NodeHash;
let hash1 = NodeHash::new([0; 32]);
// ... or ...
let hash2 = NodeHash::from([0; 32]);
assert_eq!(hash1, hash2);
assert_eq!(
hash1.to_string().as_str(),
"0000000000000000000000000000000000000000000000000000000000000000"
);
Computing a parent hash (i.e a hash of two nodes concatenated)
use std::str::FromStr;
use rustreexo::accumulator::node_hash::NodeHash;
let left = NodeHash::new([0; 32]);
let right = NodeHash::new([1; 32]);
let parent = NodeHash::parent_hash(&left, &right);
let expected_parent =
NodeHash::from_str("34e33ca0c40b7bd33d28932ca9e35170def7309a3bf91ecda5e1ceb067548a12")
.unwrap();
assert_eq!(parent, expected_parent);
Enums
- NodeHash is a wrapper around a 32 byte array that represents a hash of a node in the tree.