cita_database/
database.rs1use crate::error::DatabaseError;
2use rocksdb::DBIterator;
3use std::result;
4
5pub type Result<T> = result::Result<T, DatabaseError>;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum DataCategory {
11 State,
13 Headers,
15 Bodies,
17 Extra,
19 Trace,
21 AccountBloom,
23 Other,
25}
26
27pub trait Database: Send + Sync {
28 fn get(&self, category: Option<DataCategory>, key: &[u8]) -> Result<Option<Vec<u8>>>;
29
30 fn get_batch(
31 &self,
32 category: Option<DataCategory>,
33 keys: &[Vec<u8>],
34 ) -> Result<Vec<Option<Vec<u8>>>>;
35
36 fn insert(&self, category: Option<DataCategory>, key: Vec<u8>, value: Vec<u8>) -> Result<()>;
37
38 fn insert_batch(
39 &self,
40 category: Option<DataCategory>,
41 keys: Vec<Vec<u8>>,
42 values: Vec<Vec<u8>>,
43 ) -> Result<()>;
44
45 fn contains(&self, category: Option<DataCategory>, key: &[u8]) -> Result<bool>;
46
47 fn remove(&self, category: Option<DataCategory>, key: &[u8]) -> Result<()>;
48
49 fn remove_batch(&self, category: Option<DataCategory>, keys: &[Vec<u8>]) -> Result<()>;
50
51 fn restore(&mut self, new_db: &str) -> Result<()>;
52
53 fn iterator(&self, category: Option<DataCategory>) -> Option<DBIterator>;
55
56 fn close(&mut self);
57 fn flush(&self) -> Result<()>;
58}