فهرست منبع

blockchain: Implement wrapper Blockchain struct to take the stores.

parazyd 4 سال پیش
والد
کامیت
3018751d40
1فایلهای تغییر یافته به همراه25 افزوده شده و 0 حذف شده
  1. 25 0
      src/blockchain2/mod.rs

+ 25 - 0
src/blockchain2/mod.rs

@@ -11,6 +11,31 @@ pub mod nfstore;
 pub mod rootstore;
 pub mod txstore;
 
+use blockstore::BlockStore;
+use nfstore::NullifierStore;
+use rootstore::RootStore;
+use txstore::TxStore;
+
+pub struct Blockchain {
+    pub db: sled::Db,
+    pub blocks: BlockStore,
+    pub transactions: TxStore,
+    pub nullifiers: NullifierStore,
+    pub merkle_roots: RootStore,
+}
+
+impl Blockchain {
+    pub fn new(db_path: &str) -> Result<Self> {
+        let db = sled::open(db_path)?;
+        let blocks = BlockStore::new(&db)?;
+        let transactions = TxStore::new(&db)?;
+        let nullifiers = NullifierStore::new(&db)?;
+        let merkle_roots = RootStore::new(&db)?;
+
+        Ok(Self { db, blocks, transactions, nullifiers, merkle_roots })
+    }
+}
+
 impl Encodable for blake3::Hash {
     fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
         s.write_slice(self.as_bytes())?;