use core::fmt::Debug;
use cosmrs::{proto::traits::TypeUrl, tx::MessageExt, Any};
use std::fmt::Display;
use super::error::ChainError;
pub trait Msg:
Clone + Sized + TryFrom<Self::Proto, Error = Self::Err> + TryInto<Self::Proto, Error = Self::Err>
{
type Proto: Default + MessageExt + Sized + TypeUrl;
type Err: From<ChainError> + Debug + Display;
fn from_any(any: &Any) -> Result<Self, Self::Err> {
Self::Proto::from_any(any)
.map_err(ChainError::prost_proto_decoding)?
.try_into()
}
fn to_any(&self) -> Result<Any, Self::Err> {
self.clone().into_any()
}
fn into_any(self) -> Result<Any, Self::Err> {
Ok(self
.try_into()?
.to_any()
.map_err(ChainError::prost_proto_encoding)?)
}
}