mod errors;
mod host;
mod merge;
mod noop;
mod proof;
mod stats;
pub use errors::SyncerError;
pub use host::HostReadSyncer;
pub use merge::merge_verified_subtree;
pub use noop::NoopReadSyncer;
pub use proof::{Proof, ProofBuilder, ProofVerifier, RawProofEntry};
pub use stats::StatsCollector;
use std::any::Any;
use anyhow::Result;
use crate::{
common::crypto::hash::Hash,
storage::mkvs::{tree::Root, Prefix},
};
#[derive(Clone, Debug, Default, PartialEq, Eq, cbor::Encode, cbor::Decode)]
pub struct TreeID {
pub root: Root,
pub position: Hash,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct GetRequest {
pub tree: TreeID,
pub key: Vec<u8>,
#[cbor(optional)]
pub include_siblings: bool,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct GetPrefixesRequest {
pub tree: TreeID,
pub prefixes: Vec<Prefix>,
pub limit: u16,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct IterateRequest {
pub tree: TreeID,
pub key: Vec<u8>,
pub prefetch: u16,
}
#[derive(Clone, Debug, Default, cbor::Encode, cbor::Decode)]
pub struct ProofResponse {
pub proof: Proof,
}
pub trait ReadSync {
fn as_any(&self) -> &dyn Any;
fn sync_get(&mut self, request: GetRequest) -> Result<ProofResponse>;
fn sync_get_prefixes(&mut self, request: GetPrefixesRequest) -> Result<ProofResponse>;
fn sync_iterate(&mut self, request: IterateRequest) -> Result<ProofResponse>;
}
#[cfg(test)]
mod test;