pub use crate::runtime_api::StatementSource;
use crate::{Hash, Statement, Topic};
#[derive(Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
#[error("Database error: {0:?}")]
Db(String),
#[error("Error decoding statement: {0:?}")]
Decode(String),
#[error("Error calling into the runtime")]
Runtime,
}
#[derive(Debug, PartialEq, Eq)]
pub enum NetworkPriority {
High,
Low,
}
#[derive(Debug, Eq, PartialEq)]
pub enum SubmitResult {
New(NetworkPriority),
Known,
KnownExpired,
Ignored,
Bad(&'static str),
InternalError(Error),
}
pub type Result<T> = std::result::Result<T, Error>;
pub trait StatementStore: Send + Sync {
fn statements(&self) -> Result<Vec<(Hash, Statement)>>;
fn take_recent_statements(&self) -> Result<Vec<(Hash, Statement)>>;
fn statement(&self, hash: &Hash) -> Result<Option<Statement>>;
fn has_statement(&self, hash: &Hash) -> bool;
fn broadcasts(&self, match_all_topics: &[Topic]) -> Result<Vec<Vec<u8>>>;
fn posted(&self, match_all_topics: &[Topic], dest: [u8; 32]) -> Result<Vec<Vec<u8>>>;
fn posted_clear(&self, match_all_topics: &[Topic], dest: [u8; 32]) -> Result<Vec<Vec<u8>>>;
fn broadcasts_stmt(&self, match_all_topics: &[Topic]) -> Result<Vec<Vec<u8>>>;
fn posted_stmt(&self, match_all_topics: &[Topic], dest: [u8; 32]) -> Result<Vec<Vec<u8>>>;
fn posted_clear_stmt(&self, match_all_topics: &[Topic], dest: [u8; 32])
-> Result<Vec<Vec<u8>>>;
fn submit(&self, statement: Statement, source: StatementSource) -> SubmitResult;
fn remove(&self, hash: &Hash) -> Result<()>;
fn remove_by(&self, who: [u8; 32]) -> Result<()>;
}