commonware_sync/databases/
mod.rs1use crate::Key;
4use commonware_codec::Encode;
5use commonware_storage::{
6 mmr::{Location, Proof},
7 qmdb::{self, operation::Operation},
8};
9use std::{future::Future, num::NonZeroU64};
10
11pub mod any;
12pub mod current;
13pub mod immutable;
14
15#[derive(Debug, Clone, Copy)]
17pub enum DatabaseType {
18 Any,
19 Current,
20 Immutable,
21}
22
23impl std::str::FromStr for DatabaseType {
24 type Err = String;
25
26 fn from_str(s: &str) -> Result<Self, Self::Err> {
27 match s.to_lowercase().as_str() {
28 "any" => Ok(Self::Any),
29 "current" => Ok(Self::Current),
30 "immutable" => Ok(Self::Immutable),
31 _ => Err(format!(
32 "Invalid database type: '{s}'. Must be 'any', 'current', or 'immutable'",
33 )),
34 }
35 }
36}
37
38impl DatabaseType {
39 pub const fn as_str(&self) -> &'static str {
40 match self {
41 Self::Any => "any",
42 Self::Current => "current",
43 Self::Immutable => "immutable",
44 }
45 }
46}
47
48pub trait Syncable: Sized {
50 type Operation: Operation + Encode + Sync + 'static;
52
53 fn create_test_operations(count: usize, seed: u64) -> Vec<Self::Operation>;
56
57 fn add_operations(
60 &mut self,
61 operations: Vec<Self::Operation>,
62 ) -> impl Future<Output = Result<(), qmdb::Error>>;
63
64 fn root(&self) -> Key;
66
67 fn size(&self) -> impl Future<Output = Location> + Send;
69
70 fn inactivity_floor(&self) -> impl Future<Output = Location> + Send;
72
73 fn historical_proof(
75 &self,
76 op_count: Location,
77 start_loc: Location,
78 max_ops: NonZeroU64,
79 ) -> impl Future<Output = Result<(Proof<Key>, Vec<Self::Operation>), qmdb::Error>> + Send;
80
81 fn name() -> &'static str;
83}