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