A merkle-tree toolkit and backend.
Kelvin is designed to make designing and using Merkle Tree structures a breeze.
Here is an example of all you need to construct a program state that can be persisted as a Merkle Tree. (taken from examples/simple)
```rust use std::io;
use kelvin::{Blake2b, ByteHash, Content, Map, Root, Sink, Source}; use kelvin_btree::BTree;
struct State
// The initial root state
impl
impl
fn restore(source: &mut Source<H>) -> io::Result<Self> {
Ok(State {
map_a: BTree::restore(source)?,
map_b: BTree::restore(source)?,
counter: u64::restore(source)?,
})
}
}
fn main() -> io::Result<()> { let mut root = Root::<_, Blake2b>::new("/tmp/kelvin-example")?;
let mut state: State<_> = root.restore()?;
match state.map_a.get(&"Foo".to_owned())? {
Some(path) => println!("Foo is {}", *path),
None => println!("Foo is `None`"),
}
println!("Counter is {}", state.counter);
state.counter += 1;
state.map_a.insert(
"Foo".into(),
format!("Bar {}", state.counter * state.counter),
)?;
root.set_root(&mut state)?;
Ok(())
} ```