Set lamports (#16747)
* lamports = -> set_lamports() * .lamports = X -> .set_lamports(X)
This commit is contained in:
committed by
GitHub
parent
8d9d6b62d9
commit
8a6b80095e
@ -9957,7 +9957,7 @@ pub mod tests {
|
|||||||
// Store an account
|
// Store an account
|
||||||
let lamports = 42;
|
let lamports = 42;
|
||||||
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
||||||
account.lamports = lamports;
|
account.set_lamports(lamports);
|
||||||
db.store_uncached(slot, &[(&pubkey, &account)]);
|
db.store_uncached(slot, &[(&pubkey, &account)]);
|
||||||
|
|
||||||
// Set the slot as a root so account loads will see the contents of this slot
|
// 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
|
// Store an account
|
||||||
let lamports = 42;
|
let lamports = 42;
|
||||||
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
let mut account = AccountSharedData::new(1, 0, &AccountSharedData::default().owner);
|
||||||
account.lamports = lamports;
|
account.set_lamports(lamports);
|
||||||
db.store_uncached(slot, &[(&pubkey, &account)]);
|
db.store_uncached(slot, &[(&pubkey, &account)]);
|
||||||
|
|
||||||
let t_purge_slot = {
|
let t_purge_slot = {
|
||||||
|
@ -1458,8 +1458,8 @@ mod tests {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn lamports(mut self, pre: u64, post: u64) -> Self {
|
pub fn lamports(mut self, pre: u64, post: u64) -> Self {
|
||||||
self.pre.account.borrow_mut().lamports = pre;
|
self.pre.account.borrow_mut().set_lamports(pre);
|
||||||
self.post.lamports = post;
|
self.post.set_lamports(post);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub fn owner(mut self, post: &Pubkey) -> Self {
|
pub fn owner(mut self, post: &Pubkey) -> Self {
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
account_utils::State as AccountUtilsState, ic_msg, keyed_account::KeyedAccount,
|
account::{ReadableAccount, WritableAccount},
|
||||||
nonce_account::create_account, process_instruction::InvokeContext,
|
account_utils::State as AccountUtilsState,
|
||||||
|
ic_msg,
|
||||||
|
keyed_account::KeyedAccount,
|
||||||
|
nonce_account::create_account,
|
||||||
|
process_instruction::InvokeContext,
|
||||||
};
|
};
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
instruction::{checked_add, InstructionError},
|
instruction::{checked_add, InstructionError},
|
||||||
@ -153,14 +157,18 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
|||||||
return Err(InstructionError::MissingRequiredSignature);
|
return Err(InstructionError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
let nonce_balance = self.try_account_ref_mut()?.lamports;
|
let nonce_balance = self.try_account_ref_mut()?.lamports();
|
||||||
self.try_account_ref_mut()?.lamports = nonce_balance
|
self.try_account_ref_mut()?.set_lamports(
|
||||||
|
nonce_balance
|
||||||
.checked_sub(lamports)
|
.checked_sub(lamports)
|
||||||
.ok_or(InstructionError::ArithmeticOverflow)?;
|
.ok_or(InstructionError::ArithmeticOverflow)?,
|
||||||
let to_balance = to.try_account_ref_mut()?.lamports;
|
);
|
||||||
to.try_account_ref_mut()?.lamports = to_balance
|
let to_balance = to.try_account_ref_mut()?.lamports();
|
||||||
|
to.try_account_ref_mut()?.set_lamports(
|
||||||
|
to_balance
|
||||||
.checked_add(lamports)
|
.checked_add(lamports)
|
||||||
.ok_or(InstructionError::ArithmeticOverflow)?;
|
.ok_or(InstructionError::ArithmeticOverflow)?,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user