cosmrs/tx/
auth_info.rs

1//! Auth info.
2
3use super::{Fee, SignerInfo};
4use crate::{
5    proto::{self, traits::MessageExt},
6    Error, ErrorReport, Result,
7};
8
9/// [`AuthInfo`] describes the fee and signer modes that are used to sign a transaction.
10// TODO(tarcieri): support for the `tip` field
11#[derive(Clone, Debug, Eq, PartialEq)]
12pub struct AuthInfo {
13    /// Defines the signing modes for the required signers.
14    ///
15    /// The number and order of elements must match the required signers from transaction
16    /// [`Body`][`super::Body`]’s messages. The first element is the primary signer and the one
17    /// which pays the [`Fee`].
18    pub signer_infos: Vec<SignerInfo>,
19
20    /// [`Fee`] and gas limit for the transaction.
21    ///
22    /// The first signer is the primary signer and the one which pays the fee.
23    /// The fee can be calculated based on the cost of evaluating the body and doing signature
24    /// verification of the signers. This can be estimated via simulation.
25    pub fee: Fee,
26}
27
28impl AuthInfo {
29    /// Convert to a Protocol Buffers representation.
30    pub fn into_proto(self) -> proto::cosmos::tx::v1beta1::AuthInfo {
31        self.into()
32    }
33
34    /// Encode this type using Protocol Buffers.
35    pub fn into_bytes(self) -> Result<Vec<u8>> {
36        Ok(self.into_proto().to_bytes()?)
37    }
38}
39
40impl TryFrom<proto::cosmos::tx::v1beta1::AuthInfo> for AuthInfo {
41    type Error = ErrorReport;
42
43    fn try_from(proto: proto::cosmos::tx::v1beta1::AuthInfo) -> Result<AuthInfo> {
44        Ok(AuthInfo {
45            signer_infos: proto
46                .signer_infos
47                .into_iter()
48                .map(TryFrom::try_from)
49                .collect::<Result<_, _>>()?,
50            fee: proto
51                .fee
52                .ok_or(Error::MissingField { name: "fee" })?
53                .try_into()?,
54        })
55    }
56}
57
58impl From<AuthInfo> for proto::cosmos::tx::v1beta1::AuthInfo {
59    fn from(auth_info: AuthInfo) -> proto::cosmos::tx::v1beta1::AuthInfo {
60        #[allow(deprecated)] // tip
61        proto::cosmos::tx::v1beta1::AuthInfo {
62            signer_infos: auth_info.signer_infos.into_iter().map(Into::into).collect(),
63            fee: Some(auth_info.fee.into()),
64            tip: None,
65        }
66    }
67}