use core::error::Error;
use amplify::MultiError;
use sonicapi::SemanticError;
use ultrasonic::{CallError, CellAddr, ContractName, Operation, Opid};
use crate::{Articles, EffectiveState, Transition};
pub trait Stock {
type Conf;
type Error: Error;
fn new(articles: Articles, state: EffectiveState, conf: Self::Conf) -> Result<Self, Self::Error>
where Self: Sized;
fn load(conf: Self::Conf) -> Result<Self, Self::Error>
where Self: Sized;
fn config(&self) -> Self::Conf;
fn articles(&self) -> &Articles;
fn state(&self) -> &EffectiveState;
fn is_valid(&self, opid: Opid) -> bool;
fn mark_valid(&mut self, opid: Opid);
fn mark_invalid(&mut self, opid: Opid);
fn has_operation(&self, opid: Opid) -> bool;
fn operation_count(&self) -> u64;
fn operation(&self, opid: Opid) -> Operation;
fn operations(&self) -> impl Iterator<Item = (Opid, Operation)>;
fn transition(&self, opid: Opid) -> Transition;
fn trace(&self) -> impl Iterator<Item = (Opid, Transition)>;
fn read_by(&self, addr: CellAddr) -> impl Iterator<Item = Opid>;
fn spent_by(&self, addr: CellAddr) -> Option<Opid>;
fn update_articles(
&mut self,
f: impl FnOnce(&mut Articles) -> Result<bool, SemanticError>,
) -> Result<bool, MultiError<SemanticError, Self::Error>>;
fn update_state<R>(&mut self, f: impl FnOnce(&mut EffectiveState, &Articles) -> R) -> Result<R, Self::Error>;
fn add_operation(&mut self, opid: Opid, operation: &Operation);
fn add_transition(&mut self, opid: Opid, transition: &Transition);
fn add_reading(&mut self, addr: CellAddr, reader: Opid);
fn add_spending(&mut self, spent: CellAddr, spender: Opid);
fn commit_transaction(&mut self);
}
#[derive(Clone, PartialEq, Eq, Debug, Display, Error)]
#[display(doc_comments)]
pub enum IssueError {
Genesis(ContractName, CallError),
}