pub use super::block::*;
unsafe impl lmdb::traits::LmdbRaw for Block<'static> {}
unsafe impl lmdb::traits::LmdbRaw for BlockHeader {}
unsafe impl lmdb::traits::LmdbOrdKey for Block<'static> {}
impl Blockchain<'_> {
pub fn get_tip(&self) {
}
}
pub fn init_blockchain(db_name: &'static str) -> Result<Blockchain, lmdb::Error> {
let db: lmdb::Database = get_lmdb_connection(db_name)?;
let tx = lmdb::ReadTransaction::new(db.env())?;
let blockchain = Blockchain::default();
let _curs = tx.cursor(&db).unwrap();
let _access = tx.access();
Ok(blockchain)
}
pub fn get_lmdb_connection(env: &'static str) -> Result<lmdb::Database, lmdb::Error> {
std::fs::create_dir_all(env).unwrap();
let db_env: lmdb::Environment =
unsafe { lmdb::EnvBuilder::new()?.open(&env, lmdb::open::Flags::empty(), 0o600)? };
let ops = lmdb::DatabaseOptions::create_map::<Block>();
let db: lmdb::Database = lmdb::Database::open(db_env, None, &ops)?;
Ok(db)
}