tendermint/abci/response/
deliver_tx.rs

1use bytes::Bytes;
2use serde::Serialize;
3
4use super::super::{Code, Event};
5use crate::prelude::*;
6
7#[doc = include_str!("../doc/response-delivertx.md")]
8#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize)]
9pub struct DeliverTx {
10    /// The response code.
11    ///
12    /// This code should be `0` only if the transaction is fully valid. However,
13    /// invalid transactions included in a block will still be executed against
14    /// the application state.
15    pub code: Code,
16    /// Result bytes, if any.
17    pub data: Bytes,
18    /// The output of the application's logger.
19    ///
20    /// **May be non-deterministic**.
21    pub log: String,
22    /// Additional information.
23    ///
24    /// **May be non-deterministic**.
25    pub info: String,
26    /// Amount of gas requested for the transaction.
27    pub gas_wanted: i64,
28    /// Amount of gas consumed by the transaction.
29    pub gas_used: i64,
30    /// Events that occurred while executing the transaction.
31    pub events: Vec<Event>,
32    /// The namespace for the `code`.
33    pub codespace: String,
34}
35
36// =============================================================================
37// Protobuf conversions
38// =============================================================================
39
40mod v0_34 {
41    use super::DeliverTx;
42    use tendermint_proto::v0_34 as pb;
43    use tendermint_proto::Protobuf;
44
45    impl From<DeliverTx> for pb::abci::ResponseDeliverTx {
46        fn from(deliver_tx: DeliverTx) -> Self {
47            Self {
48                code: deliver_tx.code.into(),
49                data: deliver_tx.data,
50                log: deliver_tx.log,
51                info: deliver_tx.info,
52                gas_wanted: deliver_tx.gas_wanted,
53                gas_used: deliver_tx.gas_used,
54                events: deliver_tx.events.into_iter().map(Into::into).collect(),
55                codespace: deliver_tx.codespace,
56            }
57        }
58    }
59
60    impl TryFrom<pb::abci::ResponseDeliverTx> for DeliverTx {
61        type Error = crate::Error;
62
63        fn try_from(deliver_tx: pb::abci::ResponseDeliverTx) -> Result<Self, Self::Error> {
64            Ok(Self {
65                code: deliver_tx.code.into(),
66                data: deliver_tx.data,
67                log: deliver_tx.log,
68                info: deliver_tx.info,
69                gas_wanted: deliver_tx.gas_wanted,
70                gas_used: deliver_tx.gas_used,
71                events: deliver_tx
72                    .events
73                    .into_iter()
74                    .map(TryInto::try_into)
75                    .collect::<Result<_, _>>()?,
76                codespace: deliver_tx.codespace,
77            })
78        }
79    }
80
81    impl Protobuf<pb::abci::ResponseDeliverTx> for DeliverTx {}
82}
83
84mod v0_37 {
85    use super::DeliverTx;
86    use tendermint_proto::v0_37 as pb;
87    use tendermint_proto::Protobuf;
88
89    impl From<DeliverTx> for pb::abci::ResponseDeliverTx {
90        fn from(deliver_tx: DeliverTx) -> Self {
91            Self {
92                code: deliver_tx.code.into(),
93                data: deliver_tx.data,
94                log: deliver_tx.log,
95                info: deliver_tx.info,
96                gas_wanted: deliver_tx.gas_wanted,
97                gas_used: deliver_tx.gas_used,
98                events: deliver_tx.events.into_iter().map(Into::into).collect(),
99                codespace: deliver_tx.codespace,
100            }
101        }
102    }
103
104    impl TryFrom<pb::abci::ResponseDeliverTx> for DeliverTx {
105        type Error = crate::Error;
106
107        fn try_from(deliver_tx: pb::abci::ResponseDeliverTx) -> Result<Self, Self::Error> {
108            Ok(Self {
109                code: deliver_tx.code.into(),
110                data: deliver_tx.data,
111                log: deliver_tx.log,
112                info: deliver_tx.info,
113                gas_wanted: deliver_tx.gas_wanted,
114                gas_used: deliver_tx.gas_used,
115                events: deliver_tx
116                    .events
117                    .into_iter()
118                    .map(TryInto::try_into)
119                    .collect::<Result<_, _>>()?,
120                codespace: deliver_tx.codespace,
121            })
122        }
123    }
124
125    impl Protobuf<pb::abci::ResponseDeliverTx> for DeliverTx {}
126}