mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
blockchain: nfstore and rootstore stubs.
This commit is contained in:
@@ -29,9 +29,10 @@ pub struct Blockchain {
|
||||
pub transactions: TxStore,
|
||||
/// Streamlet metadata sled tree
|
||||
pub streamlet_metadata: StreamletMetadataStore,
|
||||
// TODO:
|
||||
//pub nullifiers: NullifierStore,
|
||||
//pub merkle_roots: RootStore,
|
||||
/// Nullifiers sled tree
|
||||
pub nullifiers: NullifierStore,
|
||||
/// Merkle roots sled tree
|
||||
pub merkle_roots: RootStore,
|
||||
}
|
||||
|
||||
impl Blockchain {
|
||||
@@ -39,8 +40,10 @@ impl Blockchain {
|
||||
let blocks = BlockStore::new(db, genesis_ts, genesis_data)?;
|
||||
let transactions = TxStore::new(db)?;
|
||||
let streamlet_metadata = StreamletMetadataStore::new(db)?;
|
||||
let nullifiers = NullifierStore::new(db)?;
|
||||
let merkle_roots = RootStore::new(db)?;
|
||||
|
||||
Ok(Self { blocks, transactions, streamlet_metadata })
|
||||
Ok(Self { blocks, transactions, streamlet_metadata, nullifiers, merkle_roots })
|
||||
}
|
||||
|
||||
/// Batch insert [`BlockProposal`]s.
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
use crate::Result;
|
||||
use sled::Batch;
|
||||
|
||||
use crate::{crypto::nullifier::Nullifier, util::serial::serialize, Result};
|
||||
|
||||
const SLED_NULLIFIER_TREE: &[u8] = b"_nullifiers";
|
||||
|
||||
pub struct NullifierStore(sled::Tree);
|
||||
|
||||
impl NullifierStore {
|
||||
/// Opens a new or existing `NullifierStore` on the given sled database.
|
||||
pub fn new(db: &sled::Db) -> Result<Self> {
|
||||
let tree = db.open_tree(SLED_NULLIFIER_TREE)?;
|
||||
Ok(Self(tree))
|
||||
}
|
||||
|
||||
/// Insert a slice of [`Nullifier`] into the nullifier store.
|
||||
pub fn insert(&self, nullifiers: &[Nullifier]) -> Result<()> {
|
||||
let mut batch = Batch::default();
|
||||
for i in nullifiers {
|
||||
batch.insert(serialize(i), vec![] as Vec<u8>);
|
||||
}
|
||||
|
||||
self.0.apply_batch(batch)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
use crate::Result;
|
||||
use sled::Batch;
|
||||
|
||||
use crate::{crypto::merkle_node::MerkleNode, util::serial::serialize, Result};
|
||||
|
||||
const SLED_ROOTS_TREE: &[u8] = b"_merkleroots";
|
||||
|
||||
pub struct RootStore(sled::Tree);
|
||||
|
||||
impl RootStore {
|
||||
/// Opens a new or existing `RootStore` on the given sled database.
|
||||
pub fn new(db: &sled::Db) -> Result<Self> {
|
||||
let tree = db.open_tree(SLED_ROOTS_TREE)?;
|
||||
Ok(Self(tree))
|
||||
}
|
||||
|
||||
/// Insert a slice of [`MerkleNode`] on the given sled database.
|
||||
pub fn insert(&self, roots: &[MerkleNode]) -> Result<()> {
|
||||
let mut batch = Batch::default();
|
||||
for i in roots {
|
||||
batch.insert(serialize(i), vec![] as Vec<u8>);
|
||||
}
|
||||
|
||||
self.0.apply_batch(batch)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user