1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use super::deserialize;
use resources::base64string::Base64String;
use std::collections::HashMap;

/// In the Stellar network, users interact using accounts which can be controlled by a
/// corresponding keypair that can authorize transactions.
///
/// <https://www.stellar.org/developers/horizon/reference/resources/account.html>
#[derive(Deserialize, Debug)]
pub struct Account {
    id: String,
    account_id: String,
    #[serde(deserialize_with = "deserialize::from_str")]
    sequence: u64,
    subentry_count: u64,
    data: HashMap<String, Base64String>,
}

impl Account {
    /// The canonical id of this account, suitable for use as the :id parameter
    /// for url templates that require an account’s ID. Returns a slice that lives
    /// as long as the account does.
    pub fn id_ref(&self) -> &str {
        &self.id
    }

    /// The account’s public key encoded into a base32 string representation.
    /// Returns a slice that lives as long as the account does.
    pub fn account_id_ref(&self) -> &str {
        &self.account_id
    }

    /// The canonical id of this account, suitable for use as the :id parameter
    /// for url templates that require an account’s ID.
    pub fn id(&self) -> &String {
        &self.id
    }

    /// The account’s public key encoded into a base32 string representation.
    pub fn account_id(&self) -> &String {
        &self.account_id
    }

    /// The current sequence number that can be used when submitting a transaction
    /// from this account.
    pub fn sequence(&self) -> u64 {
        self.sequence
    }

    /// The number of account subentries.  This number is multiplied by
    /// 0.5 to determine the minimum required balance.
    pub fn subentry_count(&self) -> u64 {
        self.subentry_count
    }

    /// A key/value store of data attached to this account.
    pub fn data(&self) -> &HashMap<String, Base64String> {
        &self.data
    }
}