Set lamports (#16747)

* lamports = -> set_lamports()

* .lamports = X -> .set_lamports(X)
This commit is contained in:
Jeff Washington (jwash)
2021-04-22 13:53:06 -05:00
committed by GitHub
parent 8d9d6b62d9
commit 8a6b80095e
3 changed files with 22 additions and 14 deletions

View File

@ -1,6 +1,10 @@
use crate::{
account_utils::State as AccountUtilsState, ic_msg, keyed_account::KeyedAccount,
nonce_account::create_account, process_instruction::InvokeContext,
account::{ReadableAccount, WritableAccount},
account_utils::State as AccountUtilsState,
ic_msg,
keyed_account::KeyedAccount,
nonce_account::create_account,
process_instruction::InvokeContext,
};
use solana_program::{
instruction::{checked_add, InstructionError},
@ -153,14 +157,18 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
return Err(InstructionError::MissingRequiredSignature);
}
let nonce_balance = self.try_account_ref_mut()?.lamports;
self.try_account_ref_mut()?.lamports = nonce_balance
.checked_sub(lamports)
.ok_or(InstructionError::ArithmeticOverflow)?;
let to_balance = to.try_account_ref_mut()?.lamports;
to.try_account_ref_mut()?.lamports = to_balance
.checked_add(lamports)
.ok_or(InstructionError::ArithmeticOverflow)?;
let nonce_balance = self.try_account_ref_mut()?.lamports();
self.try_account_ref_mut()?.set_lamports(
nonce_balance
.checked_sub(lamports)
.ok_or(InstructionError::ArithmeticOverflow)?,
);
let to_balance = to.try_account_ref_mut()?.lamports();
to.try_account_ref_mut()?.set_lamports(
to_balance
.checked_add(lamports)
.ok_or(InstructionError::ArithmeticOverflow)?,
);
Ok(())
}