Skip to main content

stellar_xdr/generated/
transaction.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// Transaction is an XDR Struct defined as:
5///
6/// ```text
7/// struct Transaction
8/// {
9///     // account used to run the transaction
10///     MuxedAccount sourceAccount;
11///
12///     // the fee the sourceAccount will pay
13///     uint32 fee;
14///
15///     // sequence number to consume in the account
16///     SequenceNumber seqNum;
17///
18///     // validity conditions
19///     Preconditions cond;
20///
21///     Memo memo;
22///
23///     Operation operations<MAX_OPS_PER_TX>;
24///
25///     union switch (int v)
26///     {
27///     case 0:
28///         void;
29///     case 1:
30///         SorobanTransactionData sorobanData;
31///     }
32///     ext;
33/// };
34/// ```
35///
36#[cfg_attr(feature = "alloc", derive(Default))]
37#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
38#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
39#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
40#[cfg_attr(
41    all(feature = "serde", feature = "alloc"),
42    serde_with::serde_as,
43    derive(serde::Serialize, serde::Deserialize),
44    serde(rename_all = "snake_case")
45)]
46#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
47pub struct Transaction {
48    pub source_account: MuxedAccount,
49    pub fee: u32,
50    pub seq_num: SequenceNumber,
51    pub cond: Preconditions,
52    pub memo: Memo,
53    pub operations: VecM<Operation, 100>,
54    pub ext: TransactionExt,
55}
56
57impl ReadXdr for Transaction {
58    #[cfg(feature = "std")]
59    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
60        r.with_limited_depth(|r| {
61            Ok(Self {
62                source_account: MuxedAccount::read_xdr(r)?,
63                fee: u32::read_xdr(r)?,
64                seq_num: SequenceNumber::read_xdr(r)?,
65                cond: Preconditions::read_xdr(r)?,
66                memo: Memo::read_xdr(r)?,
67                operations: VecM::<Operation, 100>::read_xdr(r)?,
68                ext: TransactionExt::read_xdr(r)?,
69            })
70        })
71    }
72}
73
74impl WriteXdr for Transaction {
75    #[cfg(feature = "std")]
76    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
77        w.with_limited_depth(|w| {
78            self.source_account.write_xdr(w)?;
79            self.fee.write_xdr(w)?;
80            self.seq_num.write_xdr(w)?;
81            self.cond.write_xdr(w)?;
82            self.memo.write_xdr(w)?;
83            self.operations.write_xdr(w)?;
84            self.ext.write_xdr(w)?;
85            Ok(())
86        })
87    }
88}