From d4e6f12dedf4a63946b1f67d5d2c0fa7f258ffe8 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 21 Sep 2018 11:13:07 +1000 Subject: [PATCH] Add basic PoW chain db store --- lighthouse/db/stores/mod.rs | 3 +++ lighthouse/db/stores/pow_chain_store.rs | 34 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lighthouse/db/stores/pow_chain_store.rs diff --git a/lighthouse/db/stores/mod.rs b/lighthouse/db/stores/mod.rs index 9c564dd71b..0db6aba38f 100644 --- a/lighthouse/db/stores/mod.rs +++ b/lighthouse/db/stores/mod.rs @@ -4,7 +4,10 @@ use super::{ }; mod block_store; +mod pow_chain_store; pub use self::block_store::BlockStore; +pub use self::pow_chain_store::PoWChainStore; const BLOCKS_DB_COLUMN: &str = "blocks"; +const POW_CHAIN_DB_COLUMN: &str = "powchain"; diff --git a/lighthouse/db/stores/pow_chain_store.rs b/lighthouse/db/stores/pow_chain_store.rs new file mode 100644 index 0000000000..d428054764 --- /dev/null +++ b/lighthouse/db/stores/pow_chain_store.rs @@ -0,0 +1,34 @@ +use std::sync::Arc; +use super::{ + ClientDB, + DBError, +}; +use super::POW_CHAIN_DB_COLUMN as DB_COLUMN; + +pub struct PoWChainStore + where T: ClientDB +{ + db: Arc, +} + +impl PoWChainStore { + pub fn new(db: Arc) -> Self { + Self { + db, + } + } + + pub fn put_block_hash(&self, hash: &[u8]) + -> Result<(), DBError> + { + self.db.put(DB_COLUMN, hash, &vec![0]) + } + + pub fn block_hash_exists(&self, hash: &[u8]) + -> Result + { + self.db.exists(DB_COLUMN, hash) + } +} + +// TODO: add tests once a memory-db is implemented