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§

source

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>

Gets the block from the blockstore.

source

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§

source

fn has(&self, k: &Cid) -> Result<bool>

Checks if the blockstore has the specified block.

source

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>where Self: Sized, D: AsRef<[u8]>,

Puts the block into the blockstore, computing the hash with the specified multicodec.

By default, this defers to put.

source

fn put_many<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

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();
source

fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid, D)>,

Bulk-put pre-keyed blocks into the blockstore.

By default, this defers to put_keyed.

Implementations on Foreign Types§

source§

impl<BS> Blockstore for Arc<BS>where BS: Blockstore,

source§

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>

source§

fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>

source§

fn has(&self, k: &Cid) -> Result<bool>

source§

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>where Self: Sized, D: AsRef<[u8]>,

source§

fn put_many<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

source§

fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid, D)>,

source§

impl<BS> Blockstore for Rc<BS>where BS: Blockstore,

source§

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>

source§

fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>

source§

fn has(&self, k: &Cid) -> Result<bool>

source§

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>where Self: Sized, D: AsRef<[u8]>,

source§

fn put_many<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

source§

fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid, D)>,

source§

impl<BS> Blockstore for &BSwhere BS: Blockstore,

source§

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>

source§

fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>

source§

fn has(&self, k: &Cid) -> Result<bool>

source§

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid>where Self: Sized, D: AsRef<[u8]>,

source§

fn put_many<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

source§

fn put_many_keyed<D, I>(&self, blocks: I) -> Result<()>where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid, D)>,

Implementors§