use crate::CoreBlockStorage;
use cid::Cid;
use co_primitives::{Link, OptionLink, ReducerAction};
pub trait Context {
fn storage(&self) -> &CoreBlockStorage;
fn payload(&self) -> Vec<u8>;
fn event(&self) -> Cid;
fn state(&self) -> Option<Cid>;
fn set_state(&mut self, cid: Cid);
fn write_diagnostic(&mut self, cid: Cid);
}
#[allow(async_fn_in_trait)]
pub trait Reducer<A>
where
Self: Sized,
A: Clone,
{
async fn reduce(
state: OptionLink<Self>,
event: Link<ReducerAction<A>>,
storage: &CoreBlockStorage,
) -> Result<Link<Self>, anyhow::Error>;
}