mod bootstrap;
pub use bootstrap::*;
pub mod memory;
use std::fmt::Debug;
use tari_engine_types::substate::{Substate, SubstateId};
use tari_ootle_common_types::optional::IsNotFoundError;
pub trait StateReader {
fn get_state(&self, key: &SubstateId) -> Result<&Substate, StateStoreError>;
fn exists(&self, key: &SubstateId) -> Result<bool, StateStoreError>;
}
pub trait StateWriter: StateReader {
fn set_state(&mut self, key: SubstateId, value: Substate) -> Result<(), StateStoreError>;
}
#[derive(Debug, thiserror::Error)]
pub enum StateStoreError {
#[error("Non existent shard: {shard:?}")]
NonExistentShard { shard: Vec<u8> },
#[error("Error: {0}")]
CustomStr(String),
#[error("{kind} not found with key {key}")]
NotFound { kind: &'static str, key: String },
#[error("Substate has already been destroyed")]
SubstateDestroyed,
}
impl StateStoreError {
pub fn custom_str(e: &str) -> Self {
StateStoreError::CustomStr(e.to_string())
}
}
impl IsNotFoundError for StateStoreError {
fn is_not_found_error(&self) -> bool {
matches!(self, StateStoreError::NotFound { .. })
}
}