poll_get_balance no longer fails intermittently for zero balance accounts
While polling for a non-zero balance, it's not uncommon for one of the get_balance requests to fail with EWOULDBLOCK. Previously when a get_balance request failure occurred on the last iteration of the polling loop, poll_get_balance returned an error even though the N-1 iterations may have successfully retrieved a balance of 0.
This commit is contained in:
parent
f11aa4a57b
commit
308d8c254d
|
@ -196,11 +196,15 @@ impl ThinClient {
|
|||
}
|
||||
|
||||
pub fn poll_get_balance(&mut self, pubkey: &PublicKey) -> io::Result<i64> {
|
||||
let mut balance;
|
||||
let mut balance_result;
|
||||
let mut balance_value = -1;
|
||||
let now = Instant::now();
|
||||
loop {
|
||||
balance = self.get_balance(pubkey);
|
||||
if balance.is_ok() && *balance.as_ref().unwrap() != 0 || now.elapsed().as_secs() > 1 {
|
||||
balance_result = self.get_balance(pubkey);
|
||||
if balance_result.is_ok() {
|
||||
balance_value = *balance_result.as_ref().unwrap();
|
||||
}
|
||||
if balance_value > 0 || now.elapsed().as_secs() > 1 {
|
||||
break;
|
||||
}
|
||||
sleep(Duration::from_millis(100));
|
||||
|
@ -214,7 +218,12 @@ impl ThinClient {
|
|||
)
|
||||
.to_owned(),
|
||||
);
|
||||
balance
|
||||
if balance_value >= 0 {
|
||||
Ok(balance_value)
|
||||
} else {
|
||||
assert!(balance_result.is_err());
|
||||
balance_result
|
||||
}
|
||||
}
|
||||
|
||||
/// Poll the server to confirm a transaction.
|
||||
|
|
Loading…
Reference in New Issue