Просмотр исходного кода

Add skeleton for sled blockchain store.

parazyd 4 лет назад
Родитель
Сommit
0109aa0394

+ 4 - 0
Cargo.toml

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

+ 12 - 0
src/blockchain2/blockstore.rs

@@ -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 - 0
src/blockchain2/mod.rs

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

+ 12 - 0
src/blockchain2/nfstore.rs

@@ -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))
+    }
+}

+ 12 - 0
src/blockchain2/rootstore.rs

@@ -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))
+    }
+}

+ 12 - 0
src/blockchain2/txstore.rs

@@ -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))
+    }
+}

+ 4 - 0
src/error.rs

@@ -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")]

+ 3 - 0
src/lib.rs

@@ -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;