Skip to main content

tendermint_rpc/dialect/
deliver_tx.rs

1use bytes::Bytes;
2use serde::{Deserialize, Serialize};
3
4use tendermint::abci::{self, Code};
5
6use crate::prelude::*;
7use crate::serializers;
8
9#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
10#[serde(default)]
11pub struct DeliverTx<Ev> {
12    /// The response code.
13    ///
14    /// This code should be `0` only if the transaction is fully valid. However,
15    /// invalid transactions included in a block will still be executed against
16    /// the application state.
17    #[serde(default)]
18    pub code: Code,
19
20    /// Result bytes, if any.
21    #[serde(default, with = "serializers::nullable")]
22    pub data: Bytes,
23
24    /// The output of the application's logger.
25    ///
26    /// **May be non-deterministic**.
27    #[serde(default)]
28    pub log: String,
29
30    /// Additional information.
31    ///
32    /// **May be non-deterministic**.
33    #[serde(default)]
34    pub info: String,
35
36    /// Amount of gas requested for the transaction.
37    #[serde(default, with = "serializers::from_str")]
38    pub gas_wanted: i64,
39
40    /// Amount of gas consumed by the transaction.
41    #[serde(default, with = "serializers::from_str")]
42    pub gas_used: i64,
43
44    /// Events that occurred while executing the transaction.
45    #[serde(default = "Vec::new")]
46    pub events: Vec<Ev>,
47
48    /// The namespace for the `code`.
49    #[serde(default)]
50    pub codespace: String,
51}
52
53impl<Ev> Default for DeliverTx<Ev> {
54    fn default() -> Self {
55        Self {
56            code: Default::default(),
57            data: Default::default(),
58            log: Default::default(),
59            info: Default::default(),
60            gas_wanted: Default::default(),
61            gas_used: Default::default(),
62            events: Default::default(),
63            codespace: Default::default(),
64        }
65    }
66}
67
68impl<Ev> From<DeliverTx<Ev>> for abci::response::DeliverTx
69where
70    Ev: Into<abci::Event>,
71{
72    fn from(msg: DeliverTx<Ev>) -> Self {
73        Self {
74            code: msg.code,
75            data: msg.data,
76            log: msg.log,
77            info: msg.info,
78            gas_wanted: msg.gas_wanted,
79            gas_used: msg.gas_used,
80            events: msg.events.into_iter().map(Into::into).collect(),
81            codespace: msg.codespace,
82        }
83    }
84}
85
86impl<Ev> From<DeliverTx<Ev>> for abci::types::ExecTxResult
87where
88    Ev: Into<abci::Event>,
89{
90    fn from(msg: DeliverTx<Ev>) -> Self {
91        Self {
92            code: msg.code,
93            data: msg.data,
94            log: msg.log,
95            info: msg.info,
96            gas_wanted: msg.gas_wanted,
97            gas_used: msg.gas_used,
98            events: msg.events.into_iter().map(Into::into).collect(),
99            codespace: msg.codespace,
100        }
101    }
102}