1use crate::{event::ProtoEvent, DomainType, Message};
23use std::fmt::Debug;
45use cnidarium::StateWrite;
67pub trait StateWriteProto: StateWrite + Send + Sync {
8/// Puts a domain type into the verifiable key-value store with the given key.
9fn put<D>(&mut self, key: String, value: D)
10where
11D: DomainType,
12 anyhow::Error: From<<D as TryFrom<D::Proto>>::Error>,
13 {
14self.put_proto(key, D::Proto::from(value));
15 }
1617/// Puts a proto type into the verifiable key-value store with the given key.
18fn put_proto<P>(&mut self, key: String, value: P)
19where
20P: Message + Default + Debug,
21 {
22self.put_raw(key, value.encode_to_vec());
23 }
2425/// Puts a domain type into the nonverifiable key-value store with the given key
26fn nonverifiable_put<D>(&mut self, key: Vec<u8>, value: D)
27where
28D: DomainType,
29 anyhow::Error: From<<D as TryFrom<D::Proto>>::Error>,
30 {
31self.nonverifiable_put_raw(key, value.encode_to_vec());
32 }
3334/// Puts a proto type into the verifiable key-value store with the given key.
35fn nonverifiable_put_proto<P>(&mut self, key: Vec<u8>, value: P)
36where
37P: Message + Default + Debug,
38 {
39self.nonverifiable_put_raw(key, value.encode_to_vec());
40 }
4142/// Records a Protobuf message as a typed ABCI event.
43fn record_proto<E>(&mut self, proto_event: E)
44where
45E: ProtoEvent,
46 {
47self.record(proto_event.into_event())
48 }
49}
50impl<T: StateWrite + ?Sized> StateWriteProto for T {}