Expose executable and rent_epoch in AccountInfo (#8619)
This commit is contained in:
@ -1,8 +1,4 @@
|
||||
use crate::{
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
{clock::Epoch, pubkey::Pubkey},
|
||||
};
|
||||
use crate::{clock::Epoch, hash::Hash, instruction::InstructionError, pubkey::Pubkey};
|
||||
use std::{
|
||||
cell::{Ref, RefCell, RefMut},
|
||||
cmp, fmt,
|
||||
@ -183,6 +179,10 @@ impl<'a> KeyedAccount<'a> {
|
||||
Ok(self.try_borrow()?.executable)
|
||||
}
|
||||
|
||||
pub fn rent_epoch(&self) -> Result<Epoch, InstructionError> {
|
||||
Ok(self.try_borrow()?.rent_epoch)
|
||||
}
|
||||
|
||||
pub fn try_account_ref(&'a self) -> Result<Ref<Account>, InstructionError> {
|
||||
self.try_borrow()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{account::Account, program_error::ProgramError, pubkey::Pubkey};
|
||||
use crate::{account::Account, clock::Epoch, program_error::ProgramError, pubkey::Pubkey};
|
||||
use std::{
|
||||
cell::{Ref, RefCell, RefMut},
|
||||
cmp, fmt,
|
||||
@ -20,6 +20,10 @@ pub struct AccountInfo<'a> {
|
||||
pub data: Rc<RefCell<&'a mut [u8]>>,
|
||||
/// Program that owns this account
|
||||
pub owner: &'a Pubkey,
|
||||
/// This account's data contains a loaded program (and is now read-only)
|
||||
pub executable: bool,
|
||||
/// The epoch at which this account will next owe rent
|
||||
pub rent_epoch: Epoch,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for AccountInfo<'a> {
|
||||
@ -27,7 +31,7 @@ impl<'a> fmt::Debug for AccountInfo<'a> {
|
||||
let data_len = cmp::min(64, self.data_len());
|
||||
let data_str = if data_len > 0 {
|
||||
format!(
|
||||
" data: {}",
|
||||
" data: {} ...",
|
||||
hex::encode(self.data.borrow()[..data_len].to_vec())
|
||||
)
|
||||
} else {
|
||||
@ -35,10 +39,15 @@ impl<'a> fmt::Debug for AccountInfo<'a> {
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"AccountInfo {{ lamports: {} data.len: {} owner: {} {} }}",
|
||||
"AccountInfo {{ key: {} owner: {} is_signer: {} is_writable: {} executable: {} rent_epoch: {} lamports: {} data.len: {} {} }}",
|
||||
self.key,
|
||||
self.owner,
|
||||
self.is_signer,
|
||||
self.is_writable,
|
||||
self.executable,
|
||||
self.rent_epoch,
|
||||
self.lamports(),
|
||||
self.data_len(),
|
||||
self.owner,
|
||||
data_str,
|
||||
)
|
||||
}
|
||||
@ -57,10 +66,6 @@ impl<'a> AccountInfo<'a> {
|
||||
self.key
|
||||
}
|
||||
|
||||
pub fn is_writable(&self) -> bool {
|
||||
self.is_writable
|
||||
}
|
||||
|
||||
pub fn lamports(&self) -> u64 {
|
||||
**self.lamports.borrow()
|
||||
}
|
||||
@ -116,6 +121,8 @@ impl<'a> AccountInfo<'a> {
|
||||
lamports: &'a mut u64,
|
||||
data: &'a mut [u8],
|
||||
owner: &'a Pubkey,
|
||||
executable: bool,
|
||||
rent_epoch: Epoch,
|
||||
) -> Self {
|
||||
Self {
|
||||
key,
|
||||
@ -124,6 +131,8 @@ impl<'a> AccountInfo<'a> {
|
||||
lamports: Rc::new(RefCell::new(lamports)),
|
||||
data: Rc::new(RefCell::new(data)),
|
||||
owner,
|
||||
executable,
|
||||
rent_epoch,
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,6 +157,8 @@ impl<'a> From<(&'a Pubkey, &'a mut Account)> for AccountInfo<'a> {
|
||||
&mut account.lamports,
|
||||
&mut account.data,
|
||||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -161,6 +172,8 @@ impl<'a> From<(&'a Pubkey, bool, &'a mut Account)> for AccountInfo<'a> {
|
||||
&mut account.lamports,
|
||||
&mut account.data,
|
||||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -174,6 +187,8 @@ impl<'a> From<&'a mut (Pubkey, Account)> for AccountInfo<'a> {
|
||||
&mut account.lamports,
|
||||
&mut account.data,
|
||||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -195,6 +210,8 @@ pub fn create_is_signer_account_infos<'a>(
|
||||
&mut account.lamports,
|
||||
&mut account.data,
|
||||
&account.owner,
|
||||
account.executable,
|
||||
account.rent_epoch,
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
|
@ -67,18 +67,12 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
let dup_info = *(input.add(offset) as *const u8);
|
||||
offset += size_of::<u8>();
|
||||
if dup_info == std::u8::MAX {
|
||||
let is_signer = {
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_signer = *(input.add(offset) as *const u8);
|
||||
is_signer != 0
|
||||
};
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_signer = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
let is_writable = {
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_writable = *(input.add(offset) as *const u8);
|
||||
is_writable != 0
|
||||
};
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let is_writable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
let key: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
@ -100,6 +94,14 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
let owner: &Pubkey = &*(input.add(offset) as *const Pubkey);
|
||||
offset += size_of::<Pubkey>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let executable = *(input.add(offset) as *const u8) != 0;
|
||||
offset += size_of::<u8>();
|
||||
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let rent_epoch = *(input.add(offset) as *const u64);
|
||||
offset += size_of::<u64>();
|
||||
|
||||
accounts.push(AccountInfo {
|
||||
is_signer,
|
||||
is_writable,
|
||||
@ -107,6 +109,8 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
|
||||
lamports,
|
||||
data,
|
||||
owner,
|
||||
executable,
|
||||
rent_epoch,
|
||||
});
|
||||
} else {
|
||||
// Duplicate account, clone the original
|
||||
|
Reference in New Issue
Block a user