tendermint/abci/request/
finalize_block.rs

1use crate::prelude::*;
2use crate::{
3    abci::types::{CommitInfo, Misbehavior},
4    account, block, Hash, Time,
5};
6use bytes::Bytes;
7
8#[doc = include_str!("../doc/request-finalizeblock.md")]
9#[derive(Clone, PartialEq, Eq, Debug)]
10pub struct FinalizeBlock {
11    /// List of transactions committed as part of the block.
12    pub txs: Vec<Bytes>,
13    /// Information about the last commit, obtained from the block that was just decided.
14    ///
15    /// This includes the round, the list of validators, and which validators
16    /// signed the last block.
17    pub decided_last_commit: CommitInfo,
18    /// Evidence of validator misbehavior.
19    pub misbehavior: Vec<Misbehavior>,
20    /// Merkle root hash of the fields of the decided block.
21    pub hash: Hash,
22    /// The height of the finalized block.
23    pub height: block::Height,
24    /// Timestamp of the finalized block.
25    pub time: Time,
26    /// Merkle root of the next validator set.
27    pub next_validators_hash: Hash,
28    /// The address of the public key of the original proposer of the block.
29    pub proposer_address: account::Id,
30}
31
32// =============================================================================
33// Protobuf conversions
34// =============================================================================
35
36mod v0_38 {
37    use super::FinalizeBlock;
38    use crate::Error;
39    use tendermint_proto::v0_38 as pb;
40    use tendermint_proto::Protobuf;
41
42    impl From<FinalizeBlock> for pb::abci::RequestFinalizeBlock {
43        fn from(value: FinalizeBlock) -> Self {
44            Self {
45                txs: value.txs,
46                decided_last_commit: Some(value.decided_last_commit.into()),
47                misbehavior: value.misbehavior.into_iter().map(Into::into).collect(),
48                hash: value.hash.into(),
49                height: value.height.into(),
50                time: Some(value.time.into()),
51                next_validators_hash: value.next_validators_hash.into(),
52                proposer_address: value.proposer_address.into(),
53            }
54        }
55    }
56
57    impl TryFrom<pb::abci::RequestFinalizeBlock> for FinalizeBlock {
58        type Error = Error;
59
60        fn try_from(message: pb::abci::RequestFinalizeBlock) -> Result<Self, Self::Error> {
61            Ok(Self {
62                txs: message.txs,
63                decided_last_commit: message
64                    .decided_last_commit
65                    .ok_or_else(Error::missing_last_commit_info)?
66                    .try_into()?,
67                misbehavior: message
68                    .misbehavior
69                    .into_iter()
70                    .map(TryInto::try_into)
71                    .collect::<Result<_, _>>()?,
72                hash: message.hash.try_into()?,
73                height: message.height.try_into()?,
74                time: message
75                    .time
76                    .ok_or_else(Error::missing_timestamp)?
77                    .try_into()?,
78                next_validators_hash: message.next_validators_hash.try_into()?,
79                proposer_address: message.proposer_address.try_into()?,
80            })
81        }
82    }
83
84    impl Protobuf<pb::abci::RequestFinalizeBlock> for FinalizeBlock {}
85}