tendermint/abci/request/
check_tx.rs

1use bytes::Bytes;
2
3use crate::prelude::*;
4
5#[doc = include_str!("../doc/request-checktx.md")]
6#[derive(Clone, PartialEq, Eq, Debug)]
7pub struct CheckTx {
8    /// The transaction bytes.
9    pub tx: Bytes,
10    /// The kind of check to perform.
11    ///
12    /// Note: this field is called `type` in the protobuf, but we call it `kind`
13    /// to avoid the Rust keyword.
14    pub kind: CheckTxKind,
15}
16
17/// The possible kinds of [`CheckTx`] checks.
18///
19/// Note: the
20/// [ABCI documentation](https://docs.tendermint.com/master/spec/abci/abci.html#checktx)
21/// calls this `CheckTxType`, but we follow the Rust convention and name it `CheckTxKind`
22/// to avoid confusion with Rust types.
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
24#[repr(i32)]
25#[derive(Default)]
26pub enum CheckTxKind {
27    /// A full check is required (the default).
28    #[default]
29    New = 0,
30    /// Indicates that the mempool is initiating a recheck of the transaction.
31    Recheck = 1,
32}
33
34// =============================================================================
35// Protobuf conversions
36// =============================================================================
37
38tendermint_pb_modules! {
39    use super::{CheckTx, CheckTxKind};
40
41    impl From<CheckTx> for pb::abci::RequestCheckTx {
42        fn from(check_tx: CheckTx) -> Self {
43            Self {
44                tx: check_tx.tx,
45                r#type: check_tx.kind as i32,
46            }
47        }
48    }
49
50    impl TryFrom<pb::abci::RequestCheckTx> for CheckTx {
51        type Error = crate::Error;
52
53        fn try_from(check_tx: pb::abci::RequestCheckTx) -> Result<Self, Self::Error> {
54            let kind = match check_tx.r#type {
55                0 => CheckTxKind::New,
56                1 => CheckTxKind::Recheck,
57                _ => return Err(crate::Error::unsupported_check_tx_type()),
58            };
59            Ok(Self {
60                tx: check_tx.tx,
61                kind,
62            })
63        }
64    }
65
66    impl Protobuf<pb::abci::RequestCheckTx> for CheckTx {}
67}