//! Test trait implementations for the Current QMDB. use super::{ BitmapPrunedBits, batch::{MerkleizedBatch, UnmerkleizedBatch}, db::Db, }; use crate::{ Context, index::{Ordered as OrderedIndex, Unordered as UnorderedIndex}, journal::contiguous::{Contiguous, Mutable}, merkle::{Graftable, Location}, qmdb::{ Error, any::{ operation::{Operation, Update, update}, traits::{ BatchableDb, DbAny, MerkleizedBatch as MerkleizedBatchTrait, UnmerkleizedBatch as UnmerkleizedBatchTrait, }, }, floor::Policy, operation::Key, value::ValueEncoding, }, }; use commonware_codec::Codec; use commonware_cryptography::{Digest, Hasher}; use commonware_parallel::Strategy; use commonware_runtime::Handle; use core::borrow::Borrow; use std::{ops::Range, sync::Arc}; impl BitmapPrunedBits for Db where F: Graftable, E: Context, C: Contiguous>, I: UnorderedIndex>, H: Hasher, U: Update, S: Strategy, Operation: Codec, { fn pruned_bits(&self) -> u64 { self.any.bitmap.pruned_bits() } fn get_bit(&self, index: u64) -> bool { self.any.bitmap.get_bit(index) } } impl UnmerkleizedBatchTrait, N, S>> for UnmerkleizedBatch, N, S> where F: Graftable, K: Key, V: ValueEncoding, H: Hasher, E: Context, C: Mutable>>, I: UnorderedIndex> + 'static, S: Strategy, Operation>: Codec, { type Family = F; type Key = K; type Value = V::Value; type Metadata = V::Value; type Merkleized = Arc, N, S>>; fn with_metadata(self, metadata: impl Into>) -> Self { Self::with_metadata(self, metadata) } fn write(self, key: K, value: Option) -> Self { Self::write(self, key, value) } async fn merkleize_with + Send>( self, db: &Db, N, S>, policy: &mut P, ) -> Result> { self.merkleize_with(db, policy).await } } impl UnmerkleizedBatchTrait, N, S>> for UnmerkleizedBatch, N, S> where F: Graftable, K: Key, V: ValueEncoding, H: Hasher, E: Context, C: Mutable>>, I: OrderedIndex> + 'static, S: Strategy, Operation>: Codec, { type Family = F; type Key = K; type Value = V::Value; type Metadata = V::Value; type Merkleized = Arc, N, S>>; fn with_metadata(self, metadata: impl Into>) -> Self { Self::with_metadata(self, metadata) } fn write(self, key: K, value: Option) -> Self { Self::write(self, key, value) } async fn merkleize_with + Send>( self, db: &Db, N, S>, policy: &mut P, ) -> Result> { self.merkleize_with(db, policy).await } } impl MerkleizedBatchTrait for Arc> where Operation: Codec, { type Digest = D; fn root(&self) -> D { MerkleizedBatch::root(self) } } impl BatchableDb for Db where F: Graftable, E: Context, C: Mutable>, I: UnorderedIndex> + 'static, H: Hasher, U: update::Update, S: Strategy, Operation: Codec, UnmerkleizedBatch: UnmerkleizedBatchTrait< Self, Family = F, Key = U::Key, Value = U::Value, Metadata = U::Value, Merkleized = Arc>, >, { type Family = F; type Key = U::Key; type Value = U::Value; type Merkleized = Arc>; type Batch = UnmerkleizedBatch; fn new_batch(&self) -> Self::Batch { self.new_batch() } fn apply_batch( self, batch: Self::Merkleized, ) -> impl Future>> { self.apply_batch(batch) } } impl DbAny for Db where F: Graftable, E: Context, C: Mutable>, I: UnorderedIndex>, H: Hasher, U: Update, S: Strategy, Operation: Codec, Self: BatchableDb, { type Digest = H::Digest; async fn get(&self, key: &U::Key) -> Result, Error> { Self::get(self, key).await } async fn get_many + Sync>( &self, keys: &[Q], ) -> Result>, Error> { Self::get_many(self, keys).await } fn root(&self) -> H::Digest { Self::root(self) } fn bounds(&self) -> Range> { Self::bounds(self) } async fn get_metadata(&self) -> Result, Error> { Self::get_metadata(self).await } async fn prune(self, loc: Location) -> Result> { Self::prune(self, loc).await } async fn start_sync(self) -> Result<(Self, Handle<()>), Error> { Self::start_sync(self).await } async fn commit(self) -> Result> { Self::commit(self).await } async fn sync(self) -> Result> { Self::sync(self).await } async fn destroy(self) -> Result<(), Error> { Self::destroy(self).await } fn inactivity_floor(&self) -> Location { Self::inactivity_floor(self) } fn sync_boundary(&self) -> Location { Self::sync_boundary(self) } }