tendermint/abci/request/
extend_vote.rs

1use bytes::Bytes;
2
3use crate::abci::types::{CommitInfo, Misbehavior};
4use crate::prelude::*;
5use crate::{account, block, Hash, Time};
6
7#[doc = include_str!("../doc/request-extendvote.md")]
8#[derive(Clone, PartialEq, Eq, Debug)]
9pub struct ExtendVote {
10    pub hash: Hash,
11    pub height: block::Height,
12    pub time: Time,
13    pub txs: Vec<Bytes>,
14    pub proposed_last_commit: Option<CommitInfo>,
15    pub misbehavior: Vec<Misbehavior>,
16    pub next_validators_hash: Hash,
17    pub proposer_address: account::Id,
18}
19
20// =============================================================================
21// Protobuf conversions
22// =============================================================================
23
24mod v0_38 {
25    use super::ExtendVote;
26    use crate::{prelude::*, Error};
27    use tendermint_proto::v0_38 as pb;
28    use tendermint_proto::Protobuf;
29
30    impl From<ExtendVote> for pb::abci::RequestExtendVote {
31        fn from(extend_vote: ExtendVote) -> Self {
32            Self {
33                hash: extend_vote.hash.into(),
34                height: extend_vote.height.into(),
35                time: Some(extend_vote.time.into()),
36                txs: extend_vote.txs,
37                proposed_last_commit: extend_vote.proposed_last_commit.map(Into::into),
38                misbehavior: extend_vote
39                    .misbehavior
40                    .into_iter()
41                    .map(Into::into)
42                    .collect(),
43                next_validators_hash: extend_vote.next_validators_hash.into(),
44                proposer_address: extend_vote.proposer_address.into(),
45            }
46        }
47    }
48
49    impl TryFrom<pb::abci::RequestExtendVote> for ExtendVote {
50        type Error = Error;
51
52        fn try_from(message: pb::abci::RequestExtendVote) -> Result<Self, Self::Error> {
53            Ok(Self {
54                hash: message.hash.try_into()?,
55                height: message.height.try_into()?,
56                time: message
57                    .time
58                    .ok_or_else(Error::missing_timestamp)?
59                    .try_into()?,
60                txs: message.txs,
61                proposed_last_commit: message
62                    .proposed_last_commit
63                    .map(TryInto::try_into)
64                    .transpose()?,
65                misbehavior: message
66                    .misbehavior
67                    .into_iter()
68                    .map(TryInto::try_into)
69                    .collect::<Result<Vec<_>, _>>()?,
70                next_validators_hash: message.next_validators_hash.try_into()?,
71                proposer_address: message.proposer_address.try_into()?,
72            })
73        }
74    }
75
76    impl Protobuf<pb::abci::RequestExtendVote> for ExtendVote {}
77}