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

@ -9957,7 +9957,7 @@ pub mod tests {
// Store an account
let lamports = 42;
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
account.lamports = lamports;
account.set_lamports(lamports);
db.store_uncached(slot, &[(&pubkey, &account)]);
// Set the slot as a root so account loads will see the contents of this slot
@ -10032,7 +10032,7 @@ pub mod tests {
// Store an account
let lamports = 42;
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
account.lamports = lamports;
account.set_lamports(lamports);
db.store_uncached(slot, &[(&pubkey, &account)]);
let t_purge_slot = {

View File

@ -1458,8 +1458,8 @@ mod tests {
self
}
pub fn lamports(mut self, pre: u64, post: u64) -> Self {
self.pre.account.borrow_mut().lamports = pre;
self.post.lamports = post;
self.pre.account.borrow_mut().set_lamports(pre);
self.post.set_lamports(post);
self
}
pub fn owner(mut self, post: &Pubkey) -> Self {

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(())
}