Cleanly handle balance underflows

This commit is contained in:
Michael Vines 2019-01-15 16:14:24 -08:00
parent 3f9c2bc33b
commit 9354e797b6
1 changed files with 11 additions and 1 deletions

View File

@ -360,8 +360,18 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
.as_u64()
.unwrap_or(previous_balance);
if current_balance < previous_balance {
Err(format!(
"Airdrop failed: current_balance({}) < previous_balance({})",
current_balance, previous_balance
))?;
}
if current_balance - previous_balance < tokens {
Err("Airdrop failed!")?;
Err(format!(
"Airdrop failed: Account balance increased by {} instead of {}",
current_balance - previous_balance,
tokens
))?;
}
Ok(format!("Your balance is: {:?}", current_balance))
}