Add basic PoW chain db store

This commit is contained in:
Paul Hauner 2018-09-21 11:13:07 +10:00
parent 1065554216
commit d4e6f12ded
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 37 additions and 0 deletions

View File

@ -4,7 +4,10 @@ use super::{
}; };
mod block_store; mod block_store;
mod pow_chain_store;
pub use self::block_store::BlockStore; pub use self::block_store::BlockStore;
pub use self::pow_chain_store::PoWChainStore;
const BLOCKS_DB_COLUMN: &str = "blocks"; const BLOCKS_DB_COLUMN: &str = "blocks";
const POW_CHAIN_DB_COLUMN: &str = "powchain";

View File

@ -0,0 +1,34 @@
use std::sync::Arc;
use super::{
ClientDB,
DBError,
};
use super::POW_CHAIN_DB_COLUMN as DB_COLUMN;
pub struct PoWChainStore<T>
where T: ClientDB
{
db: Arc<T>,
}
impl<T: ClientDB> PoWChainStore<T> {
pub fn new(db: Arc<T>) -> 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<bool, DBError>
{
self.db.exists(DB_COLUMN, hash)
}
}
// TODO: add tests once a memory-db is implemented