mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-10-05 18:47:22 +03:00
error instead of panic on invalid balance
This commit is contained in:
parent
b9667ef190
commit
f25ce4cbcc
@ -306,5 +306,11 @@ create_messages!(
|
||||
msg: "Failed to confirm transaction".to_string(),
|
||||
help: None,
|
||||
}
|
||||
|
||||
|
||||
@backtraced
|
||||
invalid_balance {
|
||||
args: (account: impl Display),
|
||||
msg: format!("Invalid public balance for account: {account}"),
|
||||
help: Some("Make sure the account has enough balance to pay for the deployment.".to_string()),
|
||||
}
|
||||
);
|
||||
|
@ -261,8 +261,12 @@ fn check_balance<N: Network>(
|
||||
.execute(Context::new(context.path.clone(), context.home.clone(), true)?)?;
|
||||
// Remove the last 3 characters since they represent the `u64` suffix.
|
||||
public_balance.truncate(public_balance.len() - 3);
|
||||
// This unwrap is safe as the Query will error if it cannot retrieve a public balance, and if it returns a balance that will be a u64.
|
||||
let balance = public_balance.parse::<u64>().unwrap();
|
||||
// Make sure the balance is valid.
|
||||
let balance = if let Ok(credits) = public_balance.parse::<u64>() {
|
||||
credits
|
||||
} else {
|
||||
return Err(CliError::invalid_balance(address).into());
|
||||
};
|
||||
// Compare balance.
|
||||
if balance < total_cost {
|
||||
Err(PackageError::insufficient_balance(address, public_balance, total_cost).into())
|
||||
|
Loading…
Reference in New Issue
Block a user