bank.withdraw uses checked_sub_lamports (#16848)

* bank.withdraw uses checked_sub_lamports

* retain previous codepath for error

* map_err from clippy
This commit is contained in:
Jeff Washington (jwash) 2021-04-27 09:58:41 -05:00 committed by GitHub
parent 69bfbf9e98
commit d533f77301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4034,8 +4034,9 @@ impl Bank {
.checked_add(min_balance)
.filter(|required_balance| *required_balance <= account.lamports())
.ok_or(TransactionError::InsufficientFundsForFee)?;
account.lamports -= lamports;
account
.checked_sub_lamports(lamports)
.map_err(|_| TransactionError::InsufficientFundsForFee)?;
self.store_account(pubkey, &account);
Ok(())