tendermint/abci/response/
begin_block.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{abci::Event, prelude::*};
4
5#[doc = include_str!("../doc/response-beginblock.md")]
6#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
7pub struct BeginBlock {
8    /// Events that occurred while beginning the block.
9    #[serde(default)]
10    pub events: Vec<Event>,
11}
12
13// =============================================================================
14// Protobuf conversions
15// =============================================================================
16
17mod v0_34 {
18    use super::BeginBlock;
19    use tendermint_proto::v0_34 as pb;
20    use tendermint_proto::Protobuf;
21
22    impl From<BeginBlock> for pb::abci::ResponseBeginBlock {
23        fn from(begin_block: BeginBlock) -> Self {
24            Self {
25                events: begin_block.events.into_iter().map(Into::into).collect(),
26            }
27        }
28    }
29
30    impl TryFrom<pb::abci::ResponseBeginBlock> for BeginBlock {
31        type Error = crate::Error;
32
33        fn try_from(begin_block: pb::abci::ResponseBeginBlock) -> Result<Self, Self::Error> {
34            Ok(Self {
35                events: begin_block
36                    .events
37                    .into_iter()
38                    .map(TryInto::try_into)
39                    .collect::<Result<_, _>>()?,
40            })
41        }
42    }
43
44    impl Protobuf<pb::abci::ResponseBeginBlock> for BeginBlock {}
45}
46
47mod v0_37 {
48    use super::BeginBlock;
49    use tendermint_proto::v0_37 as pb;
50    use tendermint_proto::Protobuf;
51
52    impl From<BeginBlock> for pb::abci::ResponseBeginBlock {
53        fn from(begin_block: BeginBlock) -> Self {
54            Self {
55                events: begin_block.events.into_iter().map(Into::into).collect(),
56            }
57        }
58    }
59
60    impl TryFrom<pb::abci::ResponseBeginBlock> for BeginBlock {
61        type Error = crate::Error;
62
63        fn try_from(begin_block: pb::abci::ResponseBeginBlock) -> Result<Self, Self::Error> {
64            Ok(Self {
65                events: begin_block
66                    .events
67                    .into_iter()
68                    .map(TryInto::try_into)
69                    .collect::<Result<_, _>>()?,
70            })
71        }
72    }
73
74    impl Protobuf<pb::abci::ResponseBeginBlock> for BeginBlock {}
75}