mirror of
https://github.com/vacp2p/pmtree.git
synced 2025-02-22 12:08:31 +00:00
feat: add Error type
This commit is contained in:
parent
252fa319eb
commit
0f08d43574
10
src/lib.rs
10
src/lib.rs
@ -19,3 +19,13 @@ pub type DBKey = [u8; 8];
|
|||||||
|
|
||||||
/// Denotes values in a database
|
/// Denotes values in a database
|
||||||
pub type Value = Vec<u8>;
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ const DEPTH_KEY: DBKey = (usize::MAX - 1).to_be_bytes();
|
|||||||
const NEXT_INDEX_KEY: DBKey = usize::MAX.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
|
// Denotes keys (depth, index) in Merkle Tree. Can be converted to DBKey
|
||||||
|
// TODO! Think about using hashing for that
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct Key(usize, usize);
|
struct Key(usize, usize);
|
||||||
impl From<Key> for DBKey {
|
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 {
|
fn hash_couple(&self, depth: usize, key: usize) -> H::Fr {
|
||||||
let b = key & !1;
|
let b = key & !1;
|
||||||
H::hash(&[
|
H::hash(&[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user