tendermint/abci/response/
commit.rs

1use crate::{block, prelude::*};
2use bytes::Bytes;
3
4#[doc = include_str!("../doc/response-commit.md")]
5#[derive(Clone, PartialEq, Eq, Debug, Default)]
6pub struct Commit {
7    /// The Merkle root hash of the application state.
8    ///
9    /// This field is ignored since CometBFT 0.38.
10    pub data: Bytes,
11    /// Blocks below this height may be removed.
12    pub retain_height: block::Height,
13}
14
15// =============================================================================
16// Protobuf conversions
17// =============================================================================
18
19mod v0_34 {
20    use super::Commit;
21    use tendermint_proto::v0_34 as pb;
22    use tendermint_proto::Protobuf;
23
24    impl From<Commit> for pb::abci::ResponseCommit {
25        fn from(commit: Commit) -> Self {
26            Self {
27                data: commit.data,
28                retain_height: commit.retain_height.into(),
29            }
30        }
31    }
32
33    impl TryFrom<pb::abci::ResponseCommit> for Commit {
34        type Error = crate::Error;
35
36        fn try_from(commit: pb::abci::ResponseCommit) -> Result<Self, Self::Error> {
37            Ok(Self {
38                data: commit.data,
39                retain_height: commit.retain_height.try_into()?,
40            })
41        }
42    }
43
44    impl Protobuf<pb::abci::ResponseCommit> for Commit {}
45}
46
47mod v0_37 {
48    use super::Commit;
49    use tendermint_proto::v0_37 as pb;
50    use tendermint_proto::Protobuf;
51
52    impl From<Commit> for pb::abci::ResponseCommit {
53        fn from(commit: Commit) -> Self {
54            Self {
55                data: commit.data,
56                retain_height: commit.retain_height.into(),
57            }
58        }
59    }
60
61    impl TryFrom<pb::abci::ResponseCommit> for Commit {
62        type Error = crate::Error;
63
64        fn try_from(commit: pb::abci::ResponseCommit) -> Result<Self, Self::Error> {
65            Ok(Self {
66                data: commit.data,
67                retain_height: commit.retain_height.try_into()?,
68            })
69        }
70    }
71
72    impl Protobuf<pb::abci::ResponseCommit> for Commit {}
73}
74
75mod v0_38 {
76    use super::Commit;
77    use tendermint_proto::v0_38 as pb;
78    use tendermint_proto::Protobuf;
79
80    impl From<Commit> for pb::abci::ResponseCommit {
81        fn from(commit: Commit) -> Self {
82            Self {
83                retain_height: commit.retain_height.into(),
84            }
85        }
86    }
87
88    impl TryFrom<pb::abci::ResponseCommit> for Commit {
89        type Error = crate::Error;
90
91        fn try_from(commit: pb::abci::ResponseCommit) -> Result<Self, Self::Error> {
92            Ok(Self {
93                retain_height: commit.retain_height.try_into()?,
94                data: Default::default(),
95            })
96        }
97    }
98
99    impl Protobuf<pb::abci::ResponseCommit> for Commit {}
100}