Skip to main content

stellar_xdr/generated/
generalized_transaction_set.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// GeneralizedTransactionSet is an XDR Union defined as:
5///
6/// ```text
7/// union GeneralizedTransactionSet switch (int v)
8/// {
9/// // We consider the legacy TransactionSet to be v0.
10/// case 1:
11///     TransactionSetV1 v1TxSet;
12/// };
13/// ```
14///
15// union with discriminant i32
16#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
17#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
18#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
19#[cfg_attr(
20    all(feature = "serde", feature = "alloc"),
21    serde_with::serde_as,
22    derive(serde::Serialize, serde::Deserialize),
23    serde(rename_all = "snake_case")
24)]
25#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
26#[allow(clippy::large_enum_variant)]
27pub enum GeneralizedTransactionSet {
28    V1(TransactionSetV1),
29}
30
31#[cfg(feature = "alloc")]
32impl Default for GeneralizedTransactionSet {
33    fn default() -> Self {
34        Self::V1(TransactionSetV1::default())
35    }
36}
37
38impl GeneralizedTransactionSet {
39    const _VARIANTS: &[i32] = &[1];
40    pub const VARIANTS: [i32; Self::_VARIANTS.len()] = {
41        let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
42        let mut i = 1;
43        while i < Self::_VARIANTS.len() {
44            arr[i] = Self::_VARIANTS[i];
45            i += 1;
46        }
47        arr
48    };
49    const _VARIANTS_STR: &[&str] = &["V1"];
50    pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
51        let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
52        let mut i = 1;
53        while i < Self::_VARIANTS_STR.len() {
54            arr[i] = Self::_VARIANTS_STR[i];
55            i += 1;
56        }
57        arr
58    };
59
60    #[must_use]
61    pub const fn name(&self) -> &'static str {
62        match self {
63            Self::V1(_) => "V1",
64        }
65    }
66
67    #[must_use]
68    pub const fn discriminant(&self) -> i32 {
69        #[allow(clippy::match_same_arms)]
70        match self {
71            Self::V1(_) => 1,
72        }
73    }
74
75    #[must_use]
76    pub const fn variants() -> [i32; Self::_VARIANTS.len()] {
77        Self::VARIANTS
78    }
79}
80
81impl Name for GeneralizedTransactionSet {
82    #[must_use]
83    fn name(&self) -> &'static str {
84        Self::name(self)
85    }
86}
87
88impl Discriminant<i32> for GeneralizedTransactionSet {
89    #[must_use]
90    fn discriminant(&self) -> i32 {
91        Self::discriminant(self)
92    }
93}
94
95impl Variants<i32> for GeneralizedTransactionSet {
96    fn variants() -> slice::Iter<'static, i32> {
97        Self::VARIANTS.iter()
98    }
99}
100
101impl Union<i32> for GeneralizedTransactionSet {}
102
103impl ReadXdr for GeneralizedTransactionSet {
104    #[cfg(feature = "std")]
105    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
106        r.with_limited_depth(|r| {
107            let dv: i32 = <i32 as ReadXdr>::read_xdr(r)?;
108            #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
109            let v = match dv {
110                1 => Self::V1(TransactionSetV1::read_xdr(r)?),
111                #[allow(unreachable_patterns)]
112                _ => return Err(Error::Invalid),
113            };
114            Ok(v)
115        })
116    }
117}
118
119impl WriteXdr for GeneralizedTransactionSet {
120    #[cfg(feature = "std")]
121    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
122        w.with_limited_depth(|w| {
123            self.discriminant().write_xdr(w)?;
124            #[allow(clippy::match_same_arms)]
125            match self {
126                Self::V1(v) => v.write_xdr(w)?,
127            };
128            Ok(())
129        })
130    }
131}