Skip to main content

stellar_xdr/generated/
inner_transaction_result_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// InnerTransactionResultResult is an XDR NestedUnion defined as:
5///
6/// ```text
7/// union switch (TransactionResultCode code)
8///     {
9///     // txFEE_BUMP_INNER_SUCCESS is not included
10///     case txSUCCESS:
11///     case txFAILED:
12///         OperationResult results<>;
13///     case txTOO_EARLY:
14///     case txTOO_LATE:
15///     case txMISSING_OPERATION:
16///     case txBAD_SEQ:
17///     case txBAD_AUTH:
18///     case txINSUFFICIENT_BALANCE:
19///     case txNO_ACCOUNT:
20///     case txINSUFFICIENT_FEE:
21///     case txBAD_AUTH_EXTRA:
22///     case txINTERNAL_ERROR:
23///     case txNOT_SUPPORTED:
24///     // txFEE_BUMP_INNER_FAILED is not included
25///     case txBAD_SPONSORSHIP:
26///     case txBAD_MIN_SEQ_AGE_OR_GAP:
27///     case txMALFORMED:
28///     case txSOROBAN_INVALID:
29///     case txFROZEN_KEY_ACCESSED:
30///         void;
31///     }
32/// ```
33///
34// union with discriminant TransactionResultCode
35#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
36#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
37#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
38#[cfg_attr(
39    all(feature = "serde", feature = "alloc"),
40    serde_with::serde_as,
41    derive(serde::Serialize, serde::Deserialize),
42    serde(rename_all = "snake_case")
43)]
44#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
45#[allow(clippy::large_enum_variant)]
46pub enum InnerTransactionResultResult {
47    TxSuccess(VecM<OperationResult>),
48    TxFailed(VecM<OperationResult>),
49    TxTooEarly,
50    TxTooLate,
51    TxMissingOperation,
52    TxBadSeq,
53    TxBadAuth,
54    TxInsufficientBalance,
55    TxNoAccount,
56    TxInsufficientFee,
57    TxBadAuthExtra,
58    TxInternalError,
59    TxNotSupported,
60    TxBadSponsorship,
61    TxBadMinSeqAgeOrGap,
62    TxMalformed,
63    TxSorobanInvalid,
64    TxFrozenKeyAccessed,
65}
66
67#[cfg(feature = "alloc")]
68impl Default for InnerTransactionResultResult {
69    fn default() -> Self {
70        Self::TxSuccess(VecM::<OperationResult>::default())
71    }
72}
73
74impl InnerTransactionResultResult {
75    const _VARIANTS: &[TransactionResultCode] = &[
76        TransactionResultCode::TxSuccess,
77        TransactionResultCode::TxFailed,
78        TransactionResultCode::TxTooEarly,
79        TransactionResultCode::TxTooLate,
80        TransactionResultCode::TxMissingOperation,
81        TransactionResultCode::TxBadSeq,
82        TransactionResultCode::TxBadAuth,
83        TransactionResultCode::TxInsufficientBalance,
84        TransactionResultCode::TxNoAccount,
85        TransactionResultCode::TxInsufficientFee,
86        TransactionResultCode::TxBadAuthExtra,
87        TransactionResultCode::TxInternalError,
88        TransactionResultCode::TxNotSupported,
89        TransactionResultCode::TxBadSponsorship,
90        TransactionResultCode::TxBadMinSeqAgeOrGap,
91        TransactionResultCode::TxMalformed,
92        TransactionResultCode::TxSorobanInvalid,
93        TransactionResultCode::TxFrozenKeyAccessed,
94    ];
95    pub const VARIANTS: [TransactionResultCode; Self::_VARIANTS.len()] = {
96        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
97        let mut i = 1;
98        while i < Self::_VARIANTS.len() {
99            arr[i] = Self::_VARIANTS[i];
100            i += 1;
101        }
102        arr
103    };
104    const _VARIANTS_STR: &[&str] = &[
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        "TxBadSponsorship",
119        "TxBadMinSeqAgeOrGap",
120        "TxMalformed",
121        "TxSorobanInvalid",
122        "TxFrozenKeyAccessed",
123    ];
124    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
125        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
126        let mut i = 1;
127        while i < Self::_VARIANTS_STR.len() {
128            arr[i] = Self::_VARIANTS_STR[i];
129            i += 1;
130        }
131        arr
132    };
133
134    #[must_use]
135    pub const fn name(&self) -> &'static str {
136        match self {
137            Self::TxSuccess(_) => "TxSuccess",
138            Self::TxFailed(_) => "TxFailed",
139            Self::TxTooEarly => "TxTooEarly",
140            Self::TxTooLate => "TxTooLate",
141            Self::TxMissingOperation => "TxMissingOperation",
142            Self::TxBadSeq => "TxBadSeq",
143            Self::TxBadAuth => "TxBadAuth",
144            Self::TxInsufficientBalance => "TxInsufficientBalance",
145            Self::TxNoAccount => "TxNoAccount",
146            Self::TxInsufficientFee => "TxInsufficientFee",
147            Self::TxBadAuthExtra => "TxBadAuthExtra",
148            Self::TxInternalError => "TxInternalError",
149            Self::TxNotSupported => "TxNotSupported",
150            Self::TxBadSponsorship => "TxBadSponsorship",
151            Self::TxBadMinSeqAgeOrGap => "TxBadMinSeqAgeOrGap",
152            Self::TxMalformed => "TxMalformed",
153            Self::TxSorobanInvalid => "TxSorobanInvalid",
154            Self::TxFrozenKeyAccessed => "TxFrozenKeyAccessed",
155        }
156    }
157
158    #[must_use]
159    pub const fn discriminant(&self) -> TransactionResultCode {
160        #[allow(clippy::match_same_arms)]
161        match self {
162            Self::TxSuccess(_) => TransactionResultCode::TxSuccess,
163            Self::TxFailed(_) => TransactionResultCode::TxFailed,
164            Self::TxTooEarly => TransactionResultCode::TxTooEarly,
165            Self::TxTooLate => TransactionResultCode::TxTooLate,
166            Self::TxMissingOperation => TransactionResultCode::TxMissingOperation,
167            Self::TxBadSeq => TransactionResultCode::TxBadSeq,
168            Self::TxBadAuth => TransactionResultCode::TxBadAuth,
169            Self::TxInsufficientBalance => TransactionResultCode::TxInsufficientBalance,
170            Self::TxNoAccount => TransactionResultCode::TxNoAccount,
171            Self::TxInsufficientFee => TransactionResultCode::TxInsufficientFee,
172            Self::TxBadAuthExtra => TransactionResultCode::TxBadAuthExtra,
173            Self::TxInternalError => TransactionResultCode::TxInternalError,
174            Self::TxNotSupported => TransactionResultCode::TxNotSupported,
175            Self::TxBadSponsorship => TransactionResultCode::TxBadSponsorship,
176            Self::TxBadMinSeqAgeOrGap => TransactionResultCode::TxBadMinSeqAgeOrGap,
177            Self::TxMalformed => TransactionResultCode::TxMalformed,
178            Self::TxSorobanInvalid => TransactionResultCode::TxSorobanInvalid,
179            Self::TxFrozenKeyAccessed => TransactionResultCode::TxFrozenKeyAccessed,
180        }
181    }
182
183    #[must_use]
184    pub const fn variants() -> [TransactionResultCode; Self::_VARIANTS.len()] {
185        Self::VARIANTS
186    }
187}
188
189impl Name for InnerTransactionResultResult {
190    #[must_use]
191    fn name(&self) -> &'static str {
192        Self::name(self)
193    }
194}
195
196impl Discriminant<TransactionResultCode> for InnerTransactionResultResult {
197    #[must_use]
198    fn discriminant(&self) -> TransactionResultCode {
199        Self::discriminant(self)
200    }
201}
202
203impl Variants<TransactionResultCode> for InnerTransactionResultResult {
204    fn variants() -> slice::Iter<'static, TransactionResultCode> {
205        Self::VARIANTS.iter()
206    }
207}
208
209impl Union<TransactionResultCode> for InnerTransactionResultResult {}
210
211impl ReadXdr for InnerTransactionResultResult {
212    #[cfg(feature = "std")]
213    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
214        r.with_limited_depth(|r| {
215            let dv: TransactionResultCode = <TransactionResultCode as ReadXdr>::read_xdr(r)?;
216            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
217            let v = match dv {
218                TransactionResultCode::TxSuccess => {
219                    Self::TxSuccess(VecM::<OperationResult>::read_xdr(r)?)
220                }
221                TransactionResultCode::TxFailed => {
222                    Self::TxFailed(VecM::<OperationResult>::read_xdr(r)?)
223                }
224                TransactionResultCode::TxTooEarly => Self::TxTooEarly,
225                TransactionResultCode::TxTooLate => Self::TxTooLate,
226                TransactionResultCode::TxMissingOperation => Self::TxMissingOperation,
227                TransactionResultCode::TxBadSeq => Self::TxBadSeq,
228                TransactionResultCode::TxBadAuth => Self::TxBadAuth,
229                TransactionResultCode::TxInsufficientBalance => Self::TxInsufficientBalance,
230                TransactionResultCode::TxNoAccount => Self::TxNoAccount,
231                TransactionResultCode::TxInsufficientFee => Self::TxInsufficientFee,
232                TransactionResultCode::TxBadAuthExtra => Self::TxBadAuthExtra,
233                TransactionResultCode::TxInternalError => Self::TxInternalError,
234                TransactionResultCode::TxNotSupported => Self::TxNotSupported,
235                TransactionResultCode::TxBadSponsorship => Self::TxBadSponsorship,
236                TransactionResultCode::TxBadMinSeqAgeOrGap => Self::TxBadMinSeqAgeOrGap,
237                TransactionResultCode::TxMalformed => Self::TxMalformed,
238                TransactionResultCode::TxSorobanInvalid => Self::TxSorobanInvalid,
239                TransactionResultCode::TxFrozenKeyAccessed => Self::TxFrozenKeyAccessed,
240                #[allow(unreachable_patterns)]
241                _ => return Err(Error::Invalid),
242            };
243            Ok(v)
244        })
245    }
246}
247
248impl WriteXdr for InnerTransactionResultResult {
249    #[cfg(feature = "std")]
250    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
251        w.with_limited_depth(|w| {
252            self.discriminant().write_xdr(w)?;
253            #[allow(clippy::match_same_arms)]
254            match self {
255                Self::TxSuccess(v) => v.write_xdr(w)?,
256                Self::TxFailed(v) => v.write_xdr(w)?,
257                Self::TxTooEarly => ().write_xdr(w)?,
258                Self::TxTooLate => ().write_xdr(w)?,
259                Self::TxMissingOperation => ().write_xdr(w)?,
260                Self::TxBadSeq => ().write_xdr(w)?,
261                Self::TxBadAuth => ().write_xdr(w)?,
262                Self::TxInsufficientBalance => ().write_xdr(w)?,
263                Self::TxNoAccount => ().write_xdr(w)?,
264                Self::TxInsufficientFee => ().write_xdr(w)?,
265                Self::TxBadAuthExtra => ().write_xdr(w)?,
266                Self::TxInternalError => ().write_xdr(w)?,
267                Self::TxNotSupported => ().write_xdr(w)?,
268                Self::TxBadSponsorship => ().write_xdr(w)?,
269                Self::TxBadMinSeqAgeOrGap => ().write_xdr(w)?,
270                Self::TxMalformed => ().write_xdr(w)?,
271                Self::TxSorobanInvalid => ().write_xdr(w)?,
272                Self::TxFrozenKeyAccessed => ().write_xdr(w)?,
273            };
274            Ok(())
275        })
276    }
277}