aboutsummaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/mst.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-02 21:10:57 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-11-02 21:10:57 -0700
commit9b4a5c6bfd2b816fc9b281bdd12e67a0e0245f4c (patch)
tree9aabb43924f610fcf7946fa4a29f4315d3f25ded /adenosine-pds/src/mst.rs
parent8319500ed7bb1bfba15b74132f19dc2b960ea7c1 (diff)
downloadadenosine-9b4a5c6bfd2b816fc9b281bdd12e67a0e0245f4c.tar.gz
adenosine-9b4a5c6bfd2b816fc9b281bdd12e67a0e0245f4c.zip
pds: progress on repo mst wrapper
Diffstat (limited to 'adenosine-pds/src/mst.rs')
-rw-r--r--adenosine-pds/src/mst.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/adenosine-pds/src/mst.rs b/adenosine-pds/src/mst.rs
index db5e457..b71cc73 100644
--- a/adenosine-pds/src/mst.rs
+++ b/adenosine-pds/src/mst.rs
@@ -1,5 +1,5 @@
use crate::load_car_to_blockstore;
-use anyhow::{anyhow, Result};
+use anyhow::{anyhow, Context, Result};
use ipfs_sqlite_block_store::BlockStore;
use libipld::cbor::DagCborCodec;
use libipld::multihash::Code;
@@ -61,10 +61,13 @@ struct WipNode {
}
fn get_mst_node(db: &mut BlockStore<libipld::DefaultParams>, cid: &Cid) -> Result<MstNode> {
- let mst_node: MstNode = DagCborCodec.decode(
- &db.get_block(cid)?
- .ok_or(anyhow!("expected block in store"))?,
- )?;
+ let block = &db
+ .get_block(cid)?
+ .ok_or(anyhow!("reading MST node from blockstore"))?;
+ //println!("{:?}", block);
+ let mst_node: MstNode = DagCborCodec
+ .decode(block)
+ .context("parsing MST DAG-CBOR IPLD node from blockstore")?;
Ok(mst_node)
}
@@ -168,9 +171,9 @@ fn leading_zeros(key: &str) -> u8 {
digest.len() as u8
}
-fn generate_mst(
+pub fn generate_mst(
db: &mut BlockStore<libipld::DefaultParams>,
- map: &mut BTreeMap<String, Cid>,
+ map: &BTreeMap<String, Cid>,
) -> Result<Cid> {
// construct a "WIP" tree
let mut root: Option<WipNode> = None;
@@ -192,7 +195,12 @@ fn generate_mst(
});
}
}
- serialize_wip_tree(db, root.expect("non-empty MST tree"))
+ let empty_node = WipNode {
+ height: 0,
+ left: None,
+ entries: vec![],
+ };
+ serialize_wip_tree(db, root.unwrap_or(empty_node))
}
fn insert_entry(mut node: WipNode, entry: WipEntry) -> WipNode {