Trait wnfs_common::blockstore::BlockStore
source · pub trait BlockStore: CondSync {
// Required methods
fn get_block(
&self,
cid: &Cid
) -> impl Future<Output = Result<Bytes, BlockStoreError>> + CondSend;
fn put_block_keyed(
&self,
cid: Cid,
bytes: impl Into<Bytes> + CondSend
) -> impl Future<Output = Result<(), BlockStoreError>> + CondSend;
fn has_block(
&self,
cid: &Cid
) -> impl Future<Output = Result<bool, BlockStoreError>> + CondSend;
// Provided methods
fn put_block(
&self,
bytes: impl Into<Bytes> + CondSend,
codec: u64
) -> impl Future<Output = Result<Cid, BlockStoreError>> + CondSend { ... }
fn create_cid(
&self,
bytes: &[u8],
codec: u64
) -> Result<Cid, BlockStoreError> { ... }
}
Expand description
For types that implement block store operations like adding, getting content from the store.
Required Methods§
sourcefn get_block(
&self,
cid: &Cid
) -> impl Future<Output = Result<Bytes, BlockStoreError>> + CondSend
fn get_block( &self, cid: &Cid ) -> impl Future<Output = Result<Bytes, BlockStoreError>> + CondSend
Retrieve a block from this store via its hash (Cid
).
If this store can’t find the block, it may raise an error like BlockNotFound
.
sourcefn put_block_keyed(
&self,
cid: Cid,
bytes: impl Into<Bytes> + CondSend
) -> impl Future<Output = Result<(), BlockStoreError>> + CondSend
fn put_block_keyed( &self, cid: Cid, bytes: impl Into<Bytes> + CondSend ) -> impl Future<Output = Result<(), BlockStoreError>> + CondSend
Put a block of data into this blockstore. The block’s CID needs to match the CID given.
It’s up to the blockstore whether to check this fact or assume it when this function is called.
The default implementation of put_block
will use this function under the hood and use
the correct CID provided by the create_cid
function.
This is useful to be able to add blocks that were generated from other clients with differently configured hashing functions to this blockstore.
Provided Methods§
sourcefn put_block(
&self,
bytes: impl Into<Bytes> + CondSend,
codec: u64
) -> impl Future<Output = Result<Cid, BlockStoreError>> + CondSend
fn put_block( &self, bytes: impl Into<Bytes> + CondSend, codec: u64 ) -> impl Future<Output = Result<Cid, BlockStoreError>> + CondSend
Put some bytes into the blockstore. These bytes should be encoded with the given codec.
E.g. CODEC_RAW
for raw bytes blocks, CODEC_DAG_CBOR
for dag-cbor, etc.
This codec will determine the codec encoded in the final Cid
that’s returned.
If the codec is incorrect, this function won’t fail, but any tools that depend on the correctness of the codec may fail. (E.g. tools that follow the links of blocks).
This funciton allows the blockstore to choose the hashing function itself.
The hashing function that was chosen will be readable from the Cid
metadata.
If you need control over the concrete hashing function that’s used, see put_block_keyed
.