Skip to main content

stellar_xdr/generated/
operation.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// Operation is an XDR Struct defined as:
5///
6/// ```text
7/// struct Operation
8/// {
9///     // sourceAccount is the account used to run the operation
10///     // if not set, the runtime defaults to "sourceAccount" specified at
11///     // the transaction level
12///     MuxedAccount* sourceAccount;
13///
14///     union switch (OperationType type)
15///     {
16///     case CREATE_ACCOUNT:
17///         CreateAccountOp createAccountOp;
18///     case PAYMENT:
19///         PaymentOp paymentOp;
20///     case PATH_PAYMENT_STRICT_RECEIVE:
21///         PathPaymentStrictReceiveOp pathPaymentStrictReceiveOp;
22///     case MANAGE_SELL_OFFER:
23///         ManageSellOfferOp manageSellOfferOp;
24///     case CREATE_PASSIVE_SELL_OFFER:
25///         CreatePassiveSellOfferOp createPassiveSellOfferOp;
26///     case SET_OPTIONS:
27///         SetOptionsOp setOptionsOp;
28///     case CHANGE_TRUST:
29///         ChangeTrustOp changeTrustOp;
30///     case ALLOW_TRUST:
31///         AllowTrustOp allowTrustOp;
32///     case ACCOUNT_MERGE:
33///         MuxedAccount destination;
34///     case INFLATION:
35///         void;
36///     case MANAGE_DATA:
37///         ManageDataOp manageDataOp;
38///     case BUMP_SEQUENCE:
39///         BumpSequenceOp bumpSequenceOp;
40///     case MANAGE_BUY_OFFER:
41///         ManageBuyOfferOp manageBuyOfferOp;
42///     case PATH_PAYMENT_STRICT_SEND:
43///         PathPaymentStrictSendOp pathPaymentStrictSendOp;
44///     case CREATE_CLAIMABLE_BALANCE:
45///         CreateClaimableBalanceOp createClaimableBalanceOp;
46///     case CLAIM_CLAIMABLE_BALANCE:
47///         ClaimClaimableBalanceOp claimClaimableBalanceOp;
48///     case BEGIN_SPONSORING_FUTURE_RESERVES:
49///         BeginSponsoringFutureReservesOp beginSponsoringFutureReservesOp;
50///     case END_SPONSORING_FUTURE_RESERVES:
51///         void;
52///     case REVOKE_SPONSORSHIP:
53///         RevokeSponsorshipOp revokeSponsorshipOp;
54///     case CLAWBACK:
55///         ClawbackOp clawbackOp;
56///     case CLAWBACK_CLAIMABLE_BALANCE:
57///         ClawbackClaimableBalanceOp clawbackClaimableBalanceOp;
58///     case SET_TRUST_LINE_FLAGS:
59///         SetTrustLineFlagsOp setTrustLineFlagsOp;
60///     case LIQUIDITY_POOL_DEPOSIT:
61///         LiquidityPoolDepositOp liquidityPoolDepositOp;
62///     case LIQUIDITY_POOL_WITHDRAW:
63///         LiquidityPoolWithdrawOp liquidityPoolWithdrawOp;
64///     case INVOKE_HOST_FUNCTION:
65///         InvokeHostFunctionOp invokeHostFunctionOp;
66///     case EXTEND_FOOTPRINT_TTL:
67///         ExtendFootprintTTLOp extendFootprintTTLOp;
68///     case RESTORE_FOOTPRINT:
69///         RestoreFootprintOp restoreFootprintOp;
70///     }
71///     body;
72/// };
73/// ```
74///
75#[cfg_attr(feature = "alloc", derive(Default))]
76#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
77#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
78#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
79#[cfg_attr(
80    all(feature = "serde", feature = "alloc"),
81    serde_with::serde_as,
82    derive(serde::Serialize, serde::Deserialize),
83    serde(rename_all = "snake_case")
84)]
85#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
86pub struct Operation {
87    pub source_account: Option<MuxedAccount>,
88    pub body: OperationBody,
89}
90
91impl ReadXdr for Operation {
92    #[cfg(feature = "std")]
93    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
94        r.with_limited_depth(|r| {
95            Ok(Self {
96                source_account: Option::<MuxedAccount>::read_xdr(r)?,
97                body: OperationBody::read_xdr(r)?,
98            })
99        })
100    }
101}
102
103impl WriteXdr for Operation {
104    #[cfg(feature = "std")]
105    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
106        w.with_limited_depth(|w| {
107            self.source_account.write_xdr(w)?;
108            self.body.write_xdr(w)?;
109            Ok(())
110        })
111    }
112}