basecoin_store/
context.rs

1use core::fmt::Debug;
2
3use ics23::CommitmentProof;
4
5use crate::types::{Height, Path, RawHeight};
6use crate::utils::Async;
7
8/// Store trait - maybe provableStore or privateStore
9pub trait Store: Async + Clone {
10    /// Error type - expected to envelope all possible errors in store
11    type Error: Debug;
12
13    /// Set `value` for `path`
14    fn set(&mut self, path: Path, value: Vec<u8>) -> Result<Option<Vec<u8>>, Self::Error>;
15
16    /// Get associated `value` for `path` at specified `height`
17    fn get(&self, height: Height, path: &Path) -> Option<Vec<u8>>;
18
19    /// Delete specified `path`
20    // TODO(rano): return Result to denote success or failure
21    fn delete(&mut self, path: &Path);
22
23    /// Commit `Pending` block to canonical chain and create new `Pending`
24    fn commit(&mut self) -> Result<Vec<u8>, Self::Error>;
25
26    /// Apply accumulated changes to `Pending`
27    fn apply(&mut self) -> Result<(), Self::Error> {
28        Ok(())
29    }
30
31    /// Reset accumulated changes
32    fn reset(&mut self) {}
33
34    /// Prune historic blocks upto specified `height`
35    fn prune(&mut self, height: RawHeight) -> Result<RawHeight, Self::Error> {
36        Ok(height)
37    }
38
39    /// Return the current height of the chain
40    fn current_height(&self) -> RawHeight;
41
42    /// Return all keys that start with specified prefix
43    fn get_keys(&self, key_prefix: &Path) -> Vec<Path>; // TODO(hu55a1n1): implement support for all heights
44}
45
46/// ProvableStore trait
47pub trait ProvableStore: Store {
48    /// Return a vector commitment
49    fn root_hash(&self) -> Vec<u8>;
50
51    /// Return proof of existence for key
52    fn get_proof(&self, height: Height, key: &Path) -> Option<CommitmentProof>;
53}