tendermint/abci/response/
process_proposal.rs

1use crate::prelude::*;
2
3#[doc = include_str!("../doc/response-processproposal.md")]
4#[derive(Copy, Clone, Debug, PartialEq, Eq)]
5#[repr(i32)]
6#[derive(Default)]
7pub enum ProcessProposal {
8    #[default]
9    Unknown = 0,
10    Accept = 1,
11    Reject = 2,
12}
13
14// =============================================================================
15// Protobuf conversions
16// =============================================================================
17
18mod v0_37 {
19    use super::ProcessProposal;
20    use crate::Error;
21    use tendermint_proto::v0_37::abci as pb;
22    use tendermint_proto::Protobuf;
23
24    impl From<ProcessProposal> for pb::ResponseProcessProposal {
25        fn from(value: ProcessProposal) -> Self {
26            Self {
27                status: value as i32,
28            }
29        }
30    }
31
32    impl TryFrom<pb::ResponseProcessProposal> for ProcessProposal {
33        type Error = Error;
34
35        fn try_from(message: pb::ResponseProcessProposal) -> Result<Self, Self::Error> {
36            use pb::response_process_proposal::ProposalStatus;
37
38            let status = message
39                .status
40                .try_into()
41                .map_err(|_| Error::unsupported_process_proposal_status())?;
42
43            let value = match status {
44                ProposalStatus::Unknown => ProcessProposal::Unknown,
45                ProposalStatus::Accept => ProcessProposal::Accept,
46                ProposalStatus::Reject => ProcessProposal::Reject,
47            };
48            Ok(value)
49        }
50    }
51
52    impl Protobuf<pb::ResponseProcessProposal> for ProcessProposal {}
53}
54
55mod v0_38 {
56    use super::ProcessProposal;
57    use crate::Error;
58    use tendermint_proto::v0_38::abci as pb;
59    use tendermint_proto::Protobuf;
60
61    impl From<ProcessProposal> for pb::ResponseProcessProposal {
62        fn from(value: ProcessProposal) -> Self {
63            Self {
64                status: value as i32,
65            }
66        }
67    }
68
69    impl TryFrom<pb::ResponseProcessProposal> for ProcessProposal {
70        type Error = Error;
71
72        fn try_from(message: pb::ResponseProcessProposal) -> Result<Self, Self::Error> {
73            use pb::response_process_proposal::ProposalStatus;
74
75            let status = message
76                .status
77                .try_into()
78                .map_err(|_| Error::unsupported_process_proposal_status())?;
79
80            let value = match status {
81                ProposalStatus::Unknown => ProcessProposal::Unknown,
82                ProposalStatus::Accept => ProcessProposal::Accept,
83                ProposalStatus::Reject => ProcessProposal::Reject,
84            };
85            Ok(value)
86        }
87    }
88
89    impl Protobuf<pb::ResponseProcessProposal> for ProcessProposal {}
90}