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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
crate::ix!();
pub fn parse_get_info_result(result: &mut UniValue) -> Result<(),StdException> {
if !find_value(result,"error").is_null() {
return Ok(());
}
let mut RESET: String = String::new();
let mut GREEN: String = String::new();
let mut BLUE: String = String::new();
let mut YELLOW: String = String::new();
let mut MAGENTA: String = String::new();
let mut CYAN: String = String::new();
let mut should_colorize: bool = false;
#[cfg(not(WIN32))]
if unsafe { isatty(libc::fileno(stdout())) } != 0 {
should_colorize = true;
}
if G_ARGS
.lock()
.is_arg_set("-color")
{
let color: String
= G_ARGS
.lock()
.get_arg("-color", DEFAULT_COLOR_SETTING);
if color == "always" {
should_colorize = true;
} else {
if color == "never" {
should_colorize = false;
} else {
if color != "auto" {
return Err(runtime_error("Invalid value for -color option. Valid values: always, auto, never."));
}
}
}
}
if should_colorize {
RESET = "\x1B[0m".to_string();
GREEN = "\x1B[32m".to_string();
BLUE = "\x1B[34m".to_string();
YELLOW = "\x1B[33m".to_string();
MAGENTA = "\x1B[35m".to_string();
CYAN = "\x1B[36m".to_string();
}
let mut result_string: String = format!("{}Chain: {}{}\n",BLUE,result["chain"].get_val_str(), RESET);
result_string += format!("Blocks: {}\n",result["blocks"].get_val_str()).as_str();
result_string += format!("Headers: {}\n",result["headers"].get_val_str()).as_str();
let ibd_progress: f64 = result["verificationprogress"].get_real();
let mut ibd_progress_bar = String::default();
if ibd_progress < 0.99 {
get_progress_bar(ibd_progress, &mut ibd_progress_bar);
ibd_progress_bar += " ";
}
result_string += format!("Verification progress: {}{:.4}%%\n",ibd_progress_bar,ibd_progress * 100.0).as_str();
result_string += format!("Difficulty: {}\n\n",result["difficulty"].get_val_str()).as_str();
result_string += format!(
"{}Network: in {}, out {}, total {}{}\n",
GREEN,
result["connections"]["in"].get_val_str(),
result["connections"]["out"].get_val_str(),
result["connections"]["total"].get_val_str(),
RESET
).as_str();
result_string += format!("Version: {}\n",result["version"].get_val_str()).as_str();
result_string += format!("Time offset (s): {}\n",result["timeoffset"].get_val_str()).as_str();
let mut proxy_networks = HashMap::<String,Vec::<String>>::default();;
let mut ordered_proxies = Vec::<String>::default();
for network in result["networks"].get_values().unwrap().iter() {
let mut proxy: String = network["proxy"].get_val_str().to_string();
if proxy.is_empty() {
continue;
}
if proxy_networks.get(&proxy) == None {
ordered_proxies.push(proxy.clone());
}
let name = network["name"].get_val_str().to_string();
proxy_networks.get_mut(&proxy).unwrap().push(name);
}
let mut formatted_proxies = Vec::<String>::default();
for proxy in ordered_proxies.iter() {
formatted_proxies.push(
format!(
"{} ({})",
proxy,
join(proxy_networks.get(proxy).unwrap(),", ")
)
);
}
result_string += format!("Proxies: {}\n",match formatted_proxies.is_empty() {
true => "n/a".to_string(),
false => join(&formatted_proxies,", ")
}).as_str();
result_string += format!(
"Min tx relay fee rate ({}/kvB): {}\n\n",
CURRENCY_UNIT,
result["relayfee"].get_val_str()
).as_str();
if !result["has_wallet"].is_null() {
let walletname: &String = result["walletname"].get_val_str();
result_string += format!(
"{}Wallet: {}{}\n",MAGENTA,
match walletname.is_empty() {
true => "\"\"",
false => walletname.as_str()
},
RESET
).as_str();
result_string += format!("Keypool size: {}\n",result["keypoolsize"].get_val_str()).as_str();
if !result["unlocked_until"].is_null() {
result_string += format!("Unlocked until: {}\n",result["unlocked_until"].get_val_str()).as_str();
}
result_string += format!(
"Transaction fee rate (-paytxfee) ({}/kvB): {}\n\n",
CURRENCY_UNIT,
result["paytxfee"].get_val_str()
).as_str();
}
if !result["balance"].is_null() {
result_string += format!("{}Balance:{} {}\n\n",CYAN,RESET,result["balance"].get_val_str()).as_str();
}
if !result["balances"].is_null() {
result_string += format!("{}Balances{}\n",CYAN,RESET).as_str();
let mut max_balance_length: usize = 10;
for wallet in result["balances"].get_keys().unwrap().iter() {
max_balance_length = max(result["balances"][wallet.as_str()].get_val_str().len(),max_balance_length);
}
for wallet in result["balances"].get_keys().unwrap().iter() {
result_string += format!(
"{:max_balance_length$} {}\n",
result["balances"][wallet.as_str()].get_val_str(),
match wallet.is_empty() {
true => "\"\"",
false => wallet
}
).as_str();
}
result_string += "\n";
}
result_string += format!(
"{}Warnings:{} {}",
YELLOW,
RESET,
result["warnings"].get_val_str()
).as_str();
result.set_str(&result_string);
Ok(())
}