Skip to main content

Blockstore

Trait Blockstore 

Source
pub trait Blockstore {
    // Required methods
    fn get(&self, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>;
    fn put_keyed(&self, k: &Cid<64>, block: &[u8]) -> Result<(), Error>;

    // Provided methods
    fn has(&self, k: &Cid<64>) -> Result<bool, Error> { ... }
    fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
       where Self: Sized,
             D: AsRef<[u8]> { ... }
    fn put_many<D, I>(&self, blocks: I) -> Result<(), Error>
       where Self: Sized,
             D: AsRef<[u8]>,
             I: IntoIterator<Item = (Code, Block<D>)> { ... }
    fn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
       where Self: Sized,
             D: AsRef<[u8]>,
             I: IntoIterator<Item = (Cid<64>, 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<64>) -> Result<Option<Vec<u8>>, Error>

Gets the block from the blockstore.

Source

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

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<64>) -> Result<bool, Error>

Checks if the blockstore has the specified block.

Source

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
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<(), Error>
where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

Bulk put blocks into the blockstore.

use multihash_codetable::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<(), Error>
where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid<64>, D)>,

Bulk-put pre-keyed blocks into the blockstore.

By default, this defers to put_keyed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Blockstore for Blockstore

Blockstore implementation is borrowed from the builtin actors. This impl will likely be made redundant if low-level SDKs export blockstore implementations.

Source§

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

Source§

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

Source§

fn put<D>(&self, code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
where D: AsRef<[u8]>,

Source§

impl Blockstore for SharedMemoryBlockstore

Source§

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

Gets the block from the blockstore.

Source§

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

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.

Source§

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

Checks if the blockstore has the specified block.

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<S, BS> Blockstore for ActorRuntime<S, BS>
where S: Syscalls, BS: Blockstore,

Convenience impl encapsulating the blockstore functionality.

Source§

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

Source§

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

Implementors§