celestia_core/abci/response/
process_proposal.rs

1use crate::prelude::*;
2
3use bytes::Bytes;
4
5#[doc = include_str!("../doc/response-processproposal.md")]
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct ProcessProposal {
8    pub result: ProcessProposalResult,
9    pub evidence: Vec<Bytes>,
10}
11
12#[derive(Copy, Clone, Debug, PartialEq, Eq)]
13#[repr(i32)]
14#[derive(Default)]
15pub enum ProcessProposalResult {
16    #[default]
17    Unknown = 0,
18    Accept = 1,
19    Reject = 2,
20}
21
22// =============================================================================
23// Protobuf conversions
24// =============================================================================
25
26mod v0_34 {
27    use super::{ProcessProposal, ProcessProposalResult};
28    use crate::Error;
29    use celestia_core_proto::v0_34::abci as pb;
30    use celestia_core_proto::Protobuf;
31
32    impl From<ProcessProposal> for pb::ResponseProcessProposal {
33        fn from(value: ProcessProposal) -> pb::ResponseProcessProposal {
34            pb::ResponseProcessProposal {
35                result: value.result as i32,
36                evidence: value.evidence,
37            }
38        }
39    }
40
41    impl TryFrom<pb::ResponseProcessProposal> for ProcessProposal {
42        type Error = Error;
43
44        fn try_from(message: pb::ResponseProcessProposal) -> Result<Self, Self::Error> {
45            use pb::response_process_proposal::Result;
46
47            let result = Result::try_from(message.result)
48                .map_err(|_| Error::unsupported_process_proposal_result())?;
49
50            let result = match result {
51                Result::Unknown => ProcessProposalResult::Unknown,
52                Result::Accept => ProcessProposalResult::Accept,
53                Result::Reject => ProcessProposalResult::Reject,
54            };
55
56            Ok(ProcessProposal {
57                result,
58                evidence: message.evidence,
59            })
60        }
61    }
62
63    impl Protobuf<pb::ResponseProcessProposal> for ProcessProposal {}
64}