use sha2::{Digest, Sha256}; #[derive(Debug)] enum Position { Right, Left, } #[derive(Debug)] struct Node { left: String, right: String, sibling: String, position: Position, data: String, } impl Node { fn hash(&self) -> String { let h = Sha256::digest(self.data.clone()); hex::encode(h).to_string() } } fn main(){ let d = Node { left:"aaa".to_string(), right:"aaa".to_string(), sibling:"aaa".to_string(), position: Position::Left, data:"aaa".to_string()}; println!("{:?}", d); println!("{:?}", d.hash()); }
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.24s
Running `target/debug/sample`
Node { left: “aaa”, right: “aaa”, sibling: “aaa”, position: Left, data: “aaa” }
“9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0”
これで良いのか? なんか違うような気もするが、これでmerkle treeを作っていきたい。。。