tendermint/abci/response/
end_block.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{abci::Event, consensus, prelude::*, serializers, validator};
4
5#[doc = include_str!("../doc/response-endblock.md")]
6#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
7pub struct EndBlock {
8    /// Changes to the validator set, if any.
9    ///
10    /// Setting the voting power to 0 removes a validator.
11    #[serde(with = "serializers::nullable")]
12    pub validator_updates: Vec<validator::Update>,
13    /// Changes to consensus parameters (optional).
14    pub consensus_param_updates: Option<consensus::Params>,
15    /// Events that occurred while ending the block.
16    #[serde(default)]
17    pub events: Vec<Event>,
18}
19
20// =============================================================================
21// Protobuf conversions
22// =============================================================================
23
24mod v0_34 {
25    use super::EndBlock;
26    use tendermint_proto::v0_34 as pb;
27    use tendermint_proto::Protobuf;
28
29    impl From<EndBlock> for pb::abci::ResponseEndBlock {
30        fn from(end_block: EndBlock) -> Self {
31            Self {
32                validator_updates: end_block
33                    .validator_updates
34                    .into_iter()
35                    .map(Into::into)
36                    .collect(),
37                consensus_param_updates: end_block.consensus_param_updates.map(Into::into),
38                events: end_block.events.into_iter().map(Into::into).collect(),
39            }
40        }
41    }
42
43    impl TryFrom<pb::abci::ResponseEndBlock> for EndBlock {
44        type Error = crate::Error;
45
46        fn try_from(end_block: pb::abci::ResponseEndBlock) -> Result<Self, Self::Error> {
47            Ok(Self {
48                validator_updates: end_block
49                    .validator_updates
50                    .into_iter()
51                    .map(TryInto::try_into)
52                    .collect::<Result<_, _>>()?,
53                consensus_param_updates: end_block
54                    .consensus_param_updates
55                    .map(TryInto::try_into)
56                    .transpose()?,
57                events: end_block
58                    .events
59                    .into_iter()
60                    .map(TryInto::try_into)
61                    .collect::<Result<_, _>>()?,
62            })
63        }
64    }
65
66    impl Protobuf<pb::abci::ResponseEndBlock> for EndBlock {}
67}
68
69mod v0_37 {
70    use super::EndBlock;
71    use tendermint_proto::v0_37 as pb;
72    use tendermint_proto::Protobuf;
73
74    impl From<EndBlock> for pb::abci::ResponseEndBlock {
75        fn from(end_block: EndBlock) -> Self {
76            Self {
77                validator_updates: end_block
78                    .validator_updates
79                    .into_iter()
80                    .map(Into::into)
81                    .collect(),
82                consensus_param_updates: end_block.consensus_param_updates.map(Into::into),
83                events: end_block.events.into_iter().map(Into::into).collect(),
84            }
85        }
86    }
87
88    impl TryFrom<pb::abci::ResponseEndBlock> for EndBlock {
89        type Error = crate::Error;
90
91        fn try_from(end_block: pb::abci::ResponseEndBlock) -> Result<Self, Self::Error> {
92            Ok(Self {
93                validator_updates: end_block
94                    .validator_updates
95                    .into_iter()
96                    .map(TryInto::try_into)
97                    .collect::<Result<_, _>>()?,
98                consensus_param_updates: end_block
99                    .consensus_param_updates
100                    .map(TryInto::try_into)
101                    .transpose()?,
102                events: end_block
103                    .events
104                    .into_iter()
105                    .map(TryInto::try_into)
106                    .collect::<Result<_, _>>()?,
107            })
108        }
109    }
110
111    impl Protobuf<pb::abci::ResponseEndBlock> for EndBlock {}
112}