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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use crate::Result;
use crate::{
client::{Client, ClientType},
error::ClientError,
types::ClientOptions,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Protocol {
Handshake,
Nimiq,
Bitcoin,
Ethereum,
EthereumClassic,
Ravencoin,
Siacoin,
Chia,
Turtl,
Starcoin,
Unknown,
}
impl Protocol {
pub fn get_client(
&self,
client_type: ClientType,
options: ClientOptions,
) -> Result<Box<Client>> {
match *self {
Protocol::Bitcoin => Ok(crate::clients::bitcoin::get_client(client_type, options)?),
Protocol::Nimiq => Ok(crate::clients::nimiq::get_client(client_type, options)?),
Protocol::Handshake => Ok(crate::clients::handshake::get_client(client_type, options)?),
Protocol::Ethereum => Ok(crate::clients::ethereum::get_client(client_type, options)?),
Protocol::EthereumClassic => Ok(crate::clients::ethereum_classic::get_client(
client_type,
options,
)?),
Protocol::Ravencoin => Ok(crate::clients::ravencoin::get_client(client_type, options)?),
Protocol::Siacoin => Ok(crate::clients::siacoin::get_client(client_type, options)?),
Protocol::Chia => Ok(crate::clients::chia::get_client(client_type, options)?),
Protocol::Turtl => Ok(crate::clients::turtl::get_client(client_type, options)?),
Protocol::Starcoin => Ok(crate::clients::starcoin::get_client(client_type, options)?),
Protocol::Unknown => Err(ClientError::UnknownProtocol),
}
}
pub fn from_str(s: &str) -> Protocol {
match s {
"handshake" | "hns" => Protocol::Handshake,
"nimiq" | "nim" => Protocol::Nimiq,
"bitcoin" | "btc" => Protocol::Bitcoin,
"ethereum" | "eth" => Protocol::Ethereum,
"ethereum classic" | "ethereum_classic" | "etc" => Protocol::EthereumClassic,
"ravencoin" | "raven" | "rvn" => Protocol::Ravencoin,
"siacoin" | "sc" | "sia" => Protocol::Siacoin,
"chiacoin" | "chia" => Protocol::Chia,
"turtl" | "turtlcoin" => Protocol::Turtl,
"starcoin" | "stc" => Protocol::Starcoin,
_ => Protocol::Unknown,
}
}
pub fn hashrate_multiplier(&self) -> u64 {
match *self {
Protocol::Bitcoin => 2_u64.pow(32),
Protocol::Ethereum => 2_u64.pow(32),
Protocol::EthereumClassic => 2_u64.pow(32),
Protocol::Ravencoin => 2_u64.pow(32),
Protocol::Siacoin => 2_u64.pow(32),
Protocol::Chia => 1,
Protocol::Turtl => 1,
Protocol::Starcoin => 1,
Protocol::Nimiq => 2_u64.pow(16),
Protocol::Handshake => 2_u64.pow(32),
Protocol::Unknown => 1,
}
}
pub fn decimals(&self) -> u32 {
match *self {
Protocol::Bitcoin => 8,
_ => 0,
}
}
pub fn decimal_multiplier(&self) -> u64 {
match *self {
Protocol::Bitcoin => 100_000_000,
_ => 0,
}
}
}
impl From<String> for Protocol {
fn from(s: String) -> Self {
Protocol::from_str(&s)
}
}
impl From<&str> for Protocol {
fn from(s: &str) -> Self {
Protocol::from_str(s)
}
}