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
use crate::Protocol;
use num_bigint::BigInt;
#[derive(Debug)]
pub struct Amount {
pub value: BigInt,
pub currency: Currency,
}
impl Amount {
pub fn from_decimal(protocol: Protocol, amount: f64) -> Self {
let amt = amount * protocol.decimal_multiplier() as f64;
let amt = amt.trunc();
let value = BigInt::from(amt as u64);
Self {
value,
currency: Currency::from(protocol),
}
}
}
#[derive(Debug)]
pub struct Currency {
pub symbol: Symbol,
pub decimals: u32,
}
impl From<Protocol> for Currency {
fn from(p: Protocol) -> Currency {
match p {
Protocol::Bitcoin => Currency {
symbol: Symbol::BTC,
decimals: p.decimals(),
},
_ => unimplemented!(),
}
}
}
#[derive(Debug)]
pub enum Symbol {
BTC,
ETH,
HNS,
NIM,
RVN,
SIA,
}