use super::{Fee, SignerInfo};
use crate::{
proto::{self, traits::MessageExt},
Error, ErrorReport, Result,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AuthInfo {
pub signer_infos: Vec<SignerInfo>,
pub fee: Fee,
}
impl AuthInfo {
pub fn into_proto(self) -> proto::cosmos::tx::v1beta1::AuthInfo {
self.into()
}
pub fn into_bytes(self) -> Result<Vec<u8>> {
Ok(self.into_proto().to_bytes()?)
}
}
impl TryFrom<proto::cosmos::tx::v1beta1::AuthInfo> for AuthInfo {
type Error = ErrorReport;
fn try_from(proto: proto::cosmos::tx::v1beta1::AuthInfo) -> Result<AuthInfo> {
Ok(AuthInfo {
signer_infos: proto
.signer_infos
.into_iter()
.map(TryFrom::try_from)
.collect::<Result<_, _>>()?,
fee: proto
.fee
.ok_or(Error::MissingField { name: "fee" })?
.try_into()?,
})
}
}
impl From<AuthInfo> for proto::cosmos::tx::v1beta1::AuthInfo {
fn from(auth_info: AuthInfo) -> proto::cosmos::tx::v1beta1::AuthInfo {
#[allow(deprecated)] proto::cosmos::tx::v1beta1::AuthInfo {
signer_infos: auth_info.signer_infos.into_iter().map(Into::into).collect(),
fee: Some(auth_info.fee.into()),
tip: None,
}
}
}