tendermint/abci/request/
process_proposal.rs

1use crate::prelude::*;
2use crate::{
3    abci::types::{CommitInfo, Misbehavior},
4    account, block, Hash, Time,
5};
6
7use bytes::Bytes;
8
9#[doc = include_str!("../doc/request-processproposal.md")]
10#[derive(Clone, Debug, PartialEq, Eq)]
11pub struct ProcessProposal {
12    /// txs is an array of transactions that will be included in a block,
13    /// sent to the app for possible modifications.
14    pub txs: Vec<Bytes>,
15    pub proposed_last_commit: Option<CommitInfo>,
16    pub misbehavior: Vec<Misbehavior>,
17    pub hash: Hash,
18    pub height: block::Height,
19    pub time: Time,
20    pub next_validators_hash: Hash,
21    /// address of the public key of the validator proposing the block.
22    pub proposer_address: account::Id,
23}
24
25// =============================================================================
26// Protobuf conversions
27// =============================================================================
28
29mod v0_37 {
30    use super::ProcessProposal;
31    use crate::{prelude::*, Error};
32    use tendermint_proto::v0_37::abci as pb;
33    use tendermint_proto::Protobuf;
34
35    impl From<ProcessProposal> for pb::RequestProcessProposal {
36        fn from(value: ProcessProposal) -> Self {
37            Self {
38                txs: value.txs,
39                proposed_last_commit: value.proposed_last_commit.map(Into::into),
40                misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
41                hash: value.hash.into(),
42                height: value.height.into(),
43                time: Some(value.time.into()),
44                next_validators_hash: value.next_validators_hash.into(),
45                proposer_address: value.proposer_address.into(),
46            }
47        }
48    }
49
50    impl TryFrom<pb::RequestProcessProposal> for ProcessProposal {
51        type Error = Error;
52
53        fn try_from(message: pb::RequestProcessProposal) -> Result<Self, Self::Error> {
54            let req = Self {
55                txs: message.txs,
56                proposed_last_commit: message
57                    .proposed_last_commit
58                    .map(TryInto::try_into)
59                    .transpose()?,
60                misbehavior: message
61                    .misbehavior
62                    .into_iter()
63                    .map(TryInto::try_into)
64                    .collect::<Result<Vec<_>, _>>()?,
65                hash: message.hash.try_into()?,
66                height: message.height.try_into()?,
67                time: message
68                    .time
69                    .ok_or_else(Error::missing_timestamp)?
70                    .try_into()?,
71                next_validators_hash: message.next_validators_hash.try_into()?,
72                proposer_address: message.proposer_address.try_into()?,
73            };
74            Ok(req)
75        }
76    }
77
78    impl Protobuf<pb::RequestProcessProposal> for ProcessProposal {}
79}
80
81mod v0_38 {
82    use super::ProcessProposal;
83    use crate::{prelude::*, Error};
84    use tendermint_proto::v0_38::abci as pb;
85    use tendermint_proto::Protobuf;
86
87    impl From<ProcessProposal> for pb::RequestProcessProposal {
88        fn from(value: ProcessProposal) -> Self {
89            Self {
90                txs: value.txs,
91                proposed_last_commit: value.proposed_last_commit.map(Into::into),
92                misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
93                hash: value.hash.into(),
94                height: value.height.into(),
95                time: Some(value.time.into()),
96                next_validators_hash: value.next_validators_hash.into(),
97                proposer_address: value.proposer_address.into(),
98            }
99        }
100    }
101
102    impl TryFrom<pb::RequestProcessProposal> for ProcessProposal {
103        type Error = Error;
104
105        fn try_from(message: pb::RequestProcessProposal) -> Result<Self, Self::Error> {
106            let req = Self {
107                txs: message.txs,
108                proposed_last_commit: message
109                    .proposed_last_commit
110                    .map(TryInto::try_into)
111                    .transpose()?,
112                misbehavior: message
113                    .misbehavior
114                    .into_iter()
115                    .map(TryInto::try_into)
116                    .collect::<Result<Vec<_>, _>>()?,
117                hash: message.hash.try_into()?,
118                height: message.height.try_into()?,
119                time: message
120                    .time
121                    .ok_or_else(Error::missing_timestamp)?
122                    .try_into()?,
123                next_validators_hash: message.next_validators_hash.try_into()?,
124                proposer_address: message.proposer_address.try_into()?,
125            };
126            Ok(req)
127        }
128    }
129
130    impl Protobuf<pb::RequestProcessProposal> for ProcessProposal {}
131}