feat: add Error type

This commit is contained in:
Magamedrasul Ibragimov 2022-11-06 14:08:43 +03:00
parent 252fa319eb
commit 0f08d43574
2 changed files with 12 additions and 1 deletions

View File

@ -19,3 +19,13 @@ pub type DBKey = [u8; 8];
/// Denotes values in a database
pub type Value = Vec<u8>;
/// Denotes Error type, for handling DB interaction errors
#[derive(Debug)]
pub struct Error(String);
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

View File

@ -8,6 +8,7 @@ const DEPTH_KEY: DBKey = (usize::MAX - 1).to_be_bytes();
const NEXT_INDEX_KEY: DBKey = usize::MAX.to_be_bytes();
// Denotes keys (depth, index) in Merkle Tree. Can be converted to DBKey
// TODO! Think about using hashing for that
#[derive(Clone, Copy)]
struct Key(usize, usize);
impl From<Key> for DBKey {
@ -141,7 +142,7 @@ where
}
}
// Hashes the right couple for the key
// Hashes the correct couple for the key
fn hash_couple(&self, depth: usize, key: usize) -> H::Fr {
let b = key & !1;
H::hash(&[