Skip to main content

stellar_xdr/generated/
account_entry.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// AccountEntry is an XDR Struct defined as:
5///
6/// ```text
7/// struct AccountEntry
8/// {
9///     AccountID accountID;      // master public key for this account
10///     int64 balance;            // in stroops
11///     SequenceNumber seqNum;    // last sequence number used for this account
12///     uint32 numSubEntries;     // number of sub-entries this account has
13///                               // drives the reserve
14///     AccountID* inflationDest; // Account to vote for during inflation
15///     uint32 flags;             // see AccountFlags
16///
17///     string32 homeDomain; // can be used for reverse federation and memo lookup
18///
19///     // fields used for signatures
20///     // thresholds stores unsigned bytes: [weight of master|low|medium|high]
21///     Thresholds thresholds;
22///
23///     Signer signers<MAX_SIGNERS>; // possible signers for this account
24///
25///     // reserved for future use
26///     union switch (int v)
27///     {
28///     case 0:
29///         void;
30///     case 1:
31///         AccountEntryExtensionV1 v1;
32///     }
33///     ext;
34/// };
35/// ```
36///
37#[cfg_attr(feature = "alloc", derive(Default))]
38#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
39#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
40#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
41#[cfg_attr(
42    all(feature = "serde", feature = "alloc"),
43    serde_with::serde_as,
44    derive(serde::Serialize, serde::Deserialize),
45    serde(rename_all = "snake_case")
46)]
47#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
48pub struct AccountEntry {
49    pub account_id: AccountId,
50    #[cfg_attr(
51        all(feature = "serde", feature = "alloc"),
52        serde_as(as = "NumberOrString")
53    )]
54    pub balance: i64,
55    pub seq_num: SequenceNumber,
56    pub num_sub_entries: u32,
57    pub inflation_dest: Option<AccountId>,
58    pub flags: u32,
59    pub home_domain: String32,
60    pub thresholds: Thresholds,
61    pub signers: VecM<Signer, 20>,
62    pub ext: AccountEntryExt,
63}
64
65impl ReadXdr for AccountEntry {
66    #[cfg(feature = "std")]
67    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
68        r.with_limited_depth(|r| {
69            Ok(Self {
70                account_id: AccountId::read_xdr(r)?,
71                balance: i64::read_xdr(r)?,
72                seq_num: SequenceNumber::read_xdr(r)?,
73                num_sub_entries: u32::read_xdr(r)?,
74                inflation_dest: Option::<AccountId>::read_xdr(r)?,
75                flags: u32::read_xdr(r)?,
76                home_domain: String32::read_xdr(r)?,
77                thresholds: Thresholds::read_xdr(r)?,
78                signers: VecM::<Signer, 20>::read_xdr(r)?,
79                ext: AccountEntryExt::read_xdr(r)?,
80            })
81        })
82    }
83}
84
85impl WriteXdr for AccountEntry {
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.balance.write_xdr(w)?;
91            self.seq_num.write_xdr(w)?;
92            self.num_sub_entries.write_xdr(w)?;
93            self.inflation_dest.write_xdr(w)?;
94            self.flags.write_xdr(w)?;
95            self.home_domain.write_xdr(w)?;
96            self.thresholds.write_xdr(w)?;
97            self.signers.write_xdr(w)?;
98            self.ext.write_xdr(w)?;
99            Ok(())
100        })
101    }
102}