Skip to main content

stellar_xdr/generated/
operation_result.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// OperationResult is an XDR Union defined as:
5///
6/// ```text
7/// union OperationResult switch (OperationResultCode code)
8/// {
9/// case opINNER:
10///     union switch (OperationType type)
11///     {
12///     case CREATE_ACCOUNT:
13///         CreateAccountResult createAccountResult;
14///     case PAYMENT:
15///         PaymentResult paymentResult;
16///     case PATH_PAYMENT_STRICT_RECEIVE:
17///         PathPaymentStrictReceiveResult pathPaymentStrictReceiveResult;
18///     case MANAGE_SELL_OFFER:
19///         ManageSellOfferResult manageSellOfferResult;
20///     case CREATE_PASSIVE_SELL_OFFER:
21///         ManageSellOfferResult createPassiveSellOfferResult;
22///     case SET_OPTIONS:
23///         SetOptionsResult setOptionsResult;
24///     case CHANGE_TRUST:
25///         ChangeTrustResult changeTrustResult;
26///     case ALLOW_TRUST:
27///         AllowTrustResult allowTrustResult;
28///     case ACCOUNT_MERGE:
29///         AccountMergeResult accountMergeResult;
30///     case INFLATION:
31///         InflationResult inflationResult;
32///     case MANAGE_DATA:
33///         ManageDataResult manageDataResult;
34///     case BUMP_SEQUENCE:
35///         BumpSequenceResult bumpSeqResult;
36///     case MANAGE_BUY_OFFER:
37///         ManageBuyOfferResult manageBuyOfferResult;
38///     case PATH_PAYMENT_STRICT_SEND:
39///         PathPaymentStrictSendResult pathPaymentStrictSendResult;
40///     case CREATE_CLAIMABLE_BALANCE:
41///         CreateClaimableBalanceResult createClaimableBalanceResult;
42///     case CLAIM_CLAIMABLE_BALANCE:
43///         ClaimClaimableBalanceResult claimClaimableBalanceResult;
44///     case BEGIN_SPONSORING_FUTURE_RESERVES:
45///         BeginSponsoringFutureReservesResult beginSponsoringFutureReservesResult;
46///     case END_SPONSORING_FUTURE_RESERVES:
47///         EndSponsoringFutureReservesResult endSponsoringFutureReservesResult;
48///     case REVOKE_SPONSORSHIP:
49///         RevokeSponsorshipResult revokeSponsorshipResult;
50///     case CLAWBACK:
51///         ClawbackResult clawbackResult;
52///     case CLAWBACK_CLAIMABLE_BALANCE:
53///         ClawbackClaimableBalanceResult clawbackClaimableBalanceResult;
54///     case SET_TRUST_LINE_FLAGS:
55///         SetTrustLineFlagsResult setTrustLineFlagsResult;
56///     case LIQUIDITY_POOL_DEPOSIT:
57///         LiquidityPoolDepositResult liquidityPoolDepositResult;
58///     case LIQUIDITY_POOL_WITHDRAW:
59///         LiquidityPoolWithdrawResult liquidityPoolWithdrawResult;
60///     case INVOKE_HOST_FUNCTION:
61///         InvokeHostFunctionResult invokeHostFunctionResult;
62///     case EXTEND_FOOTPRINT_TTL:
63///         ExtendFootprintTTLResult extendFootprintTTLResult;
64///     case RESTORE_FOOTPRINT:
65///         RestoreFootprintResult restoreFootprintResult;
66///     }
67///     tr;
68/// case opBAD_AUTH:
69/// case opNO_ACCOUNT:
70/// case opNOT_SUPPORTED:
71/// case opTOO_MANY_SUBENTRIES:
72/// case opEXCEEDED_WORK_LIMIT:
73/// case opTOO_MANY_SPONSORING:
74///     void;
75/// };
76/// ```
77///
78// union with discriminant OperationResultCode
79#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
80#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
81#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
82#[cfg_attr(
83    all(feature = "serde", feature = "alloc"),
84    serde_with::serde_as,
85    derive(serde::Serialize, serde::Deserialize),
86    serde(rename_all = "snake_case")
87)]
88#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
89#[allow(clippy::large_enum_variant)]
90pub enum OperationResult {
91    OpInner(OperationResultTr),
92    OpBadAuth,
93    OpNoAccount,
94    OpNotSupported,
95    OpTooManySubentries,
96    OpExceededWorkLimit,
97    OpTooManySponsoring,
98}
99
100#[cfg(feature = "alloc")]
101impl Default for OperationResult {
102    fn default() -> Self {
103        Self::OpInner(OperationResultTr::default())
104    }
105}
106
107impl OperationResult {
108    const _VARIANTS: &[OperationResultCode] = &[
109        OperationResultCode::OpInner,
110        OperationResultCode::OpBadAuth,
111        OperationResultCode::OpNoAccount,
112        OperationResultCode::OpNotSupported,
113        OperationResultCode::OpTooManySubentries,
114        OperationResultCode::OpExceededWorkLimit,
115        OperationResultCode::OpTooManySponsoring,
116    ];
117    pub const VARIANTS: [OperationResultCode; Self::_VARIANTS.len()] = {
118        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
119        let mut i = 1;
120        while i < Self::_VARIANTS.len() {
121            arr[i] = Self::_VARIANTS[i];
122            i += 1;
123        }
124        arr
125    };
126    const _VARIANTS_STR: &[&str] = &[
127        "OpInner",
128        "OpBadAuth",
129        "OpNoAccount",
130        "OpNotSupported",
131        "OpTooManySubentries",
132        "OpExceededWorkLimit",
133        "OpTooManySponsoring",
134    ];
135    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
136        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
137        let mut i = 1;
138        while i < Self::_VARIANTS_STR.len() {
139            arr[i] = Self::_VARIANTS_STR[i];
140            i += 1;
141        }
142        arr
143    };
144
145    #[must_use]
146    pub const fn name(&self) -> &'static str {
147        match self {
148            Self::OpInner(_) => "OpInner",
149            Self::OpBadAuth => "OpBadAuth",
150            Self::OpNoAccount => "OpNoAccount",
151            Self::OpNotSupported => "OpNotSupported",
152            Self::OpTooManySubentries => "OpTooManySubentries",
153            Self::OpExceededWorkLimit => "OpExceededWorkLimit",
154            Self::OpTooManySponsoring => "OpTooManySponsoring",
155        }
156    }
157
158    #[must_use]
159    pub const fn discriminant(&self) -> OperationResultCode {
160        #[allow(clippy::match_same_arms)]
161        match self {
162            Self::OpInner(_) => OperationResultCode::OpInner,
163            Self::OpBadAuth => OperationResultCode::OpBadAuth,
164            Self::OpNoAccount => OperationResultCode::OpNoAccount,
165            Self::OpNotSupported => OperationResultCode::OpNotSupported,
166            Self::OpTooManySubentries => OperationResultCode::OpTooManySubentries,
167            Self::OpExceededWorkLimit => OperationResultCode::OpExceededWorkLimit,
168            Self::OpTooManySponsoring => OperationResultCode::OpTooManySponsoring,
169        }
170    }
171
172    #[must_use]
173    pub const fn variants() -> [OperationResultCode; Self::_VARIANTS.len()] {
174        Self::VARIANTS
175    }
176}
177
178impl Name for OperationResult {
179    #[must_use]
180    fn name(&self) -> &'static str {
181        Self::name(self)
182    }
183}
184
185impl Discriminant<OperationResultCode> for OperationResult {
186    #[must_use]
187    fn discriminant(&self) -> OperationResultCode {
188        Self::discriminant(self)
189    }
190}
191
192impl Variants<OperationResultCode> for OperationResult {
193    fn variants() -> slice::Iter<'static, OperationResultCode> {
194        Self::VARIANTS.iter()
195    }
196}
197
198impl Union<OperationResultCode> for OperationResult {}
199
200impl ReadXdr for OperationResult {
201    #[cfg(feature = "std")]
202    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
203        r.with_limited_depth(|r| {
204            let dv: OperationResultCode = <OperationResultCode as ReadXdr>::read_xdr(r)?;
205            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
206            let v = match dv {
207                OperationResultCode::OpInner => Self::OpInner(OperationResultTr::read_xdr(r)?),
208                OperationResultCode::OpBadAuth => Self::OpBadAuth,
209                OperationResultCode::OpNoAccount => Self::OpNoAccount,
210                OperationResultCode::OpNotSupported => Self::OpNotSupported,
211                OperationResultCode::OpTooManySubentries => Self::OpTooManySubentries,
212                OperationResultCode::OpExceededWorkLimit => Self::OpExceededWorkLimit,
213                OperationResultCode::OpTooManySponsoring => Self::OpTooManySponsoring,
214                #[allow(unreachable_patterns)]
215                _ => return Err(Error::Invalid),
216            };
217            Ok(v)
218        })
219    }
220}
221
222impl WriteXdr for OperationResult {
223    #[cfg(feature = "std")]
224    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
225        w.with_limited_depth(|w| {
226            self.discriminant().write_xdr(w)?;
227            #[allow(clippy::match_same_arms)]
228            match self {
229                Self::OpInner(v) => v.write_xdr(w)?,
230                Self::OpBadAuth => ().write_xdr(w)?,
231                Self::OpNoAccount => ().write_xdr(w)?,
232                Self::OpNotSupported => ().write_xdr(w)?,
233                Self::OpTooManySubentries => ().write_xdr(w)?,
234                Self::OpExceededWorkLimit => ().write_xdr(w)?,
235                Self::OpTooManySponsoring => ().write_xdr(w)?,
236            };
237            Ok(())
238        })
239    }
240}