feat: Add in-memory blockstore#160
Merged
Merged
Conversation
37b286c to
fd9e451
Compare
oblique
reviewed
Dec 11, 2023
0267613 to
3f0e1dc
Compare
3f0e1dc to
b0ba48c
Compare
fl0rek
commented
Dec 13, 2023
ec35957 to
1af0e1c
Compare
1af0e1c to
be8d776
Compare
Contributor
|
I'm confused. Why pub trait Block<const S: usize>: Sync + Send {
fn cid(&self) -> CidGeneric<S>;
fn data(&self) -> &[u8];
} |
Contributor
|
I tried this and works: blockstore/src/lib.rs pub trait Blockstore {
// ....
async fn put_many<const S: usize, B, I>(&self, blocks: I) -> Result<()>
where
B: Block<S>,
I: IntoIterator<Item = B> + Send,
<I as IntoIterator>::IntoIter: Send,
{
for b in blocks {
let cid = b.cid()?;
self.put_keyed(&cid, b.data()).await?;
}
Ok(())
}
// ...
}
pub trait Block<const S: usize>: Sync + Send {
fn cid(&self) -> Result<CidGeneric<S>, CidError>;
fn data(&self) -> &[u8];
}types/src/share.rs impl Block<NMT_ID_SIZE> for Share {
fn cid(&self) -> Result<CidGeneric<NMT_ID_SIZE>, CidError> {
let hasher = NamespacedSha2Hasher::with_ignore_max_ns(true);
let digest = hasher.hash_leaf(self.as_ref()).iter().collect::<Vec<_>>();
// size is correct, so unwrap is safe
let hash = Multihash::wrap(NMT_CODEC, &digest).unwrap();
Ok(CidGeneric::new_v1(NMT_MULTIHASH_CODE, hash))
}
fn data(&self) -> &[u8] {
&self.data
}
}I prefer this simpler API for the end users |
5c545c9 to
2d2db78
Compare
oblique
reviewed
Dec 15, 2023
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #162