Skip to main content

stellar_xdr/generated/
trust_line_entry.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// TrustLineEntry is an XDR Struct defined as:
5///
6/// ```text
7/// struct TrustLineEntry
8/// {
9///     AccountID accountID;  // account this trustline belongs to
10///     TrustLineAsset asset; // type of asset (with issuer)
11///     int64 balance;        // how much of this asset the user has.
12///                           // Asset defines the unit for this;
13///
14///     int64 limit;  // balance cannot be above this
15///     uint32 flags; // see TrustLineFlags
16///
17///     // reserved for future use
18///     union switch (int v)
19///     {
20///     case 0:
21///         void;
22///     case 1:
23///         struct
24///         {
25///             Liabilities liabilities;
26///
27///             union switch (int v)
28///             {
29///             case 0:
30///                 void;
31///             case 2:
32///                 TrustLineEntryExtensionV2 v2;
33///             }
34///             ext;
35///         } v1;
36///     }
37///     ext;
38/// };
39/// ```
40///
41#[cfg_attr(feature = "alloc", derive(Default))]
42#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
43#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
44#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
45#[cfg_attr(
46    all(feature = "serde", feature = "alloc"),
47    serde_with::serde_as,
48    derive(serde::Serialize, serde::Deserialize),
49    serde(rename_all = "snake_case")
50)]
51#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
52pub struct TrustLineEntry {
53    pub account_id: AccountId,
54    pub asset: TrustLineAsset,
55    #[cfg_attr(
56        all(feature = "serde", feature = "alloc"),
57        serde_as(as = "NumberOrString")
58    )]
59    pub balance: i64,
60    #[cfg_attr(
61        all(feature = "serde", feature = "alloc"),
62        serde_as(as = "NumberOrString")
63    )]
64    pub limit: i64,
65    pub flags: u32,
66    pub ext: TrustLineEntryExt,
67}
68
69impl ReadXdr for TrustLineEntry {
70    #[cfg(feature = "std")]
71    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
72        r.with_limited_depth(|r| {
73            Ok(Self {
74                account_id: AccountId::read_xdr(r)?,
75                asset: TrustLineAsset::read_xdr(r)?,
76                balance: i64::read_xdr(r)?,
77                limit: i64::read_xdr(r)?,
78                flags: u32::read_xdr(r)?,
79                ext: TrustLineEntryExt::read_xdr(r)?,
80            })
81        })
82    }
83}
84
85impl WriteXdr for TrustLineEntry {
86    #[cfg(feature = "std")]
87    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
88        w.with_limited_depth(|w| {
89            self.account_id.write_xdr(w)?;
90            self.asset.write_xdr(w)?;
91            self.balance.write_xdr(w)?;
92            self.limit.write_xdr(w)?;
93            self.flags.write_xdr(w)?;
94            self.ext.write_xdr(w)?;
95            Ok(())
96        })
97    }
98}