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
//! Crypto-bank balances primitives.

#[macro_use]
extern crate serde_derive;
extern crate serde;

mod points;
mod reverse;

pub use self::points::*;
pub use self::reverse::*;

/// Account balance.
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
pub struct Balance {
    /// Total assets.
    pub total: u64,
    /// Assets in use.
    pub in_use: u64,
    /// Unused assets.
    pub unused: u64,
    /// Total balance in BTC.
    /// Only for monitoring.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_btc: Option<f64>,
}

impl Balance {
    #[inline]
    pub fn is_zero(&self) -> bool {
        self.total == 0
    }

    #[inline]
    pub fn quote(&self) -> f64 {
        price(self.total)
    }
}