celestia_core/abci/request/
begin_block.rs

1// bring into scope for doc links
2#[allow(unused)]
3use super::DeliverTx;
4use crate::{
5    abci::types::{CommitInfo, Misbehavior},
6    block,
7    prelude::*,
8    Hash,
9};
10
11#[doc = include_str!("../doc/request-beginblock.md")]
12#[derive(Clone, PartialEq, Eq, Debug)]
13pub struct BeginBlock {
14    /// The block's hash.
15    ///
16    /// This can be derived from the block header.
17    pub hash: Hash,
18    /// The block header.
19    pub header: block::Header,
20    /// Information about the last commit.
21    ///
22    /// This includes the round, the list of validators, and which validators
23    /// signed the last block.
24    pub last_commit_info: CommitInfo,
25    /// Evidence of validator misbehavior.
26    pub byzantine_validators: Vec<Misbehavior>,
27}
28
29// =============================================================================
30// Protobuf conversions
31// =============================================================================
32
33tendermint_pb_modules! {
34    use super::BeginBlock;
35    use crate::Error;
36
37    impl From<BeginBlock> for pb::abci::RequestBeginBlock {
38        fn from(begin_block: BeginBlock) -> Self {
39            Self {
40                hash: begin_block.hash.into(),
41                header: Some(begin_block.header.into()),
42                last_commit_info: Some(begin_block.last_commit_info.into()),
43                byzantine_validators: begin_block
44                    .byzantine_validators
45                    .into_iter()
46                    .map(Into::into)
47                    .collect(),
48            }
49        }
50    }
51
52    impl TryFrom<pb::abci::RequestBeginBlock> for BeginBlock {
53        type Error = Error;
54
55        fn try_from(begin_block: pb::abci::RequestBeginBlock) -> Result<Self, Self::Error> {
56            Ok(Self {
57                hash: begin_block.hash.try_into()?,
58                header: begin_block
59                    .header
60                    .ok_or_else(Error::missing_header)?
61                    .try_into()?,
62                last_commit_info: begin_block
63                    .last_commit_info
64                    .ok_or_else(Error::missing_last_commit_info)?
65                    .try_into()?,
66                byzantine_validators: begin_block
67                    .byzantine_validators
68                    .into_iter()
69                    .map(TryInto::try_into)
70                    .collect::<Result<_, _>>()?,
71            })
72        }
73    }
74
75    impl Protobuf<pb::abci::RequestBeginBlock> for BeginBlock {}
76}