blockchain_rocksdb/
lib.rs

1mod utils;
2mod settlement;
3mod backend;
4
5pub use self::backend::RocksBackend;
6
7use std::{fmt, error as stderror};
8use std::sync::Arc;
9use parity_codec::{Encode, Decode};
10use rocksdb::DB;
11use blockchain::backend::OperationError;
12
13#[derive(Debug)]
14/// RocksDB backend errors
15pub enum Error {
16	/// Invalid Operation
17	InvalidOperation,
18	/// Trying to import a block that is genesis
19	IsGenesis,
20	/// Query does not exist
21	NotExist,
22	/// Corrupted database,
23	Corrupted,
24	/// RocksDB errors
25	Rocks(rocksdb::Error),
26}
27
28impl From<rocksdb::Error> for Error {
29	fn from(error: rocksdb::Error) -> Error {
30		Error::Rocks(error)
31	}
32}
33
34impl OperationError for Error {
35	fn invalid_operation() -> Self {
36		Error::InvalidOperation
37	}
38
39	fn block_is_genesis() -> Self {
40		Error::IsGenesis
41	}
42}
43
44impl fmt::Display for Error {
45	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46		write!(f, "{:?}", self)
47	}
48}
49
50impl stderror::Error for Error { }
51
52impl From<Error> for blockchain::import::Error {
53	fn from(error: Error) -> Self {
54		match error {
55			Error::IsGenesis => blockchain::import::Error::IsGenesis,
56			error => blockchain::import::Error::Backend(Box::new(error)),
57		}
58	}
59}
60
61pub trait RocksState {
62	type Raw: Encode + Decode;
63
64	fn from_raw(raw: Self::Raw, db: Arc<DB>) -> Self;
65	fn into_raw(self) -> Self::Raw;
66}