1use core::fmt::Debug;
2use cosmrs::{proto::traits::TypeUrl, tx::MessageExt, Any};
3use std::fmt::Display;
4
5use super::error::ChainError;
6
7pub trait Msg:
8 Clone + Sized + TryFrom<Self::Proto, Error = Self::Err> + TryInto<Self::Proto, Error = Self::Err>
9{
10 type Proto: Default + MessageExt + Sized + TypeUrl;
12
13 type Err: From<ChainError> + Debug + Display;
15
16 fn from_any(any: &Any) -> Result<Self, Self::Err> {
18 Self::Proto::from_any(any)
19 .map_err(ChainError::prost_proto_decoding)?
20 .try_into()
21 }
22
23 fn to_any(&self) -> Result<Any, Self::Err> {
25 self.clone().into_any()
26 }
27
28 fn into_any(self) -> Result<Any, Self::Err> {
30 Ok(self
31 .try_into()?
32 .to_any()
33 .map_err(ChainError::prost_proto_encoding)?)
34 }
35}