tendermint/abci/request/
prepare_proposal.rs

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