diff --git a/lighthouse/db/mod.rs b/lighthouse/db/mod.rs index 33f97cc37..c85eaf18b 100644 --- a/lighthouse/db/mod.rs +++ b/lighthouse/db/mod.rs @@ -1,29 +1,11 @@ extern crate rocksdb; mod disk_db; +mod traits; pub use self::disk_db::DiskDB; - -type DBValue = Vec; - -#[derive(Debug)] -pub struct DBError { - message: String -} - -impl DBError { - pub fn new(message: String) -> Self { - Self { message } - } -} - -pub trait ClientDB: Sync + Send { - fn create_col(&mut self, col: &str) - -> Result<(), DBError>; - - fn get(&self, col: &str, key: &[u8]) - -> Result, DBError>; - - fn put(&self, col: &str, key: &[u8], val: &[u8]) - -> Result<(), DBError>; -} +pub use self::traits::{ + DBError, + DBValue, + ClientDB, +}; diff --git a/lighthouse/db/traits.rs b/lighthouse/db/traits.rs new file mode 100644 index 000000000..97759d3b7 --- /dev/null +++ b/lighthouse/db/traits.rs @@ -0,0 +1,30 @@ +pub type DBValue = Vec; + +#[derive(Debug)] +pub struct DBError { + pub message: String +} + +impl DBError { + pub fn new(message: String) -> Self { + Self { message } + } +} + +/// A generic database to be used by the "client' (i.e., +/// the lighthouse blockchain client). +/// +/// The purpose of having this generic trait is to allow the +/// program to use a persistent on-disk database during production, +/// but use a transient database during tests. +pub trait ClientDB: Sync + Send { + fn create_col(&mut self, col: &str) + -> Result<(), DBError>; + + fn get(&self, col: &str, key: &[u8]) + -> Result, DBError>; + + fn put(&self, col: &str, key: &[u8], val: &[u8]) + -> Result<(), DBError>; +} +