stellar_xdr/generated/
transaction_envelope.rs1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
20#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
21#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
22#[cfg_attr(
23 all(feature = "serde", feature = "alloc"),
24 serde_with::serde_as,
25 derive(serde::Serialize, serde::Deserialize),
26 serde(rename_all = "snake_case")
27)]
28#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
29#[allow(clippy::large_enum_variant)]
30pub enum TransactionEnvelope {
31 TxV0(TransactionV0Envelope),
32 Tx(TransactionV1Envelope),
33 TxFeeBump(FeeBumpTransactionEnvelope),
34}
35
36impl TransactionEnvelope {
37 const _VARIANTS: &[EnvelopeType] = &[
38 EnvelopeType::TxV0,
39 EnvelopeType::Tx,
40 EnvelopeType::TxFeeBump,
41 ];
42 pub const VARIANTS: [EnvelopeType; Self::_VARIANTS.len()] = {
43 let mut arr = [Self::_VARIANTS[0]; Self::_VARIANTS.len()];
44 let mut i = 1;
45 while i < Self::_VARIANTS.len() {
46 arr[i] = Self::_VARIANTS[i];
47 i += 1;
48 }
49 arr
50 };
51 const _VARIANTS_STR: &[&str] = &["TxV0", "Tx", "TxFeeBump"];
52 pub const VARIANTS_STR: [&'static str; Self::_VARIANTS_STR.len()] = {
53 let mut arr = [Self::_VARIANTS_STR[0]; Self::_VARIANTS_STR.len()];
54 let mut i = 1;
55 while i < Self::_VARIANTS_STR.len() {
56 arr[i] = Self::_VARIANTS_STR[i];
57 i += 1;
58 }
59 arr
60 };
61
62 #[must_use]
63 pub const fn name(&self) -> &'static str {
64 match self {
65 Self::TxV0(_) => "TxV0",
66 Self::Tx(_) => "Tx",
67 Self::TxFeeBump(_) => "TxFeeBump",
68 }
69 }
70
71 #[must_use]
72 pub const fn discriminant(&self) -> EnvelopeType {
73 #[allow(clippy::match_same_arms)]
74 match self {
75 Self::TxV0(_) => EnvelopeType::TxV0,
76 Self::Tx(_) => EnvelopeType::Tx,
77 Self::TxFeeBump(_) => EnvelopeType::TxFeeBump,
78 }
79 }
80
81 #[must_use]
82 pub const fn variants() -> [EnvelopeType; Self::_VARIANTS.len()] {
83 Self::VARIANTS
84 }
85}
86
87impl Name for TransactionEnvelope {
88 #[must_use]
89 fn name(&self) -> &'static str {
90 Self::name(self)
91 }
92}
93
94impl Discriminant<EnvelopeType> for TransactionEnvelope {
95 #[must_use]
96 fn discriminant(&self) -> EnvelopeType {
97 Self::discriminant(self)
98 }
99}
100
101impl Variants<EnvelopeType> for TransactionEnvelope {
102 fn variants() -> slice::Iter<'static, EnvelopeType> {
103 Self::VARIANTS.iter()
104 }
105}
106
107impl Union<EnvelopeType> for TransactionEnvelope {}
108
109impl ReadXdr for TransactionEnvelope {
110 #[cfg(feature = "std")]
111 fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
112 r.with_limited_depth(|r| {
113 let dv: EnvelopeType = <EnvelopeType as ReadXdr>::read_xdr(r)?;
114 #[allow(clippy::match_same_arms, clippy::match_wildcard_for_single_variants)]
115 let v = match dv {
116 EnvelopeType::TxV0 => Self::TxV0(TransactionV0Envelope::read_xdr(r)?),
117 EnvelopeType::Tx => Self::Tx(TransactionV1Envelope::read_xdr(r)?),
118 EnvelopeType::TxFeeBump => {
119 Self::TxFeeBump(FeeBumpTransactionEnvelope::read_xdr(r)?)
120 }
121 #[allow(unreachable_patterns)]
122 _ => return Err(Error::Invalid),
123 };
124 Ok(v)
125 })
126 }
127}
128
129impl WriteXdr for TransactionEnvelope {
130 #[cfg(feature = "std")]
131 fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
132 w.with_limited_depth(|w| {
133 self.discriminant().write_xdr(w)?;
134 #[allow(clippy::match_same_arms)]
135 match self {
136 Self::TxV0(v) => v.write_xdr(w)?,
137 Self::Tx(v) => v.write_xdr(w)?,
138 Self::TxFeeBump(v) => v.write_xdr(w)?,
139 };
140 Ok(())
141 })
142 }
143}