Skip to main content

stellar_xdr/generated/
soroban_transaction_data.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// SorobanTransactionData is an XDR Struct defined as:
5///
6/// ```text
7/// struct SorobanTransactionData
8/// {
9///     union switch (int v)
10///     {
11///     case 0:
12///         void;
13///     case 1:
14///         SorobanResourcesExtV0 resourceExt;
15///     } ext;
16///     SorobanResources resources;
17///     // Amount of the transaction `fee` allocated to the Soroban resource fees.
18///     // The fraction of `resourceFee` corresponding to `resources` specified
19///     // above is *not* refundable (i.e. fees for instructions, ledger I/O), as
20///     // well as fees for the transaction size.
21///     // The remaining part of the fee is refundable and the charged value is
22///     // based on the actual consumption of refundable resources (events, ledger
23///     // rent bumps).
24///     // The `inclusionFee` used for prioritization of the transaction is defined
25///     // as `tx.fee - resourceFee`.
26///     int64 resourceFee;
27/// };
28/// ```
29///
30#[cfg_attr(feature = "alloc", derive(Default))]
31#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
32#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
33#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
34#[cfg_attr(
35    all(feature = "serde", feature = "alloc"),
36    serde_with::serde_as,
37    derive(serde::Serialize, serde::Deserialize),
38    serde(rename_all = "snake_case")
39)]
40#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
41pub struct SorobanTransactionData {
42    pub ext: SorobanTransactionDataExt,
43    pub resources: SorobanResources,
44    #[cfg_attr(
45        all(feature = "serde", feature = "alloc"),
46        serde_as(as = "NumberOrString")
47    )]
48    pub resource_fee: i64,
49}
50
51impl ReadXdr for SorobanTransactionData {
52    #[cfg(feature = "std")]
53    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
54        r.with_limited_depth(|r| {
55            Ok(Self {
56                ext: SorobanTransactionDataExt::read_xdr(r)?,
57                resources: SorobanResources::read_xdr(r)?,
58                resource_fee: i64::read_xdr(r)?,
59            })
60        })
61    }
62}
63
64impl WriteXdr for SorobanTransactionData {
65    #[cfg(feature = "std")]
66    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
67        w.with_limited_depth(|w| {
68            self.ext.write_xdr(w)?;
69            self.resources.write_xdr(w)?;
70            self.resource_fee.write_xdr(w)?;
71            Ok(())
72        })
73    }
74}