penumbra_proto/state/
write.rsuse crate::{event::ProtoEvent, DomainType, Message};
use std::fmt::Debug;
use cnidarium::StateWrite;
pub trait StateWriteProto: StateWrite + Send + Sync {
fn put<D>(&mut self, key: String, value: D)
where
D: DomainType,
anyhow::Error: From<<D as TryFrom<D::Proto>>::Error>,
{
self.put_proto(key, D::Proto::from(value));
}
fn put_proto<P>(&mut self, key: String, value: P)
where
P: Message + Default + Debug,
{
self.put_raw(key, value.encode_to_vec());
}
fn nonverifiable_put<D>(&mut self, key: Vec<u8>, value: D)
where
D: DomainType,
anyhow::Error: From<<D as TryFrom<D::Proto>>::Error>,
{
self.nonverifiable_put_raw(key, value.encode_to_vec());
}
fn nonverifiable_put_proto<P>(&mut self, key: Vec<u8>, value: P)
where
P: Message + Default + Debug,
{
self.nonverifiable_put_raw(key, value.encode_to_vec());
}
fn record_proto<E>(&mut self, proto_event: E)
where
E: ProtoEvent,
{
self.record(proto_event.into_event())
}
}
impl<T: StateWrite + ?Sized> StateWriteProto for T {}