1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::prelude::*;
use crate::{
    abci::types::{ExtendedCommitInfo, Misbehavior},
    account, block, Hash, Time,
};

use bytes::Bytes;

#[doc = include_str!("../doc/request-prepareproposal.md")]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PrepareProposal {
    /// the modified transactions cannot exceed this size.
    pub max_tx_bytes: i64,
    /// txs is an array of transactions that will be included in a block,
    /// sent to the app for possible modifications.
    pub txs: Vec<Bytes>,
    pub local_last_commit: Option<ExtendedCommitInfo>,
    pub misbehavior: Vec<Misbehavior>,
    pub height: block::Height,
    pub time: Time,
    pub next_validators_hash: Hash,
    /// address of the public key of the validator proposing the block.
    pub proposer_address: account::Id,
}

// =============================================================================
// Protobuf conversions
// =============================================================================

mod v0_37 {
    use super::PrepareProposal;
    use crate::{prelude::*, Error};
    use tendermint_proto::v0_37::abci as pb;
    use tendermint_proto::Protobuf;

    impl From<PrepareProposal> for pb::RequestPrepareProposal {
        fn from(value: PrepareProposal) -> Self {
            Self {
                max_tx_bytes: value.max_tx_bytes,
                txs: value.txs,
                local_last_commit: value.local_last_commit.map(Into::into),
                misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
                height: value.height.into(),
                time: Some(value.time.into()),
                next_validators_hash: value.next_validators_hash.into(),
                proposer_address: value.proposer_address.into(),
            }
        }
    }

    impl TryFrom<pb::RequestPrepareProposal> for PrepareProposal {
        type Error = Error;

        fn try_from(message: pb::RequestPrepareProposal) -> Result<Self, Self::Error> {
            let req = Self {
                max_tx_bytes: message.max_tx_bytes,
                txs: message.txs,
                local_last_commit: message
                    .local_last_commit
                    .map(TryInto::try_into)
                    .transpose()?,
                misbehavior: message
                    .misbehavior
                    .into_iter()
                    .map(TryInto::try_into)
                    .collect::<Result<Vec<_>, _>>()?,
                height: message.height.try_into()?,
                time: message
                    .time
                    .ok_or_else(Error::missing_timestamp)?
                    .try_into()?,
                next_validators_hash: message.next_validators_hash.try_into()?,
                proposer_address: message.proposer_address.try_into()?,
            };
            Ok(req)
        }
    }

    impl Protobuf<pb::RequestPrepareProposal> for PrepareProposal {}
}

mod v0_38 {
    use super::PrepareProposal;
    use crate::{prelude::*, Error};
    use tendermint_proto::v0_38::abci as pb;
    use tendermint_proto::Protobuf;

    impl From<PrepareProposal> for pb::RequestPrepareProposal {
        fn from(value: PrepareProposal) -> Self {
            Self {
                max_tx_bytes: value.max_tx_bytes,
                txs: value.txs,
                local_last_commit: value.local_last_commit.map(Into::into),
                misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
                height: value.height.into(),
                time: Some(value.time.into()),
                next_validators_hash: value.next_validators_hash.into(),
                proposer_address: value.proposer_address.into(),
            }
        }
    }

    impl TryFrom<pb::RequestPrepareProposal> for PrepareProposal {
        type Error = Error;

        fn try_from(message: pb::RequestPrepareProposal) -> Result<Self, Self::Error> {
            let req = Self {
                max_tx_bytes: message.max_tx_bytes,
                txs: message.txs,
                local_last_commit: message
                    .local_last_commit
                    .map(TryInto::try_into)
                    .transpose()?,
                misbehavior: message
                    .misbehavior
                    .into_iter()
                    .map(TryInto::try_into)
                    .collect::<Result<Vec<_>, _>>()?,
                height: message.height.try_into()?,
                time: message
                    .time
                    .ok_or_else(Error::missing_timestamp)?
                    .try_into()?,
                next_validators_hash: message.next_validators_hash.try_into()?,
                proposer_address: message.proposer_address.try_into()?,
            };
            Ok(req)
        }
    }

    impl Protobuf<pb::RequestPrepareProposal> for PrepareProposal {}
}