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
use crate::error::{Error, Result};
use crate::util::JsonDeserializer;
use serde_json::Value;
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct HistoryBalance {
height: u32,
balance: u64,
}
impl HistoryBalance {
pub fn new(height: u32, balance: u64) -> Self {
Self { height, balance }
}
pub fn height(&self) -> u32 {
self.height
}
pub fn balance(&self) -> u64 {
self.balance
}
}
impl TryFrom<&Value> for HistoryBalance {
type Error = Error;
fn try_from(value: &Value) -> Result<Self> {
let height = JsonDeserializer::safe_to_int_from_field(value, "height")?;
let balance = JsonDeserializer::safe_to_int_from_field(value, "balance")?;
Ok(HistoryBalance {
height: height as u32,
balance: balance as u64,
})
}
}