|
|
@@ -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())?;
|