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
crate::ix!();
pub fn connect_and_callrpc(
rh: &mut Box<dyn BaseRequestHandler>,
str_method: &str,
args: &Vec<String>,
rpcwallet: Option<&str>) -> Result<UniValue,StdException> {
let mut response: UniValue = UniValue::from(uni_value::VType::VOBJ);
let wait: bool =
G_ARGS
.lock()
.get_bool_arg("-rpcwait", false);;
let timeout: i64 =
G_ARGS
.lock()
.get_int_arg("-rpcwaittimeout", DEFAULT_WAIT_CLIENT_TIMEOUT.into())
.try_into()
.unwrap();
let deadline = get_time() + Duration::seconds(timeout);
loop {
let mut try_block = || -> TryBlockResult::<_,StdException> {
response = callrpc(rh,str_method,args,rpcwallet).unwrap();
if wait {
let error: &UniValue = find_value(&response,"error");
if !error.is_null() && error["code"].get_int() == RPCErrorCode::RPC_IN_WARMUP.bits() {
return TryBlockResult::Err(connection_failed("server in warmup"));
}
}
TryBlockResult::Break
};
match try_block() {
TryBlockResult::Return(v) => return v,
TryBlockResult::Err(e) => {
let now = get_time();
if wait && (timeout <= 0 || now < deadline) {
uninterruptible_sleep(Duration::seconds(1));
} else {
let msg = format!("timeout on transient error: {:?}",e);
return Err(connection_failed(&msg));
}
},
TryBlockResult::Break => { break; }
TryBlockResult::Success => { }
}
if !wait {
break;
}
}
Ok(response)
}