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
|
/*
This file is part of TALER
Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
use std::str::FromStr;
pub const MAIN_BTC: &str = "BITCOINBTC";
pub const REGTEST_BTC: &str = "TESTBTC";
pub const TESTNET_BTC: &str = "DEVBTC";
pub const MAIN_ETH: &str = "ETHEREUMETH";
pub const ROPSTEN_ETH: &str = "ROPSTENETH";
pub const DEV_ETH: &str = "DEVETH";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Currency {
ETH(CurrencyEth),
BTC(CurrencyBtc),
}
impl Currency {
pub const fn to_str(&self) -> &'static str {
match self {
Currency::BTC(btc) => btc.to_str(),
Currency::ETH(eth) => eth.to_str(),
}
}
}
impl FromStr for Currency {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
MAIN_BTC => Currency::BTC(CurrencyBtc::Main),
REGTEST_BTC => Currency::BTC(CurrencyBtc::Test),
TESTNET_BTC => Currency::BTC(CurrencyBtc::Dev),
MAIN_ETH => Currency::ETH(CurrencyEth::Main),
ROPSTEN_ETH => Currency::ETH(CurrencyEth::Ropsten),
DEV_ETH => Currency::ETH(CurrencyEth::Dev),
_ => return Err(()),
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CurrencyBtc {
Main,
Test,
Dev,
}
impl CurrencyBtc {
pub const fn to_str(&self) -> &'static str {
match self {
CurrencyBtc::Main => MAIN_BTC,
CurrencyBtc::Test => REGTEST_BTC,
CurrencyBtc::Dev => TESTNET_BTC,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CurrencyEth {
Main,
Dev,
Ropsten,
}
impl CurrencyEth {
pub const fn to_str(&self) -> &'static str {
match self {
CurrencyEth::Main => MAIN_ETH,
CurrencyEth::Ropsten => ROPSTEN_ETH,
CurrencyEth::Dev => DEV_ETH,
}
}
}
|