1use crate::CoreBlockStorage;
5use cid::Cid;
6use co_primitives::{Link, OptionLink, ReducerAction};
7
8pub trait Context {
10 fn storage(&self) -> &CoreBlockStorage;
12
13 fn payload(&self) -> Vec<u8>;
15
16 fn event(&self) -> Cid;
18
19 fn state(&self) -> Option<Cid>;
22
23 fn set_state(&mut self, cid: Cid);
25
26 fn write_diagnostic(&mut self, cid: Cid);
28}
29
30#[allow(async_fn_in_trait)]
31pub trait Reducer<A>
32where
33 Self: Sized,
34 A: Clone,
35{
36 async fn reduce(
37 state: OptionLink<Self>,
38 event: Link<ReducerAction<A>>,
39 storage: &CoreBlockStorage,
40 ) -> Result<Link<Self>, anyhow::Error>;
41}