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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use std::fmt;
use std::io;
use std::path::PathBuf;
use crate::core::global::ChainTypes;
use crate::util::LoggingConfig;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WalletConfig {
pub chain_type: Option<ChainTypes>,
pub api_listen_interface: String,
pub api_listen_port: u16,
pub owner_api_listen_port: Option<u16>,
pub api_secret_path: Option<String>,
pub node_api_secret_path: Option<String>,
pub check_node_api_http_addr: String,
pub owner_api_include_foreign: Option<bool>,
pub data_file_dir: String,
pub no_commit_cache: Option<bool>,
pub tls_certificate_file: Option<String>,
pub tls_certificate_key: Option<String>,
pub dark_background_color_scheme: Option<bool>,
pub keybase_notify_ttl: Option<u16>,
}
impl Default for WalletConfig {
fn default() -> WalletConfig {
WalletConfig {
chain_type: Some(ChainTypes::Mainnet),
api_listen_interface: "127.0.0.1".to_string(),
api_listen_port: 3415,
owner_api_listen_port: Some(WalletConfig::default_owner_api_listen_port()),
api_secret_path: Some(".api_secret".to_string()),
node_api_secret_path: Some(".api_secret".to_string()),
check_node_api_http_addr: "http://127.0.0.1:3413".to_string(),
owner_api_include_foreign: Some(false),
data_file_dir: ".".to_string(),
no_commit_cache: Some(false),
tls_certificate_file: None,
tls_certificate_key: None,
dark_background_color_scheme: Some(true),
keybase_notify_ttl: Some(1440),
}
}
}
impl WalletConfig {
pub fn api_listen_addr(&self) -> String {
format!("{}:{}", self.api_listen_interface, self.api_listen_port)
}
pub fn default_owner_api_listen_port() -> u16 {
3420
}
pub fn owner_api_listen_port(&self) -> u16 {
self.owner_api_listen_port
.unwrap_or(WalletConfig::default_owner_api_listen_port())
}
pub fn owner_api_listen_addr(&self) -> String {
format!("127.0.0.1:{}", self.owner_api_listen_port())
}
}
#[derive(Debug)]
pub enum ConfigError {
ParseError(String, String),
FileIOError(String, String),
FileNotFoundError(String),
SerializationError(String),
}
impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ConfigError::ParseError(ref file_name, ref message) => write!(
f,
"Error parsing configuration file at {} - {}",
file_name, message
),
ConfigError::FileIOError(ref file_name, ref message) => {
write!(f, "{} {}", message, file_name)
}
ConfigError::FileNotFoundError(ref file_name) => {
write!(f, "Configuration file not found: {}", file_name)
}
ConfigError::SerializationError(ref message) => {
write!(f, "Error serializing configuration: {}", message)
}
}
}
}
impl From<io::Error> for ConfigError {
fn from(error: io::Error) -> ConfigError {
ConfigError::FileIOError(
String::from(""),
String::from(format!("Error loading config file: {}", error)),
)
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct GlobalWalletConfig {
pub config_file_path: Option<PathBuf>,
pub members: Option<GlobalWalletConfigMembers>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct GlobalWalletConfigMembers {
#[serde(default)]
pub wallet: WalletConfig,
pub logging: Option<LoggingConfig>,
}