penumbra_sdk_proto/state/
write.rs

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