Trait fvm_ipld_blockstore::Blockstore
source · pub trait Blockstore {
// Required methods
fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>;
fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>;
// Provided methods
fn has(&self, k: &Cid) -> Result<bool> { ... }
fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>
where Self: Sized,
D: AsRef<[u8]> { ... }
fn put_many<D, I>(&self, blocks: I) -> Result<()>
where Self: Sized,
D: AsRef<[u8]>,
I: IntoIterator<Item = (Code, Block<D>)> { ... }
fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>
where Self: Sized,
D: AsRef<[u8]>,
I: IntoIterator<Item = (Cid, D)> { ... }
}
Expand description
An IPLD blockstore suitable for injection into the FVM.
The cgo blockstore adapter implements this trait.
Required Methods§
sourcefn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>
fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>
Put a block with a pre-computed cid.
If you don’t yet know the CID, use put. Some blockstores will re-compute the CID internally even if you provide it.
If you do already know the CID, use this method as some blockstores won’t recompute it.
Provided Methods§
sourcefn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>
fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>
Puts the block into the blockstore, computing the hash with the specified multicodec.
By default, this defers to put.
sourcefn put_many<D, I>(&self, blocks: I) -> Result<()>
fn put_many<D, I>(&self, blocks: I) -> Result<()>
Bulk put blocks into the blockstore.
use multihash::Code::Blake2b256;
use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore, Block};
let bs = MemoryBlockstore::default();
let blocks = vec![Block::new(0x55, vec![0, 1, 2])];
bs.put_many(blocks.iter().map(|b| (Blake2b256, b.into()))).unwrap();
sourcefn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>
fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>
Bulk-put pre-keyed blocks into the blockstore.
By default, this defers to put_keyed.