#[repr(C)]pub struct AccountInfo<'a> {
pub key: &'a Pubkey,
pub lamports: Rc<RefCell<&'a mut u64>>,
pub utxo: &'a UtxoMeta,
pub data: Rc<RefCell<&'a mut [u8]>>,
pub owner: &'a Pubkey,
pub is_signer: bool,
pub is_writable: bool,
pub is_executable: bool,
}Expand description
Account information that is passed to programs during instruction execution. The account’s data contains the actual account state managed by programs.
Fields§
§key: &'a Pubkey§lamports: Rc<RefCell<&'a mut u64>>The lamports in the account. Modifiable by programs.
utxo: &'a UtxoMeta§data: Rc<RefCell<&'a mut [u8]>>§owner: &'a Pubkey§is_signer: bool§is_writable: bool§is_executable: boolImplementations§
Source§impl<'a> AccountInfo<'a>
impl<'a> AccountInfo<'a>
Sourcepub fn new(
key: &'a Pubkey,
lamports: &'a mut u64,
data: &'a mut [u8],
owner: &'a Pubkey,
utxo: &'a UtxoMeta,
is_signer: bool,
is_writable: bool,
is_executable: bool,
) -> Self
pub fn new( key: &'a Pubkey, lamports: &'a mut u64, data: &'a mut [u8], owner: &'a Pubkey, utxo: &'a UtxoMeta, is_signer: bool, is_writable: bool, is_executable: bool, ) -> Self
Creates a new AccountInfo instance.
§Arguments
key- The account’s public keydata- The account’s mutable dataowner- The program that owns this accountutxo- The UTXO metadata associated with this accountis_signer- Whether this account is a signeris_writable- Whether this account is writableis_executable- Whether this account contains executable code
pub fn try_data_len(&self) -> Result<usize, ProgramError>
pub fn data_is_empty(&self) -> bool
pub fn try_data_is_empty(&self) -> Result<bool, ProgramError>
pub fn signer_key(&self) -> Option<&Pubkey>
pub fn unsigned_key(&self) -> &Pubkey
pub fn lamports(&self) -> u64
pub fn try_lamports(&self) -> Result<u64, ProgramError>
pub fn try_borrow_lamports(&self) -> Result<Ref<'_, &mut u64>, ProgramError>
pub fn try_borrow_mut_lamports( &self, ) -> Result<RefMut<'_, &'a mut u64>, ProgramError>
Sourcepub fn try_borrow_data(&self) -> Result<Ref<'_, &mut [u8]>, ProgramError>
pub fn try_borrow_data(&self) -> Result<Ref<'_, &mut [u8]>, ProgramError>
Immutably borrows the account’s data.
§Returns
Ok(Ref<&mut [u8]>)- A reference to the account’s dataErr(ProgramError)- If the data is already mutably borrowed
Sourcepub fn try_borrow_mut_data(
&self,
) -> Result<RefMut<'_, &'a mut [u8]>, ProgramError>
pub fn try_borrow_mut_data( &self, ) -> Result<RefMut<'_, &'a mut [u8]>, ProgramError>
Mutably borrows the account’s data.
§Returns
Ok(RefMut<&mut [u8]>)- A mutable reference to the account’s dataErr(ProgramError)- If the data is already borrowed
Sourcepub unsafe fn original_data_len(&self) -> usize
pub unsafe fn original_data_len(&self) -> usize
Return the account’s original data length when it was serialized for the current program invocation.
§Safety
This method assumes that the original data length was serialized as a u64 integer in the 1 bytes immediately succeeding is_executable.
Sourcepub fn realloc(
&self,
new_len: usize,
zero_init: bool,
) -> Result<(), ProgramError>
pub fn realloc( &self, new_len: usize, zero_init: bool, ) -> Result<(), ProgramError>
Realloc the account’s data and optionally zero-initialize the new memory.
Note: Account data can be increased within a single call by up to
solana_program::entrypoint::MAX_PERMITTED_DATA_INCREASE bytes.
Note: Memory used to grow is already zero-initialized upon program
entrypoint and re-zeroing it wastes compute units. If within the same
call a program reallocs from larger to smaller and back to larger again
the new space could contain stale data. Pass true for zero_init in
this case, otherwise compute units will be wasted re-zero-initializing.
§Safety
This method makes assumptions about the layout and location of memory
referenced by AccountInfo fields. It should only be called for
instances of AccountInfo that were created by the runtime and received
in the process_instruction entrypoint of a program.
pub fn get_utxo(&self) -> &UtxoMeta
Trait Implementations§
Source§impl<'a> AsRef<AccountInfo<'a>> for AccountInfo<'a>
impl<'a> AsRef<AccountInfo<'a>> for AccountInfo<'a>
Source§fn as_ref(&self) -> &AccountInfo<'a>
fn as_ref(&self) -> &AccountInfo<'a>
Source§impl<'a> Clone for AccountInfo<'a>
impl<'a> Clone for AccountInfo<'a>
Source§fn clone(&self) -> AccountInfo<'a>
fn clone(&self) -> AccountInfo<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more