mirror of
https://github.com/vacp2p/pmtree.git
synced 2026-01-09 15:28:02 -05:00
fix: unwrap on root when tree is persisted
This commit is contained in:
19
src/tree.rs
19
src/tree.rs
@@ -89,15 +89,22 @@ where
|
||||
// Load existing db instance
|
||||
let db = D::load(db_config)?;
|
||||
|
||||
// Load root
|
||||
let root = H::deserialize(db.get(Key(0, 0).into())?.unwrap());
|
||||
// Load root
|
||||
let root = match db.get(Key(0, 0).into())? {
|
||||
Some(root) => H::deserialize(root),
|
||||
None => H::default_leaf(),
|
||||
};
|
||||
|
||||
// Load depth & next_index values from db
|
||||
let depth = db.get(DEPTH_KEY)?.unwrap().try_into().unwrap();
|
||||
let depth = usize::from_be_bytes(depth);
|
||||
let depth = match db.get(DEPTH_KEY)? {
|
||||
Some(depth) => usize::from_be_bytes(depth.try_into().unwrap()),
|
||||
None => 20
|
||||
};
|
||||
|
||||
let next_index = db.get(NEXT_INDEX_KEY)?.unwrap().try_into().unwrap();
|
||||
let next_index = usize::from_be_bytes(next_index);
|
||||
let next_index = match db.get(NEXT_INDEX_KEY)? {
|
||||
Some(next_index) => usize::from_be_bytes(next_index.try_into().unwrap()),
|
||||
None => 0,
|
||||
};
|
||||
|
||||
// Load cache vec
|
||||
let mut cache = vec![H::default_leaf(); depth + 1];
|
||||
|
||||
Reference in New Issue
Block a user