sparse_merkle_tree/
traits.rs1use crate::{
2 error::Error,
3 tree::{BranchKey, BranchNode},
4 H256,
5};
6
7pub trait Hasher {
9 fn write_h256(&mut self, h: &H256);
10 fn write_byte(&mut self, b: u8);
11 fn finish(self) -> H256;
12}
13
14pub trait Value {
16 fn to_h256(&self) -> H256;
17 fn zero() -> Self;
18}
19
20impl Value for H256 {
21 fn to_h256(&self) -> H256 {
22 *self
23 }
24 fn zero() -> Self {
25 H256::zero()
26 }
27}
28
29pub trait StoreReadOps<V> {
31 fn get_branch(&self, branch_key: &BranchKey) -> Result<Option<BranchNode>, Error>;
32 fn get_leaf(&self, leaf_key: &H256) -> Result<Option<V>, Error>;
33}
34
35pub trait StoreWriteOps<V> {
36 fn insert_branch(&mut self, node_key: BranchKey, branch: BranchNode) -> Result<(), Error>;
37 fn insert_leaf(&mut self, leaf_key: H256, leaf: V) -> Result<(), Error>;
38 fn remove_branch(&mut self, node_key: &BranchKey) -> Result<(), Error>;
39 fn remove_leaf(&mut self, leaf_key: &H256) -> Result<(), Error>;
40}