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
crate::ix!();
pub fn parse_result(
result: &UniValue,
str_print: &mut String) {
if result.is_null() {
return;
}
*str_print = match result.is_str() {
true => result.get_str().to_string(),
false => {
let pretty_indent = Some(2);
result.write(pretty_indent,None)
}
};
}
pub fn parse_error(
error: &UniValue,
str_print: &mut String,
n_ret: &mut i32) {
if error.is_object() {
let err_code: &UniValue = find_value(error,"code");
let err_msg: &UniValue = find_value(error,"message");
if !err_code.is_null() {
*str_print = format!{
"error code: {}\n", err_code.get_val_str()
};
}
if err_msg.is_str() {
*str_print += format!(
"error message:\n{}",
err_msg.get_str()
).as_str();
}
if err_code.is_num()
&& err_code.get_int() == RPCErrorCode::RPC_WALLET_NOT_SPECIFIED.bits()
{
*str_print += format!{
"\nTry adding \"-rpcwallet=<filename>\" option to bitcoin-cli command line."
}.as_str();
}
} else {
*str_print = format!{"error: {}", error.write(None,None)};
}
*n_ret = unsafe {
abs(error["code"].get_int())
};
}