Skip to main content

stellar_xdr/generated/
soroban_resources.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// SorobanResources is an XDR Struct defined as:
5///
6/// ```text
7/// struct SorobanResources
8/// {   
9///     // The ledger footprint of the transaction.
10///     LedgerFootprint footprint;
11///     // The maximum number of instructions this transaction can use
12///     uint32 instructions;
13///
14///     // The maximum number of bytes this transaction can read from disk backed entries
15///     uint32 diskReadBytes;
16///     // The maximum number of bytes this transaction can write to ledger
17///     uint32 writeBytes;
18/// };
19/// ```
20///
21#[cfg_attr(feature = "alloc", derive(Default))]
22#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
23#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
24#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
25#[cfg_attr(
26    all(feature = "serde", feature = "alloc"),
27    serde_with::serde_as,
28    derive(serde::Serialize, serde::Deserialize),
29    serde(rename_all = "snake_case")
30)]
31#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
32pub struct SorobanResources {
33    pub footprint: LedgerFootprint,
34    pub instructions: u32,
35    pub disk_read_bytes: u32,
36    pub write_bytes: u32,
37}
38
39impl ReadXdr for SorobanResources {
40    #[cfg(feature = "std")]
41    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
42        r.with_limited_depth(|r| {
43            Ok(Self {
44                footprint: LedgerFootprint::read_xdr(r)?,
45                instructions: u32::read_xdr(r)?,
46                disk_read_bytes: u32::read_xdr(r)?,
47                write_bytes: u32::read_xdr(r)?,
48            })
49        })
50    }
51}
52
53impl WriteXdr for SorobanResources {
54    #[cfg(feature = "std")]
55    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
56        w.with_limited_depth(|w| {
57            self.footprint.write_xdr(w)?;
58            self.instructions.write_xdr(w)?;
59            self.disk_read_bytes.write_xdr(w)?;
60            self.write_bytes.write_xdr(w)?;
61            Ok(())
62        })
63    }
64}