tendermint/abci/request/
begin_block.rs

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
// bring into scope for doc links
#[allow(unused)]
use super::DeliverTx;
use crate::{
    abci::types::{CommitInfo, Misbehavior},
    block,
    prelude::*,
    Hash,
};

#[doc = include_str!("../doc/request-beginblock.md")]
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct BeginBlock {
    /// The block's hash.
    ///
    /// This can be derived from the block header.
    pub hash: Hash,
    /// The block header.
    pub header: block::Header,
    /// Information about the last commit.
    ///
    /// This includes the round, the list of validators, and which validators
    /// signed the last block.
    pub last_commit_info: CommitInfo,
    /// Evidence of validator misbehavior.
    pub byzantine_validators: Vec<Misbehavior>,
}

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

mod v0_34 {
    use super::BeginBlock;
    use crate::Error;
    use tendermint_proto::v0_34 as pb;
    use tendermint_proto::Protobuf;

    impl From<BeginBlock> for pb::abci::RequestBeginBlock {
        fn from(begin_block: BeginBlock) -> Self {
            Self {
                hash: begin_block.hash.into(),
                header: Some(begin_block.header.into()),
                last_commit_info: Some(begin_block.last_commit_info.into()),
                byzantine_validators: begin_block
                    .byzantine_validators
                    .into_iter()
                    .map(Into::into)
                    .collect(),
            }
        }
    }

    impl TryFrom<pb::abci::RequestBeginBlock> for BeginBlock {
        type Error = Error;

        fn try_from(begin_block: pb::abci::RequestBeginBlock) -> Result<Self, Self::Error> {
            Ok(Self {
                hash: begin_block.hash.try_into()?,
                header: begin_block
                    .header
                    .ok_or_else(Error::missing_header)?
                    .try_into()?,
                last_commit_info: begin_block
                    .last_commit_info
                    .ok_or_else(Error::missing_last_commit_info)?
                    .try_into()?,
                byzantine_validators: begin_block
                    .byzantine_validators
                    .into_iter()
                    .map(TryInto::try_into)
                    .collect::<Result<_, _>>()?,
            })
        }
    }

    impl Protobuf<pb::abci::RequestBeginBlock> for BeginBlock {}
}

mod v0_37 {
    use super::BeginBlock;
    use crate::Error;
    use tendermint_proto::v0_37 as pb;
    use tendermint_proto::Protobuf;

    impl From<BeginBlock> for pb::abci::RequestBeginBlock {
        fn from(begin_block: BeginBlock) -> Self {
            Self {
                hash: begin_block.hash.into(),
                header: Some(begin_block.header.into()),
                last_commit_info: Some(begin_block.last_commit_info.into()),
                byzantine_validators: begin_block
                    .byzantine_validators
                    .into_iter()
                    .map(Into::into)
                    .collect(),
            }
        }
    }

    impl TryFrom<pb::abci::RequestBeginBlock> for BeginBlock {
        type Error = Error;

        fn try_from(begin_block: pb::abci::RequestBeginBlock) -> Result<Self, Self::Error> {
            Ok(Self {
                hash: begin_block.hash.try_into()?,
                header: begin_block
                    .header
                    .ok_or_else(Error::missing_header)?
                    .try_into()?,
                last_commit_info: begin_block
                    .last_commit_info
                    .ok_or_else(Error::missing_last_commit_info)?
                    .try_into()?,
                byzantine_validators: begin_block
                    .byzantine_validators
                    .into_iter()
                    .map(TryInto::try_into)
                    .collect::<Result<_, _>>()?,
            })
        }
    }

    impl Protobuf<pb::abci::RequestBeginBlock> for BeginBlock {}
}