use std::{any::Any, sync::Arc};
use ed25519_dalek::SigningKey;
use handle_trait::Handle;
use crate::{
Result,
backend::{BackendImpl, VerificationStatus},
entry::{Entry, ID},
};
#[derive(Clone, Handle)]
pub struct Backend {
backend_impl: Arc<dyn BackendImpl>,
}
impl Backend {
pub fn new(backend_impl: Arc<dyn BackendImpl>) -> Self {
Self { backend_impl }
}
pub fn get(&self, id: &ID) -> Result<Entry> {
self.backend_impl.get(id)
}
pub fn get_verification_status(&self, id: &ID) -> Result<VerificationStatus> {
self.backend_impl.get_verification_status(id)
}
pub fn put(&self, verification: VerificationStatus, entry: Entry) -> Result<()> {
self.backend_impl.put(verification, entry)
}
pub fn put_verified(&self, entry: Entry) -> Result<()> {
self.backend_impl.put_verified(entry)
}
pub fn put_unverified(&self, entry: Entry) -> Result<()> {
self.backend_impl.put_unverified(entry)
}
pub fn update_verification_status(&self, id: &ID, status: VerificationStatus) -> Result<()> {
self.backend_impl.update_verification_status(id, status)
}
pub fn get_entries_by_verification_status(
&self,
status: VerificationStatus,
) -> Result<Vec<ID>> {
self.backend_impl.get_entries_by_verification_status(status)
}
pub fn get_tips(&self, tree: &ID) -> Result<Vec<ID>> {
self.backend_impl.get_tips(tree)
}
pub fn get_store_tips(&self, tree: &ID, store: &str) -> Result<Vec<ID>> {
self.backend_impl.get_store_tips(tree, store)
}
pub fn get_store_tips_up_to_entries(
&self,
tree: &ID,
store: &str,
up_to: &[ID],
) -> Result<Vec<ID>> {
self.backend_impl
.get_store_tips_up_to_entries(tree, store, up_to)
}
pub fn all_roots(&self) -> Result<Vec<ID>> {
self.backend_impl.all_roots()
}
pub fn find_lca(&self, tree: &ID, store: &str, entry_ids: &[ID]) -> Result<ID> {
self.backend_impl.find_lca(tree, store, entry_ids)
}
pub fn collect_root_to_target(&self, tree: &ID, store: &str, target: &ID) -> Result<Vec<ID>> {
self.backend_impl
.collect_root_to_target(tree, store, target)
}
pub fn get_tree(&self, tree: &ID) -> Result<Vec<Entry>> {
self.backend_impl.get_tree(tree)
}
pub fn get_store(&self, tree: &ID, store: &str) -> Result<Vec<Entry>> {
self.backend_impl.get_store(tree, store)
}
pub fn get_tree_from_tips(&self, tree: &ID, tips: &[ID]) -> Result<Vec<Entry>> {
self.backend_impl.get_tree_from_tips(tree, tips)
}
pub fn get_store_from_tips(&self, tree: &ID, store: &str, tips: &[ID]) -> Result<Vec<Entry>> {
self.backend_impl.get_store_from_tips(tree, store, tips)
}
pub fn store_private_key(&self, key_name: &str, private_key: SigningKey) -> Result<()> {
self.backend_impl.store_private_key(key_name, private_key)
}
pub fn get_private_key(&self, key_name: &str) -> Result<Option<SigningKey>> {
self.backend_impl.get_private_key(key_name)
}
pub fn list_private_keys(&self) -> Result<Vec<String>> {
self.backend_impl.list_private_keys()
}
pub fn remove_private_key(&self, key_name: &str) -> Result<()> {
self.backend_impl.remove_private_key(key_name)
}
pub fn get_cached_crdt_state(&self, entry_id: &ID, store: &str) -> Result<Option<String>> {
self.backend_impl.get_cached_crdt_state(entry_id, store)
}
pub fn cache_crdt_state(&self, entry_id: &ID, store: &str, state: String) -> Result<()> {
self.backend_impl.cache_crdt_state(entry_id, store, state)
}
pub fn clear_crdt_cache(&self) -> Result<()> {
self.backend_impl.clear_crdt_cache()
}
pub fn get_sorted_store_parents(
&self,
tree_id: &ID,
entry_id: &ID,
store: &str,
) -> Result<Vec<ID>> {
self.backend_impl
.get_sorted_store_parents(tree_id, entry_id, store)
}
pub fn get_path_from_to(
&self,
tree_id: &ID,
store: &str,
from_id: &ID,
to_ids: &[ID],
) -> Result<Vec<ID>> {
self.backend_impl
.get_path_from_to(tree_id, store, from_id, to_ids)
}
pub fn as_backend_impl(&self) -> &dyn BackendImpl {
&*self.backend_impl
}
pub fn as_arc_backend_impl(&self) -> &Arc<dyn BackendImpl> {
&self.backend_impl
}
pub fn as_any(&self) -> &dyn Any {
self.backend_impl.as_any()
}
}