cometbft_rpc/dialect/
check_tx.rs

1use bytes::Bytes;
2use serde::{Deserialize, Serialize};
3
4use cometbft::abci::{self, Code};
5
6use crate::prelude::*;
7use crate::serializers;
8
9#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
10#[serde(default)]
11pub struct CheckTx<Ev> {
12    /// The response code.
13    ///
14    /// Transactions where `code != 0` will be rejected; these transactions will
15    /// not be broadcast to other nodes or included in a proposal block.
16    /// CometBFT attributes no other value to the response code.
17    pub code: Code,
18    /// Result bytes, if any.
19    #[serde(with = "serializers::nullable")]
20    pub data: Bytes,
21    /// The output of the application's logger.
22    ///
23    /// **May be non-deterministic**.
24    pub log: String,
25    /// Additional information.
26    ///
27    /// **May be non-deterministic**.
28    pub info: String,
29    /// Amount of gas requested for the transaction.
30    #[serde(with = "serializers::from_str")]
31    pub gas_wanted: i64,
32    /// Amount of gas consumed by the transaction.
33    #[serde(with = "serializers::from_str")]
34    pub gas_used: i64,
35    /// Events that occurred while checking the transaction.
36    pub events: Vec<Ev>,
37    /// The namespace for the `code`.
38    pub codespace: String,
39    /// The transaction's sender (e.g. the signer).
40    pub sender: String,
41    /// The transaction's priority (for mempool ordering).
42    #[serde(with = "serializers::from_str")]
43    pub priority: i64,
44    /// mempool_error is set by CometBFT.
45    /// ABCI applictions should not set mempool_error.
46    pub mempool_error: String,
47}
48
49impl<Ev> Default for CheckTx<Ev> {
50    fn default() -> Self {
51        Self {
52            code: Default::default(),
53            data: Default::default(),
54            log: Default::default(),
55            info: Default::default(),
56            gas_wanted: Default::default(),
57            gas_used: Default::default(),
58            events: Default::default(),
59            codespace: Default::default(),
60            sender: Default::default(),
61            priority: Default::default(),
62            mempool_error: Default::default(),
63        }
64    }
65}
66
67impl<Ev> From<CheckTx<Ev>> for abci::response::CheckTx
68where
69    Ev: Into<abci::Event>,
70{
71    fn from(msg: CheckTx<Ev>) -> Self {
72        Self {
73            code: msg.code,
74            data: msg.data,
75            log: msg.log,
76            info: msg.info,
77            gas_wanted: msg.gas_wanted,
78            gas_used: msg.gas_used,
79            events: msg.events.into_iter().map(Into::into).collect(),
80            codespace: msg.codespace,
81            sender: msg.sender,
82            priority: msg.priority,
83            mempool_error: msg.mempool_error,
84        }
85    }
86}