Add skeleton for sled blockchain store.

This commit is contained in:
parazyd
2022-04-03 14:44:40 +02:00
parent 891add8c62
commit 0109aa0394
8 changed files with 63 additions and 0 deletions

View File

@@ -200,6 +200,10 @@ blockchain = [
"net",
]
blockchain2 = [
"sled",
]
system = [
"fxhash",
"rand",

View File

@@ -0,0 +1,12 @@
use crate::Result;
const SLED_BLOCK_TREE: &[u8] = b"_blocks";
pub struct BlockStore(sled::Tree);
impl BlockStore {
pub fn new(db: &sled::Db) -> Result<Self> {
let tree = db.open_tree(SLED_BLOCK_TREE)?;
Ok(Self(tree))
}
}

4
src/blockchain2/mod.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod blockstore;
pub mod nfstore;
pub mod rootstore;
pub mod txstore;

View File

@@ -0,0 +1,12 @@
use crate::Result;
const SLED_NULLIFIER_TREE: &[u8] = b"_nullifiers";
pub struct NullifierStore(sled::Tree);
impl NullifierStore {
pub fn new(db: &sled::Db) -> Result<Self> {
let tree = db.open_tree(SLED_NULLIFIER_TREE)?;
Ok(Self(tree))
}
}

View File

@@ -0,0 +1,12 @@
use crate::Result;
const SLED_ROOTS_TREE: &[u8] = b"_merkleroots";
pub struct RootStore(sled::Tree);
impl RootStore {
pub fn new(db: &sled::Db) -> Result<Self> {
let tree = db.open_tree(SLED_ROOTS_TREE)?;
Ok(Self(tree))
}
}

View File

@@ -0,0 +1,12 @@
use crate::Result;
const SLED_TX_TREE: &[u8] = b"_transactions";
pub struct TxStore(sled::Tree);
impl TxStore {
pub fn new(db: &sled::Db) -> Result<Self> {
let tree = db.open_tree(SLED_TX_TREE)?;
Ok(Self(tree))
}
}

View File

@@ -218,6 +218,10 @@ pub enum Error {
#[cfg(feature = "wasm-runtime")]
#[error("wasm runtime out of memory")]
WasmerOomError,
#[cfg(feature = "blockchain2")]
#[error(transparent)]
SledError(#[from] sled::Error),
}
#[cfg(feature = "node")]

View File

@@ -4,6 +4,9 @@ pub use error::{Error, Result};
#[cfg(feature = "blockchain")]
pub mod blockchain;
#[cfg(feature = "blockchain2")]
pub mod blockchain2;
#[cfg(feature = "blockchain")]
pub mod consensus;