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§
Sourcefn get(&self, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>
fn get(&self, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>
Gets the block from the blockstore.
Sourcefn put_keyed(&self, k: &Cid<64>, block: &[u8]) -> Result<(), Error>
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§
Sourcefn has(&self, k: &Cid<64>) -> Result<bool, Error>
fn has(&self, k: &Cid<64>) -> Result<bool, Error>
Checks if the blockstore has the specified block.
Sourcefn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
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<(), Error>
fn put_many<D, I>(&self, blocks: I) -> Result<(), Error>
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();Sourcefn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
fn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
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.
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, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>
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>
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§impl<BS> Blockstore for &BSwhere
BS: Blockstore,
impl<BS> Blockstore for &BSwhere
BS: Blockstore,
fn get(&self, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>
fn put_keyed(&self, k: &Cid<64>, block: &[u8]) -> Result<(), Error>
fn has(&self, k: &Cid<64>) -> Result<bool, Error>
fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
fn put_many<D, I>(&self, blocks: I) -> Result<(), Error>
fn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
Source§impl<BS> Blockstore for Rc<BS>where
BS: Blockstore,
impl<BS> Blockstore for Rc<BS>where
BS: Blockstore,
fn get(&self, k: &Cid<64>) -> Result<Option<Vec<u8>>, Error>
fn put_keyed(&self, k: &Cid<64>, block: &[u8]) -> Result<(), Error>
fn has(&self, k: &Cid<64>) -> Result<bool, Error>
fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
fn put_many<D, I>(&self, blocks: I) -> Result<(), Error>
fn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
Source§impl<S, BS> Blockstore for ActorRuntime<S, BS>where
S: Syscalls,
BS: Blockstore,
Convenience impl encapsulating the blockstore functionality.
impl<S, BS> Blockstore for ActorRuntime<S, BS>where
S: Syscalls,
BS: Blockstore,
Convenience impl encapsulating the blockstore functionality.