casper_storage/block_store/
block_provider.rs

1use super::error::BlockStoreError;
2
3/// A block store that supports read/write operations consistently.
4pub trait BlockStoreProvider {
5    /// Reader alias.
6    type Reader<'a>: BlockStoreTransaction
7    where
8        Self: 'a;
9    /// ReaderWriter alias.
10    type ReaderWriter<'a>: BlockStoreTransaction
11    where
12        Self: 'a;
13
14    /// Check out read only handle.
15    fn checkout_ro(&self) -> Result<Self::Reader<'_>, BlockStoreError>;
16    /// Check out read write handle.
17    fn checkout_rw(&mut self) -> Result<Self::ReaderWriter<'_>, BlockStoreError>;
18}
19
20/// Block store transaction.
21pub trait BlockStoreTransaction {
22    /// Commit changes to the block store.
23    fn commit(self) -> Result<(), BlockStoreError>;
24
25    /// Roll back any temporary changes to the block store.
26    fn rollback(self);
27}
28
29/// Data reader definition.
30pub trait DataReader<K, T> {
31    /// Read item at key.
32    fn read(&self, key: K) -> Result<Option<T>, BlockStoreError>;
33    /// Returns true if item exists at key, else false.
34    fn exists(&self, key: K) -> Result<bool, BlockStoreError>;
35}
36
37/// Data write definition.
38pub trait DataWriter<K, T> {
39    /// Write item to store and return key.
40    fn write(&mut self, data: &T) -> Result<K, BlockStoreError>;
41    /// Delete item at key from store.
42    fn delete(&mut self, key: K) -> Result<(), BlockStoreError>;
43}