tendermint/v0_38/abci/
response.rs

1pub use crate::abci::response::{
2    ApplySnapshotChunk, BeginBlock, CheckTx, Commit, DeliverTx, Echo, EndBlock, Exception,
3    ExtendVote, FinalizeBlock, Info, InitChain, ListSnapshots, LoadSnapshotChunk, OfferSnapshot,
4    PrepareProposal, ProcessProposal, Query, VerifyVoteExtension,
5};
6use crate::Error;
7
8/// All possible ABCI responses for this protocol version.
9#[derive(Clone, PartialEq, Eq, Debug)]
10pub enum Response {
11    #[doc = include_str!("../../abci/doc/response-exception.md")]
12    Exception(Exception),
13    #[doc = include_str!("../../abci/doc/response-echo.md")]
14    Echo(Echo),
15    #[doc = include_str!("../../abci/doc/response-flush.md")]
16    Flush,
17    #[doc = include_str!("../../abci/doc/response-info.md")]
18    Info(Info),
19    #[doc = include_str!("../../abci/doc/response-initchain.md")]
20    InitChain(InitChain),
21    #[doc = include_str!("../../abci/doc/response-query.md")]
22    Query(Query),
23    #[doc = include_str!("../../abci/doc/response-checktx.md")]
24    CheckTx(CheckTx),
25    #[doc = include_str!("../../abci/doc/response-commit.md")]
26    Commit(Commit),
27    #[doc = include_str!("../../abci/doc/response-listsnapshots.md")]
28    ListSnapshots(ListSnapshots),
29    #[doc = include_str!("../../abci/doc/response-offersnapshot.md")]
30    OfferSnapshot(OfferSnapshot),
31    #[doc = include_str!("../../abci/doc/response-loadsnapshotchunk.md")]
32    LoadSnapshotChunk(LoadSnapshotChunk),
33    #[doc = include_str!("../../abci/doc/response-applysnapshotchunk.md")]
34    ApplySnapshotChunk(ApplySnapshotChunk),
35    #[doc = include_str!("../../abci/doc/response-prepareproposal.md")]
36    PrepareProposal(PrepareProposal),
37    #[doc = include_str!("../../abci/doc/response-processproposal.md")]
38    ProcessProposal(ProcessProposal),
39    #[doc = include_str!("../../abci/doc/response-extendvote.md")]
40    ExtendVote(ExtendVote),
41    #[doc = include_str!("../../abci/doc/response-verifyvoteextension.md")]
42    VerifyVoteExtension(VerifyVoteExtension),
43    #[doc = include_str!("../../abci/doc/response-finalizeblock.md")]
44    FinalizeBlock(FinalizeBlock),
45}
46
47/// The consensus category of ABCI responses.
48#[derive(Clone, PartialEq, Eq, Debug)]
49pub enum ConsensusResponse {
50    #[doc = include_str!("../../abci/doc/response-initchain.md")]
51    InitChain(InitChain),
52    #[doc = include_str!("../../abci/doc/response-prepareproposal.md")]
53    PrepareProposal(PrepareProposal),
54    #[doc = include_str!("../../abci/doc/response-processproposal.md")]
55    ProcessProposal(ProcessProposal),
56    #[doc = include_str!("../../abci/doc/response-commit.md")]
57    Commit(Commit),
58    #[doc = include_str!("../../abci/doc/response-extendvote.md")]
59    ExtendVote(ExtendVote),
60    #[doc = include_str!("../../abci/doc/response-verifyvoteextension.md")]
61    VerifyVoteExtension(VerifyVoteExtension),
62    #[doc = include_str!("../../abci/doc/response-finalizeblock.md")]
63    FinalizeBlock(FinalizeBlock),
64}
65
66/// The mempool category of ABCI responses.
67#[derive(Clone, PartialEq, Eq, Debug)]
68pub enum MempoolResponse {
69    #[doc = include_str!("../../abci/doc/response-checktx.md")]
70    CheckTx(CheckTx),
71}
72
73/// The info category of ABCI responses.
74#[derive(Clone, PartialEq, Eq, Debug)]
75pub enum InfoResponse {
76    #[doc = include_str!("../../abci/doc/response-echo.md")]
77    Echo(Echo),
78    #[doc = include_str!("../../abci/doc/response-info.md")]
79    Info(Info),
80    #[doc = include_str!("../../abci/doc/response-query.md")]
81    Query(Query),
82}
83
84/// The snapshot category of ABCI responses.
85#[derive(Clone, PartialEq, Eq, Debug)]
86pub enum SnapshotResponse {
87    #[doc = include_str!("../../abci/doc/response-listsnapshots.md")]
88    ListSnapshots(ListSnapshots),
89    #[doc = include_str!("../../abci/doc/response-offersnapshot.md")]
90    OfferSnapshot(OfferSnapshot),
91    #[doc = include_str!("../../abci/doc/response-loadsnapshotchunk.md")]
92    LoadSnapshotChunk(LoadSnapshotChunk),
93    #[doc = include_str!("../../abci/doc/response-applysnapshotchunk.md")]
94    ApplySnapshotChunk(ApplySnapshotChunk),
95}
96
97impl From<ConsensusResponse> for Response {
98    fn from(req: ConsensusResponse) -> Self {
99        match req {
100            ConsensusResponse::InitChain(x) => Self::InitChain(x),
101            ConsensusResponse::PrepareProposal(x) => Self::PrepareProposal(x),
102            ConsensusResponse::ProcessProposal(x) => Self::ProcessProposal(x),
103            ConsensusResponse::Commit(x) => Self::Commit(x),
104            ConsensusResponse::ExtendVote(x) => Self::ExtendVote(x),
105            ConsensusResponse::VerifyVoteExtension(x) => Self::VerifyVoteExtension(x),
106            ConsensusResponse::FinalizeBlock(x) => Self::FinalizeBlock(x),
107        }
108    }
109}
110
111impl TryFrom<Response> for ConsensusResponse {
112    type Error = Error;
113    fn try_from(req: Response) -> Result<Self, Self::Error> {
114        match req {
115            Response::InitChain(x) => Ok(Self::InitChain(x)),
116            Response::PrepareProposal(x) => Ok(Self::PrepareProposal(x)),
117            Response::ProcessProposal(x) => Ok(Self::ProcessProposal(x)),
118            Response::Commit(x) => Ok(Self::Commit(x)),
119            Response::ExtendVote(x) => Ok(Self::ExtendVote(x)),
120            Response::VerifyVoteExtension(x) => Ok(Self::VerifyVoteExtension(x)),
121            Response::FinalizeBlock(x) => Ok(Self::FinalizeBlock(x)),
122            _ => Err(Error::invalid_abci_response_type()),
123        }
124    }
125}
126
127impl From<MempoolResponse> for Response {
128    fn from(req: MempoolResponse) -> Self {
129        match req {
130            MempoolResponse::CheckTx(x) => Self::CheckTx(x),
131        }
132    }
133}
134
135impl TryFrom<Response> for MempoolResponse {
136    type Error = Error;
137    fn try_from(req: Response) -> Result<Self, Self::Error> {
138        match req {
139            Response::CheckTx(x) => Ok(Self::CheckTx(x)),
140            _ => Err(Error::invalid_abci_response_type()),
141        }
142    }
143}
144
145impl From<InfoResponse> for Response {
146    fn from(req: InfoResponse) -> Self {
147        match req {
148            InfoResponse::Echo(x) => Self::Echo(x),
149            InfoResponse::Info(x) => Self::Info(x),
150            InfoResponse::Query(x) => Self::Query(x),
151        }
152    }
153}
154
155impl TryFrom<Response> for InfoResponse {
156    type Error = Error;
157    fn try_from(req: Response) -> Result<Self, Self::Error> {
158        match req {
159            Response::Echo(x) => Ok(Self::Echo(x)),
160            Response::Info(x) => Ok(Self::Info(x)),
161            Response::Query(x) => Ok(Self::Query(x)),
162            _ => Err(Error::invalid_abci_response_type()),
163        }
164    }
165}
166
167impl From<SnapshotResponse> for Response {
168    fn from(req: SnapshotResponse) -> Self {
169        match req {
170            SnapshotResponse::ListSnapshots(x) => Self::ListSnapshots(x),
171            SnapshotResponse::OfferSnapshot(x) => Self::OfferSnapshot(x),
172            SnapshotResponse::LoadSnapshotChunk(x) => Self::LoadSnapshotChunk(x),
173            SnapshotResponse::ApplySnapshotChunk(x) => Self::ApplySnapshotChunk(x),
174        }
175    }
176}
177
178impl TryFrom<Response> for SnapshotResponse {
179    type Error = Error;
180    fn try_from(req: Response) -> Result<Self, Self::Error> {
181        match req {
182            Response::ListSnapshots(x) => Ok(Self::ListSnapshots(x)),
183            Response::OfferSnapshot(x) => Ok(Self::OfferSnapshot(x)),
184            Response::LoadSnapshotChunk(x) => Ok(Self::LoadSnapshotChunk(x)),
185            Response::ApplySnapshotChunk(x) => Ok(Self::ApplySnapshotChunk(x)),
186            _ => Err(Error::invalid_abci_response_type()),
187        }
188    }
189}
190
191// =============================================================================
192// Protobuf conversions
193// =============================================================================
194
195use tendermint_proto::v0_38::abci as pb;
196use tendermint_proto::Protobuf;
197
198impl From<Response> for pb::Response {
199    fn from(response: Response) -> pb::Response {
200        use pb::response::Value;
201        let value = match response {
202            Response::Exception(x) => Some(Value::Exception(x.into())),
203            Response::Echo(x) => Some(Value::Echo(x.into())),
204            Response::Flush => Some(Value::Flush(Default::default())),
205            Response::Info(x) => Some(Value::Info(x.into())),
206            Response::InitChain(x) => Some(Value::InitChain(x.into())),
207            Response::Query(x) => Some(Value::Query(x.into())),
208            Response::CheckTx(x) => Some(Value::CheckTx(x.into())),
209            Response::Commit(x) => Some(Value::Commit(x.into())),
210            Response::ListSnapshots(x) => Some(Value::ListSnapshots(x.into())),
211            Response::OfferSnapshot(x) => Some(Value::OfferSnapshot(x.into())),
212            Response::LoadSnapshotChunk(x) => Some(Value::LoadSnapshotChunk(x.into())),
213            Response::ApplySnapshotChunk(x) => Some(Value::ApplySnapshotChunk(x.into())),
214            Response::PrepareProposal(x) => Some(Value::PrepareProposal(x.into())),
215            Response::ProcessProposal(x) => Some(Value::ProcessProposal(x.into())),
216            Response::ExtendVote(x) => Some(Value::ExtendVote(x.into())),
217            Response::VerifyVoteExtension(x) => Some(Value::VerifyVoteExtension(x.into())),
218            Response::FinalizeBlock(x) => Some(Value::FinalizeBlock(x.into())),
219        };
220        pb::Response { value }
221    }
222}
223
224impl TryFrom<pb::Response> for Response {
225    type Error = Error;
226
227    fn try_from(response: pb::Response) -> Result<Self, Self::Error> {
228        use pb::response::Value;
229
230        let value = response.value.ok_or_else(Error::missing_data)?;
231
232        let response = match value {
233            Value::Exception(x) => Response::Exception(x.try_into()?),
234            Value::Echo(x) => Response::Echo(x.try_into()?),
235            Value::Flush(_) => Response::Flush,
236            Value::Info(x) => Response::Info(x.try_into()?),
237            Value::InitChain(x) => Response::InitChain(x.try_into()?),
238            Value::Query(x) => Response::Query(x.try_into()?),
239            Value::CheckTx(x) => Response::CheckTx(x.try_into()?),
240            Value::Commit(x) => Response::Commit(x.try_into()?),
241            Value::ListSnapshots(x) => Response::ListSnapshots(x.try_into()?),
242            Value::OfferSnapshot(x) => Response::OfferSnapshot(x.try_into()?),
243            Value::LoadSnapshotChunk(x) => Response::LoadSnapshotChunk(x.try_into()?),
244            Value::ApplySnapshotChunk(x) => Response::ApplySnapshotChunk(x.try_into()?),
245            Value::PrepareProposal(x) => Response::PrepareProposal(x.try_into()?),
246            Value::ProcessProposal(x) => Response::ProcessProposal(x.try_into()?),
247            Value::ExtendVote(x) => Response::ExtendVote(x.try_into()?),
248            Value::VerifyVoteExtension(x) => Response::VerifyVoteExtension(x.try_into()?),
249            Value::FinalizeBlock(x) => Response::FinalizeBlock(x.try_into()?),
250        };
251        Ok(response)
252    }
253}
254
255impl Protobuf<pb::Response> for Response {}