punching datastore functions through to API

This commit is contained in:
saresend 2020-03-23 11:28:27 -07:00
parent dee4e1cab5
commit d6e159c4de
2 changed files with 13 additions and 7 deletions

View File

@ -36,10 +36,15 @@ impl<Types: RepoTypes> IpldDag<Types> {
Some(cid) => cid,
None => return Err(anyhow::anyhow!("expected cid")),
};
let mut ipld = decode_ipld(&cid, self.repo.get_block(&cid).await?.data())?;
for sub_path in path.iter() {}
self.repo.pin_block(cid).await
}
todo!()
pub async fn unpin(&self, path: IpfsPath) -> Result<(), Error> {
let cid = match path.root().cid() {
Some(cid) => cid,
None => return Err(anyhow::anyhow!("expected cid")),
};
self.repo.unpin_block(cid).await
}
pub async fn get(&self, path: IpfsPath) -> Result<Ipld, Error> {

View File

@ -69,6 +69,7 @@ pub trait DataStore: Debug + Clone + Send + Sync + Unpin + 'static {
#[derive(Clone, Copy, Debug)]
pub enum Column {
Ipns,
Pin,
}
#[derive(Debug)]
@ -209,15 +210,15 @@ impl<TRepoTypes: RepoTypes> Repo<TRepoTypes> {
self.data_store.remove(Column::Ipns, ipns.as_bytes()).await
}
pub async fn pin_block(&self, ipns: &PeerId, cid: &Cid) -> Result<(), Error> {
pub async fn pin_block(&self, cid: &Cid) -> Result<(), Error> {
self.data_store
.put(Column::Ipns, &cid.to_bytes(), &vec![1])
.put(Column::Pin, &cid.to_bytes(), &vec![1])
.await
}
pub async fn unpin_block(&self, ipns: &PeerId, cid: &Cid) -> Result<(), Error> {
pub async fn unpin_block(&self, cid: &Cid) -> Result<(), Error> {
self.data_store
.put(Column::Ipns, &cid.to_bytes(), &vec![0])
.put(Column::Pin, &cid.to_bytes(), &vec![0])
.await
}
}