Skip to main content

stellar_xdr/generated/
operation_type.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// OperationType is an XDR Enum defined as:
5///
6/// ```text
7/// enum OperationType
8/// {
9///     CREATE_ACCOUNT = 0,
10///     PAYMENT = 1,
11///     PATH_PAYMENT_STRICT_RECEIVE = 2,
12///     MANAGE_SELL_OFFER = 3,
13///     CREATE_PASSIVE_SELL_OFFER = 4,
14///     SET_OPTIONS = 5,
15///     CHANGE_TRUST = 6,
16///     ALLOW_TRUST = 7,
17///     ACCOUNT_MERGE = 8,
18///     INFLATION = 9,
19///     MANAGE_DATA = 10,
20///     BUMP_SEQUENCE = 11,
21///     MANAGE_BUY_OFFER = 12,
22///     PATH_PAYMENT_STRICT_SEND = 13,
23///     CREATE_CLAIMABLE_BALANCE = 14,
24///     CLAIM_CLAIMABLE_BALANCE = 15,
25///     BEGIN_SPONSORING_FUTURE_RESERVES = 16,
26///     END_SPONSORING_FUTURE_RESERVES = 17,
27///     REVOKE_SPONSORSHIP = 18,
28///     CLAWBACK = 19,
29///     CLAWBACK_CLAIMABLE_BALANCE = 20,
30///     SET_TRUST_LINE_FLAGS = 21,
31///     LIQUIDITY_POOL_DEPOSIT = 22,
32///     LIQUIDITY_POOL_WITHDRAW = 23,
33///     INVOKE_HOST_FUNCTION = 24,
34///     EXTEND_FOOTPRINT_TTL = 25,
35///     RESTORE_FOOTPRINT = 26
36/// };
37/// ```
38///
39// enum
40#[cfg_attr(feature = "alloc", derive(Default))]
41#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
42#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
43#[cfg_attr(
44    all(feature = "serde", feature = "alloc"),
45    derive(serde::Serialize, serde::Deserialize),
46    serde(rename_all = "snake_case")
47)]
48#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
49#[repr(i32)]
50pub enum OperationType {
51    #[cfg_attr(feature = "alloc", default)]
52    CreateAccount = 0,
53    Payment = 1,
54    PathPaymentStrictReceive = 2,
55    ManageSellOffer = 3,
56    CreatePassiveSellOffer = 4,
57    SetOptions = 5,
58    ChangeTrust = 6,
59    AllowTrust = 7,
60    AccountMerge = 8,
61    Inflation = 9,
62    ManageData = 10,
63    BumpSequence = 11,
64    ManageBuyOffer = 12,
65    PathPaymentStrictSend = 13,
66    CreateClaimableBalance = 14,
67    ClaimClaimableBalance = 15,
68    BeginSponsoringFutureReserves = 16,
69    EndSponsoringFutureReserves = 17,
70    RevokeSponsorship = 18,
71    Clawback = 19,
72    ClawbackClaimableBalance = 20,
73    SetTrustLineFlags = 21,
74    LiquidityPoolDeposit = 22,
75    LiquidityPoolWithdraw = 23,
76    InvokeHostFunction = 24,
77    ExtendFootprintTtl = 25,
78    RestoreFootprint = 26,
79}
80
81impl OperationType {
82    const _VARIANTS: &[OperationType] = &[
83        OperationType::CreateAccount,
84        OperationType::Payment,
85        OperationType::PathPaymentStrictReceive,
86        OperationType::ManageSellOffer,
87        OperationType::CreatePassiveSellOffer,
88        OperationType::SetOptions,
89        OperationType::ChangeTrust,
90        OperationType::AllowTrust,
91        OperationType::AccountMerge,
92        OperationType::Inflation,
93        OperationType::ManageData,
94        OperationType::BumpSequence,
95        OperationType::ManageBuyOffer,
96        OperationType::PathPaymentStrictSend,
97        OperationType::CreateClaimableBalance,
98        OperationType::ClaimClaimableBalance,
99        OperationType::BeginSponsoringFutureReserves,
100        OperationType::EndSponsoringFutureReserves,
101        OperationType::RevokeSponsorship,
102        OperationType::Clawback,
103        OperationType::ClawbackClaimableBalance,
104        OperationType::SetTrustLineFlags,
105        OperationType::LiquidityPoolDeposit,
106        OperationType::LiquidityPoolWithdraw,
107        OperationType::InvokeHostFunction,
108        OperationType::ExtendFootprintTtl,
109        OperationType::RestoreFootprint,
110    ];
111    pub const VARIANTS: [OperationType; Self::_VARIANTS.len()] = {
112        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
113        let mut i = 1;
114        while i < Self::_VARIANTS.len() {
115            arr[i] = Self::_VARIANTS[i];
116            i += 1;
117        }
118        arr
119    };
120    const _VARIANTS_STR: &[&str] = &[
121        "CreateAccount",
122        "Payment",
123        "PathPaymentStrictReceive",
124        "ManageSellOffer",
125        "CreatePassiveSellOffer",
126        "SetOptions",
127        "ChangeTrust",
128        "AllowTrust",
129        "AccountMerge",
130        "Inflation",
131        "ManageData",
132        "BumpSequence",
133        "ManageBuyOffer",
134        "PathPaymentStrictSend",
135        "CreateClaimableBalance",
136        "ClaimClaimableBalance",
137        "BeginSponsoringFutureReserves",
138        "EndSponsoringFutureReserves",
139        "RevokeSponsorship",
140        "Clawback",
141        "ClawbackClaimableBalance",
142        "SetTrustLineFlags",
143        "LiquidityPoolDeposit",
144        "LiquidityPoolWithdraw",
145        "InvokeHostFunction",
146        "ExtendFootprintTtl",
147        "RestoreFootprint",
148    ];
149    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
150        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
151        let mut i = 1;
152        while i < Self::_VARIANTS_STR.len() {
153            arr[i] = Self::_VARIANTS_STR[i];
154            i += 1;
155        }
156        arr
157    };
158
159    #[must_use]
160    pub const fn name(&self) -> &'static str {
161        match self {
162            Self::CreateAccount => "CreateAccount",
163            Self::Payment => "Payment",
164            Self::PathPaymentStrictReceive => "PathPaymentStrictReceive",
165            Self::ManageSellOffer => "ManageSellOffer",
166            Self::CreatePassiveSellOffer => "CreatePassiveSellOffer",
167            Self::SetOptions => "SetOptions",
168            Self::ChangeTrust => "ChangeTrust",
169            Self::AllowTrust => "AllowTrust",
170            Self::AccountMerge => "AccountMerge",
171            Self::Inflation => "Inflation",
172            Self::ManageData => "ManageData",
173            Self::BumpSequence => "BumpSequence",
174            Self::ManageBuyOffer => "ManageBuyOffer",
175            Self::PathPaymentStrictSend => "PathPaymentStrictSend",
176            Self::CreateClaimableBalance => "CreateClaimableBalance",
177            Self::ClaimClaimableBalance => "ClaimClaimableBalance",
178            Self::BeginSponsoringFutureReserves => "BeginSponsoringFutureReserves",
179            Self::EndSponsoringFutureReserves => "EndSponsoringFutureReserves",
180            Self::RevokeSponsorship => "RevokeSponsorship",
181            Self::Clawback => "Clawback",
182            Self::ClawbackClaimableBalance => "ClawbackClaimableBalance",
183            Self::SetTrustLineFlags => "SetTrustLineFlags",
184            Self::LiquidityPoolDeposit => "LiquidityPoolDeposit",
185            Self::LiquidityPoolWithdraw => "LiquidityPoolWithdraw",
186            Self::InvokeHostFunction => "InvokeHostFunction",
187            Self::ExtendFootprintTtl => "ExtendFootprintTtl",
188            Self::RestoreFootprint => "RestoreFootprint",
189        }
190    }
191
192    #[must_use]
193    pub const fn variants() -> [OperationType; Self::_VARIANTS.len()] {
194        Self::VARIANTS
195    }
196}
197
198impl Name for OperationType {
199    #[must_use]
200    fn name(&self) -> &'static str {
201        Self::name(self)
202    }
203}
204
205impl Variants<OperationType> for OperationType {
206    fn variants() -> slice::Iter<'static, OperationType> {
207        Self::VARIANTS.iter()
208    }
209}
210
211impl Enum for OperationType {}
212
213impl fmt::Display for OperationType {
214    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
215        f.write_str(self.name())
216    }
217}
218
219impl TryFrom<i32> for OperationType {
220    type Error = Error;
221
222    fn try_from(i: i32) -> Result<Self, Error> {
223        let e = match i {
224            0 => OperationType::CreateAccount,
225            1 => OperationType::Payment,
226            2 => OperationType::PathPaymentStrictReceive,
227            3 => OperationType::ManageSellOffer,
228            4 => OperationType::CreatePassiveSellOffer,
229            5 => OperationType::SetOptions,
230            6 => OperationType::ChangeTrust,
231            7 => OperationType::AllowTrust,
232            8 => OperationType::AccountMerge,
233            9 => OperationType::Inflation,
234            10 => OperationType::ManageData,
235            11 => OperationType::BumpSequence,
236            12 => OperationType::ManageBuyOffer,
237            13 => OperationType::PathPaymentStrictSend,
238            14 => OperationType::CreateClaimableBalance,
239            15 => OperationType::ClaimClaimableBalance,
240            16 => OperationType::BeginSponsoringFutureReserves,
241            17 => OperationType::EndSponsoringFutureReserves,
242            18 => OperationType::RevokeSponsorship,
243            19 => OperationType::Clawback,
244            20 => OperationType::ClawbackClaimableBalance,
245            21 => OperationType::SetTrustLineFlags,
246            22 => OperationType::LiquidityPoolDeposit,
247            23 => OperationType::LiquidityPoolWithdraw,
248            24 => OperationType::InvokeHostFunction,
249            25 => OperationType::ExtendFootprintTtl,
250            26 => OperationType::RestoreFootprint,
251            #[allow(unreachable_patterns)]
252            _ => return Err(Error::Invalid),
253        };
254        Ok(e)
255    }
256}
257
258impl From<OperationType> for i32 {
259    #[must_use]
260    fn from(e: OperationType) -> Self {
261        e as Self
262    }
263}
264
265impl ReadXdr for OperationType {
266    #[cfg(feature = "std")]
267    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
268        r.with_limited_depth(|r| {
269            let e = i32::read_xdr(r)?;
270            let v: Self = e.try_into()?;
271            Ok(v)
272        })
273    }
274}
275
276impl WriteXdr for OperationType {
277    #[cfg(feature = "std")]
278    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
279        w.with_limited_depth(|w| {
280            let i: i32 = (*self).into();
281            i.write_xdr(w)
282        })
283    }
284}