1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
68#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
69#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
70#[cfg_attr(
71 all(feature = "serde", feature = "alloc"),
72 serde_with::serde_as,
73 derive(serde::Serialize, serde::Deserialize),
74 serde(rename_all = "snake_case")
75)]
76#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
77#[allow(clippy::large_enum_variant)]
78pub enum OperationBody {
79 CreateAccount(CreateAccountOp),
80 Payment(PaymentOp),
81 PathPaymentStrictReceive(PathPaymentStrictReceiveOp),
82 ManageSellOffer(ManageSellOfferOp),
83 CreatePassiveSellOffer(CreatePassiveSellOfferOp),
84 SetOptions(SetOptionsOp),
85 ChangeTrust(ChangeTrustOp),
86 AllowTrust(AllowTrustOp),
87 AccountMerge(MuxedAccount),
88 Inflation,
89 ManageData(ManageDataOp),
90 BumpSequence(BumpSequenceOp),
91 ManageBuyOffer(ManageBuyOfferOp),
92 PathPaymentStrictSend(PathPaymentStrictSendOp),
93 CreateClaimableBalance(CreateClaimableBalanceOp),
94 ClaimClaimableBalance(ClaimClaimableBalanceOp),
95 BeginSponsoringFutureReserves(BeginSponsoringFutureReservesOp),
96 EndSponsoringFutureReserves,
97 RevokeSponsorship(RevokeSponsorshipOp),
98 Clawback(ClawbackOp),
99 ClawbackClaimableBalance(ClawbackClaimableBalanceOp),
100 SetTrustLineFlags(SetTrustLineFlagsOp),
101 LiquidityPoolDeposit(LiquidityPoolDepositOp),
102 LiquidityPoolWithdraw(LiquidityPoolWithdrawOp),
103 InvokeHostFunction(InvokeHostFunctionOp),
104 ExtendFootprintTtl(ExtendFootprintTtlOp),
105 RestoreFootprint(RestoreFootprintOp),
106}
107
108#[cfg(feature = "alloc")]
109impl Default for OperationBody {
110 fn default() -> Self {
111 Self::CreateAccount(CreateAccountOp::default())
112 }
113}
114
115impl OperationBody {
116 const _VARIANTS: &[OperationType] = &[
117 OperationType::CreateAccount,
118 OperationType::Payment,
119 OperationType::PathPaymentStrictReceive,
120 OperationType::ManageSellOffer,
121 OperationType::CreatePassiveSellOffer,
122 OperationType::SetOptions,
123 OperationType::ChangeTrust,
124 OperationType::AllowTrust,
125 OperationType::AccountMerge,
126 OperationType::Inflation,
127 OperationType::ManageData,
128 OperationType::BumpSequence,
129 OperationType::ManageBuyOffer,
130 OperationType::PathPaymentStrictSend,
131 OperationType::CreateClaimableBalance,
132 OperationType::ClaimClaimableBalance,
133 OperationType::BeginSponsoringFutureReserves,
134 OperationType::EndSponsoringFutureReserves,
135 OperationType::RevokeSponsorship,
136 OperationType::Clawback,
137 OperationType::ClawbackClaimableBalance,
138 OperationType::SetTrustLineFlags,
139 OperationType::LiquidityPoolDeposit,
140 OperationType::LiquidityPoolWithdraw,
141 OperationType::InvokeHostFunction,
142 OperationType::ExtendFootprintTtl,
143 OperationType::RestoreFootprint,
144 ];
145 pub const VARIANTS: [OperationType; Self::_VARIANTS.len()] = {
146 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
147 let mut i = 1;
148 while i < Self::_VARIANTS.len() {
149 arr[i] = Self::_VARIANTS[i];
150 i += 1;
151 }
152 arr
153 };
154 const _VARIANTS_STR: &[&str] = &[
155 "CreateAccount",
156 "Payment",
157 "PathPaymentStrictReceive",
158 "ManageSellOffer",
159 "CreatePassiveSellOffer",
160 "SetOptions",
161 "ChangeTrust",
162 "AllowTrust",
163 "AccountMerge",
164 "Inflation",
165 "ManageData",
166 "BumpSequence",
167 "ManageBuyOffer",
168 "PathPaymentStrictSend",
169 "CreateClaimableBalance",
170 "ClaimClaimableBalance",
171 "BeginSponsoringFutureReserves",
172 "EndSponsoringFutureReserves",
173 "RevokeSponsorship",
174 "Clawback",
175 "ClawbackClaimableBalance",
176 "SetTrustLineFlags",
177 "LiquidityPoolDeposit",
178 "LiquidityPoolWithdraw",
179 "InvokeHostFunction",
180 "ExtendFootprintTtl",
181 "RestoreFootprint",
182 ];
183 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
184 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
185 let mut i = 1;
186 while i < Self::_VARIANTS_STR.len() {
187 arr[i] = Self::_VARIANTS_STR[i];
188 i += 1;
189 }
190 arr
191 };
192
193 #[must_use]
194 pub const fn name(&self) -> &'static str {
195 match self {
196 Self::CreateAccount(_) => "CreateAccount",
197 Self::Payment(_) => "Payment",
198 Self::PathPaymentStrictReceive(_) => "PathPaymentStrictReceive",
199 Self::ManageSellOffer(_) => "ManageSellOffer",
200 Self::CreatePassiveSellOffer(_) => "CreatePassiveSellOffer",
201 Self::SetOptions(_) => "SetOptions",
202 Self::ChangeTrust(_) => "ChangeTrust",
203 Self::AllowTrust(_) => "AllowTrust",
204 Self::AccountMerge(_) => "AccountMerge",
205 Self::Inflation => "Inflation",
206 Self::ManageData(_) => "ManageData",
207 Self::BumpSequence(_) => "BumpSequence",
208 Self::ManageBuyOffer(_) => "ManageBuyOffer",
209 Self::PathPaymentStrictSend(_) => "PathPaymentStrictSend",
210 Self::CreateClaimableBalance(_) => "CreateClaimableBalance",
211 Self::ClaimClaimableBalance(_) => "ClaimClaimableBalance",
212 Self::BeginSponsoringFutureReserves(_) => "BeginSponsoringFutureReserves",
213 Self::EndSponsoringFutureReserves => "EndSponsoringFutureReserves",
214 Self::RevokeSponsorship(_) => "RevokeSponsorship",
215 Self::Clawback(_) => "Clawback",
216 Self::ClawbackClaimableBalance(_) => "ClawbackClaimableBalance",
217 Self::SetTrustLineFlags(_) => "SetTrustLineFlags",
218 Self::LiquidityPoolDeposit(_) => "LiquidityPoolDeposit",
219 Self::LiquidityPoolWithdraw(_) => "LiquidityPoolWithdraw",
220 Self::InvokeHostFunction(_) => "InvokeHostFunction",
221 Self::ExtendFootprintTtl(_) => "ExtendFootprintTtl",
222 Self::RestoreFootprint(_) => "RestoreFootprint",
223 }
224 }
225
226 #[must_use]
227 pub const fn discriminant(&self) -> OperationType {
228 #[allow(clippy::match_same_arms)]
229 match self {
230 Self::CreateAccount(_) => OperationType::CreateAccount,
231 Self::Payment(_) => OperationType::Payment,
232 Self::PathPaymentStrictReceive(_) => OperationType::PathPaymentStrictReceive,
233 Self::ManageSellOffer(_) => OperationType::ManageSellOffer,
234 Self::CreatePassiveSellOffer(_) => OperationType::CreatePassiveSellOffer,
235 Self::SetOptions(_) => OperationType::SetOptions,
236 Self::ChangeTrust(_) => OperationType::ChangeTrust,
237 Self::AllowTrust(_) => OperationType::AllowTrust,
238 Self::AccountMerge(_) => OperationType::AccountMerge,
239 Self::Inflation => OperationType::Inflation,
240 Self::ManageData(_) => OperationType::ManageData,
241 Self::BumpSequence(_) => OperationType::BumpSequence,
242 Self::ManageBuyOffer(_) => OperationType::ManageBuyOffer,
243 Self::PathPaymentStrictSend(_) => OperationType::PathPaymentStrictSend,
244 Self::CreateClaimableBalance(_) => OperationType::CreateClaimableBalance,
245 Self::ClaimClaimableBalance(_) => OperationType::ClaimClaimableBalance,
246 Self::BeginSponsoringFutureReserves(_) => OperationType::BeginSponsoringFutureReserves,
247 Self::EndSponsoringFutureReserves => OperationType::EndSponsoringFutureReserves,
248 Self::RevokeSponsorship(_) => OperationType::RevokeSponsorship,
249 Self::Clawback(_) => OperationType::Clawback,
250 Self::ClawbackClaimableBalance(_) => OperationType::ClawbackClaimableBalance,
251 Self::SetTrustLineFlags(_) => OperationType::SetTrustLineFlags,
252 Self::LiquidityPoolDeposit(_) => OperationType::LiquidityPoolDeposit,
253 Self::LiquidityPoolWithdraw(_) => OperationType::LiquidityPoolWithdraw,
254 Self::InvokeHostFunction(_) => OperationType::InvokeHostFunction,
255 Self::ExtendFootprintTtl(_) => OperationType::ExtendFootprintTtl,
256 Self::RestoreFootprint(_) => OperationType::RestoreFootprint,
257 }
258 }
259
260 #[must_use]
261 pub const fn variants() -> [OperationType; Self::_VARIANTS.len()] {
262 Self::VARIANTS
263 }
264}
265
266impl Name for OperationBody {
267 #[must_use]
268 fn name(&self) -> &'static str {
269 Self::name(self)
270 }
271}
272
273impl Discriminant<OperationType> for OperationBody {
274 #[must_use]
275 fn discriminant(&self) -> OperationType {
276 Self::discriminant(self)
277 }
278}
279
280impl Variants<OperationType> for OperationBody {
281 fn variants() -> slice::Iter<'static, OperationType> {
282 Self::VARIANTS.iter()
283 }
284}
285
286impl Union<OperationType> for OperationBody {}
287
288impl ReadXdr for OperationBody {
289 #[cfg(feature = "std")]
290 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
291 r.with_limited_depth(|r| {
292 let dv: OperationType = <OperationType as ReadXdr>::read_xdr(r)?;
293 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
294 let v = match dv {
295 OperationType::CreateAccount => Self::CreateAccount(CreateAccountOp::read_xdr(r)?),
296 OperationType::Payment => Self::Payment(PaymentOp::read_xdr(r)?),
297 OperationType::PathPaymentStrictReceive => {
298 Self::PathPaymentStrictReceive(PathPaymentStrictReceiveOp::read_xdr(r)?)
299 }
300 OperationType::ManageSellOffer => {
301 Self::ManageSellOffer(ManageSellOfferOp::read_xdr(r)?)
302 }
303 OperationType::CreatePassiveSellOffer => {
304 Self::CreatePassiveSellOffer(CreatePassiveSellOfferOp::read_xdr(r)?)
305 }
306 OperationType::SetOptions => Self::SetOptions(SetOptionsOp::read_xdr(r)?),
307 OperationType::ChangeTrust => Self::ChangeTrust(ChangeTrustOp::read_xdr(r)?),
308 OperationType::AllowTrust => Self::AllowTrust(AllowTrustOp::read_xdr(r)?),
309 OperationType::AccountMerge => Self::AccountMerge(MuxedAccount::read_xdr(r)?),
310 OperationType::Inflation => Self::Inflation,
311 OperationType::ManageData => Self::ManageData(ManageDataOp::read_xdr(r)?),
312 OperationType::BumpSequence => Self::BumpSequence(BumpSequenceOp::read_xdr(r)?),
313 OperationType::ManageBuyOffer => {
314 Self::ManageBuyOffer(ManageBuyOfferOp::read_xdr(r)?)
315 }
316 OperationType::PathPaymentStrictSend => {
317 Self::PathPaymentStrictSend(PathPaymentStrictSendOp::read_xdr(r)?)
318 }
319 OperationType::CreateClaimableBalance => {
320 Self::CreateClaimableBalance(CreateClaimableBalanceOp::read_xdr(r)?)
321 }
322 OperationType::ClaimClaimableBalance => {
323 Self::ClaimClaimableBalance(ClaimClaimableBalanceOp::read_xdr(r)?)
324 }
325 OperationType::BeginSponsoringFutureReserves => {
326 Self::BeginSponsoringFutureReserves(BeginSponsoringFutureReservesOp::read_xdr(
327 r,
328 )?)
329 }
330 OperationType::EndSponsoringFutureReserves => Self::EndSponsoringFutureReserves,
331 OperationType::RevokeSponsorship => {
332 Self::RevokeSponsorship(RevokeSponsorshipOp::read_xdr(r)?)
333 }
334 OperationType::Clawback => Self::Clawback(ClawbackOp::read_xdr(r)?),
335 OperationType::ClawbackClaimableBalance => {
336 Self::ClawbackClaimableBalance(ClawbackClaimableBalanceOp::read_xdr(r)?)
337 }
338 OperationType::SetTrustLineFlags => {
339 Self::SetTrustLineFlags(SetTrustLineFlagsOp::read_xdr(r)?)
340 }
341 OperationType::LiquidityPoolDeposit => {
342 Self::LiquidityPoolDeposit(LiquidityPoolDepositOp::read_xdr(r)?)
343 }
344 OperationType::LiquidityPoolWithdraw => {
345 Self::LiquidityPoolWithdraw(LiquidityPoolWithdrawOp::read_xdr(r)?)
346 }
347 OperationType::InvokeHostFunction => {
348 Self::InvokeHostFunction(InvokeHostFunctionOp::read_xdr(r)?)
349 }
350 OperationType::ExtendFootprintTtl => {
351 Self::ExtendFootprintTtl(ExtendFootprintTtlOp::read_xdr(r)?)
352 }
353 OperationType::RestoreFootprint => {
354 Self::RestoreFootprint(RestoreFootprintOp::read_xdr(r)?)
355 }
356 #[allow(unreachable_patterns)]
357 _ => return Err(Error::Invalid),
358 };
359 Ok(v)
360 })
361 }
362}
363
364impl WriteXdr for OperationBody {
365 #[cfg(feature = "std")]
366 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
367 w.with_limited_depth(|w| {
368 self.discriminant().write_xdr(w)?;
369 #[allow(clippy::match_same_arms)]
370 match self {
371 Self::CreateAccount(v) => v.write_xdr(w)?,
372 Self::Payment(v) => v.write_xdr(w)?,
373 Self::PathPaymentStrictReceive(v) => v.write_xdr(w)?,
374 Self::ManageSellOffer(v) => v.write_xdr(w)?,
375 Self::CreatePassiveSellOffer(v) => v.write_xdr(w)?,
376 Self::SetOptions(v) => v.write_xdr(w)?,
377 Self::ChangeTrust(v) => v.write_xdr(w)?,
378 Self::AllowTrust(v) => v.write_xdr(w)?,
379 Self::AccountMerge(v) => v.write_xdr(w)?,
380 Self::Inflation => ().write_xdr(w)?,
381 Self::ManageData(v) => v.write_xdr(w)?,
382 Self::BumpSequence(v) => v.write_xdr(w)?,
383 Self::ManageBuyOffer(v) => v.write_xdr(w)?,
384 Self::PathPaymentStrictSend(v) => v.write_xdr(w)?,
385 Self::CreateClaimableBalance(v) => v.write_xdr(w)?,
386 Self::ClaimClaimableBalance(v) => v.write_xdr(w)?,
387 Self::BeginSponsoringFutureReserves(v) => v.write_xdr(w)?,
388 Self::EndSponsoringFutureReserves => ().write_xdr(w)?,
389 Self::RevokeSponsorship(v) => v.write_xdr(w)?,
390 Self::Clawback(v) => v.write_xdr(w)?,
391 Self::ClawbackClaimableBalance(v) => v.write_xdr(w)?,
392 Self::SetTrustLineFlags(v) => v.write_xdr(w)?,
393 Self::LiquidityPoolDeposit(v) => v.write_xdr(w)?,
394 Self::LiquidityPoolWithdraw(v) => v.write_xdr(w)?,
395 Self::InvokeHostFunction(v) => v.write_xdr(w)?,
396 Self::ExtendFootprintTtl(v) => v.write_xdr(w)?,
397 Self::RestoreFootprint(v) => v.write_xdr(w)?,
398 };
399 Ok(())
400 })
401 }
402}