From 26af5447e96a441135958ceb16ebd80edb31fa32 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Wed, 27 Mar 2024 19:01:45 -0400 Subject: [PATCH] impl StagedWriteBatch getters --- crates/cnidarium/src/storage.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/cnidarium/src/storage.rs b/crates/cnidarium/src/storage.rs index 500245c8d7..ca5108fcf4 100644 --- a/crates/cnidarium/src/storage.rs +++ b/crates/cnidarium/src/storage.rs @@ -46,6 +46,9 @@ struct Inner { db: Arc, } +/// A staged write batch that can be committed to RocksDB. +/// +/// This allows for write batches to be prepared and committed at a later time. pub struct StagedWriteBatch { /// The write batch to commit to RocksDB. pub(crate) write_batch: rocksdb::WriteBatch, @@ -65,6 +68,18 @@ pub struct StagedWriteBatch { pub(crate) changes: Arc, } +impl StagedWriteBatch { + /// Returns the new version of the chain state corresponding to this set of changes. + pub fn version(&self) -> jmt::Version { + self.version + } + + /// Returns the root hash of the jmt corresponding to this set of changes. + pub fn root_hash(&self) -> &RootHash { + &self.root_hash + } +} + impl Storage { /// Loads a storage instance from the given path, initializing it if necessary. pub async fn load(path: PathBuf, default_prefixes: Vec) -> Result {