Skip to main content

stellar_xdr/generated/
transaction_result_code.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// TransactionResultCode is an XDR Enum defined as:
5///
6/// ```text
7/// enum TransactionResultCode
8/// {
9///     txFEE_BUMP_INNER_SUCCESS = 1, // fee bump inner transaction succeeded
10///     txSUCCESS = 0,                // all operations succeeded
11///
12///     txFAILED = -1, // one of the operations failed (none were applied)
13///
14///     txTOO_EARLY = -2,         // ledger closeTime before minTime
15///     txTOO_LATE = -3,          // ledger closeTime after maxTime
16///     txMISSING_OPERATION = -4, // no operation was specified
17///     txBAD_SEQ = -5,           // sequence number does not match source account
18///
19///     txBAD_AUTH = -6,             // too few valid signatures / wrong network
20///     txINSUFFICIENT_BALANCE = -7, // fee would bring account below reserve
21///     txNO_ACCOUNT = -8,           // source account not found
22///     txINSUFFICIENT_FEE = -9,     // fee is too small
23///     txBAD_AUTH_EXTRA = -10,      // unused signatures attached to transaction
24///     txINTERNAL_ERROR = -11,      // an unknown error occurred
25///
26///     txNOT_SUPPORTED = -12,          // transaction type not supported
27///     txFEE_BUMP_INNER_FAILED = -13,  // fee bump inner transaction failed
28///     txBAD_SPONSORSHIP = -14,        // sponsorship not confirmed
29///     txBAD_MIN_SEQ_AGE_OR_GAP = -15, // minSeqAge or minSeqLedgerGap conditions not met
30///     txMALFORMED = -16,              // precondition is invalid
31///     txSOROBAN_INVALID = -17,        // soroban-specific preconditions were not met
32///     txFROZEN_KEY_ACCESSED = -18     // a 'frozen' ledger key is accessed by any operation
33/// };
34/// ```
35///
36// enum
37#[cfg_attr(feature = "alloc", derive(Default))]
38#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
39#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
40#[cfg_attr(
41    all(feature = "serde", feature = "alloc"),
42    derive(serde::Serialize, serde::Deserialize),
43    serde(rename_all = "snake_case")
44)]
45#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
46#[repr(i32)]
47pub enum TransactionResultCode {
48    #[cfg_attr(feature = "alloc", default)]
49    TxFeeBumpInnerSuccess = 1,
50    TxSuccess = 0,
51    TxFailed = -1,
52    TxTooEarly = -2,
53    TxTooLate = -3,
54    TxMissingOperation = -4,
55    TxBadSeq = -5,
56    TxBadAuth = -6,
57    TxInsufficientBalance = -7,
58    TxNoAccount = -8,
59    TxInsufficientFee = -9,
60    TxBadAuthExtra = -10,
61    TxInternalError = -11,
62    TxNotSupported = -12,
63    TxFeeBumpInnerFailed = -13,
64    TxBadSponsorship = -14,
65    TxBadMinSeqAgeOrGap = -15,
66    TxMalformed = -16,
67    TxSorobanInvalid = -17,
68    TxFrozenKeyAccessed = -18,
69}
70
71impl TransactionResultCode {
72    const _VARIANTS: &[TransactionResultCode] = &[
73        TransactionResultCode::TxFeeBumpInnerSuccess,
74        TransactionResultCode::TxSuccess,
75        TransactionResultCode::TxFailed,
76        TransactionResultCode::TxTooEarly,
77        TransactionResultCode::TxTooLate,
78        TransactionResultCode::TxMissingOperation,
79        TransactionResultCode::TxBadSeq,
80        TransactionResultCode::TxBadAuth,
81        TransactionResultCode::TxInsufficientBalance,
82        TransactionResultCode::TxNoAccount,
83        TransactionResultCode::TxInsufficientFee,
84        TransactionResultCode::TxBadAuthExtra,
85        TransactionResultCode::TxInternalError,
86        TransactionResultCode::TxNotSupported,
87        TransactionResultCode::TxFeeBumpInnerFailed,
88        TransactionResultCode::TxBadSponsorship,
89        TransactionResultCode::TxBadMinSeqAgeOrGap,
90        TransactionResultCode::TxMalformed,
91        TransactionResultCode::TxSorobanInvalid,
92        TransactionResultCode::TxFrozenKeyAccessed,
93    ];
94    pub const VARIANTS: [TransactionResultCode; Self::_VARIANTS.len()] = {
95        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
96        let mut i = 1;
97        while i < Self::_VARIANTS.len() {
98            arr[i] = Self::_VARIANTS[i];
99            i += 1;
100        }
101        arr
102    };
103    const _VARIANTS_STR: &[&str] = &[
104        "TxFeeBumpInnerSuccess",
105        "TxSuccess",
106        "TxFailed",
107        "TxTooEarly",
108        "TxTooLate",
109        "TxMissingOperation",
110        "TxBadSeq",
111        "TxBadAuth",
112        "TxInsufficientBalance",
113        "TxNoAccount",
114        "TxInsufficientFee",
115        "TxBadAuthExtra",
116        "TxInternalError",
117        "TxNotSupported",
118        "TxFeeBumpInnerFailed",
119        "TxBadSponsorship",
120        "TxBadMinSeqAgeOrGap",
121        "TxMalformed",
122        "TxSorobanInvalid",
123        "TxFrozenKeyAccessed",
124    ];
125    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
126        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
127        let mut i = 1;
128        while i < Self::_VARIANTS_STR.len() {
129            arr[i] = Self::_VARIANTS_STR[i];
130            i += 1;
131        }
132        arr
133    };
134
135    #[must_use]
136    pub const fn name(&self) -> &'static str {
137        match self {
138            Self::TxFeeBumpInnerSuccess => "TxFeeBumpInnerSuccess",
139            Self::TxSuccess => "TxSuccess",
140            Self::TxFailed => "TxFailed",
141            Self::TxTooEarly => "TxTooEarly",
142            Self::TxTooLate => "TxTooLate",
143            Self::TxMissingOperation => "TxMissingOperation",
144            Self::TxBadSeq => "TxBadSeq",
145            Self::TxBadAuth => "TxBadAuth",
146            Self::TxInsufficientBalance => "TxInsufficientBalance",
147            Self::TxNoAccount => "TxNoAccount",
148            Self::TxInsufficientFee => "TxInsufficientFee",
149            Self::TxBadAuthExtra => "TxBadAuthExtra",
150            Self::TxInternalError => "TxInternalError",
151            Self::TxNotSupported => "TxNotSupported",
152            Self::TxFeeBumpInnerFailed => "TxFeeBumpInnerFailed",
153            Self::TxBadSponsorship => "TxBadSponsorship",
154            Self::TxBadMinSeqAgeOrGap => "TxBadMinSeqAgeOrGap",
155            Self::TxMalformed => "TxMalformed",
156            Self::TxSorobanInvalid => "TxSorobanInvalid",
157            Self::TxFrozenKeyAccessed => "TxFrozenKeyAccessed",
158        }
159    }
160
161    #[must_use]
162    pub const fn variants() -> [TransactionResultCode; Self::_VARIANTS.len()] {
163        Self::VARIANTS
164    }
165}
166
167impl Name for TransactionResultCode {
168    #[must_use]
169    fn name(&self) -> &'static str {
170        Self::name(self)
171    }
172}
173
174impl Variants<TransactionResultCode> for TransactionResultCode {
175    fn variants() -> slice::Iter<'static, TransactionResultCode> {
176        Self::VARIANTS.iter()
177    }
178}
179
180impl Enum for TransactionResultCode {}
181
182impl fmt::Display for TransactionResultCode {
183    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
184        f.write_str(self.name())
185    }
186}
187
188impl TryFrom<i32> for TransactionResultCode {
189    type Error = Error;
190
191    fn try_from(i: i32) -> Result<Self, Error> {
192        let e = match i {
193            1 => TransactionResultCode::TxFeeBumpInnerSuccess,
194            0 => TransactionResultCode::TxSuccess,
195            -1 => TransactionResultCode::TxFailed,
196            -2 => TransactionResultCode::TxTooEarly,
197            -3 => TransactionResultCode::TxTooLate,
198            -4 => TransactionResultCode::TxMissingOperation,
199            -5 => TransactionResultCode::TxBadSeq,
200            -6 => TransactionResultCode::TxBadAuth,
201            -7 => TransactionResultCode::TxInsufficientBalance,
202            -8 => TransactionResultCode::TxNoAccount,
203            -9 => TransactionResultCode::TxInsufficientFee,
204            -10 => TransactionResultCode::TxBadAuthExtra,
205            -11 => TransactionResultCode::TxInternalError,
206            -12 => TransactionResultCode::TxNotSupported,
207            -13 => TransactionResultCode::TxFeeBumpInnerFailed,
208            -14 => TransactionResultCode::TxBadSponsorship,
209            -15 => TransactionResultCode::TxBadMinSeqAgeOrGap,
210            -16 => TransactionResultCode::TxMalformed,
211            -17 => TransactionResultCode::TxSorobanInvalid,
212            -18 => TransactionResultCode::TxFrozenKeyAccessed,
213            #[allow(unreachable_patterns)]
214            _ => return Err(Error::Invalid),
215        };
216        Ok(e)
217    }
218}
219
220impl From<TransactionResultCode> for i32 {
221    #[must_use]
222    fn from(e: TransactionResultCode) -> Self {
223        e as Self
224    }
225}
226
227impl ReadXdr for TransactionResultCode {
228    #[cfg(feature = "std")]
229    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
230        r.with_limited_depth(|r| {
231            let e = i32::read_xdr(r)?;
232            let v: Self = e.try_into()?;
233            Ok(v)
234        })
235    }
236}
237
238impl WriteXdr for TransactionResultCode {
239    #[cfg(feature = "std")]
240    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
241        w.with_limited_depth(|w| {
242            let i: i32 = (*self).into();
243            i.write_xdr(w)
244        })
245    }
246}