#[repr(C)]pub struct AccountInfo<'a> {
pub key: &'a Pubkey,
pub lamports: Rc<RefCell<&'a mut u64>>,
pub data: Rc<RefCell<&'a mut [u8]>>,
pub owner: &'a Pubkey,
pub rent_epoch: u64,
pub is_signer: bool,
pub is_writable: bool,
pub executable: bool,
}
Expand description
Account information
Fields§
§key: &'a Pubkey
Public key of the account
lamports: Rc<RefCell<&'a mut u64>>
The lamports in the account. Modifiable by programs.
data: Rc<RefCell<&'a mut [u8]>>
The data held in this account. Modifiable by programs.
owner: &'a Pubkey
Program that owns this account
rent_epoch: u64
The epoch at which this account will next owe rent
is_signer: bool
Was the transaction signed by this account’s public key?
is_writable: bool
Is the account writable?
executable: bool
This account’s data contains a loaded program (and is now read-only)
Implementations§
Source§impl<'a> AccountInfo<'a>
impl<'a> AccountInfo<'a>
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>
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 u32 integer in the 4 bytes immediately preceding the serialized account key.
pub fn data_len(&self) -> usize
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 try_borrow_lamports(&self) -> Result<Ref<'_, &mut u64>, ProgramError>
pub fn try_borrow_mut_lamports( &self, ) -> Result<RefMut<'_, &'a mut u64>, ProgramError>
pub fn try_borrow_data(&self) -> Result<Ref<'_, &mut [u8]>, ProgramError>
pub fn try_borrow_mut_data( &self, ) -> Result<RefMut<'_, &'a mut [u8]>, ProgramError>
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 assign(&self, new_owner: &Pubkey)
pub fn new( key: &'a Pubkey, is_signer: bool, is_writable: bool, lamports: &'a mut u64, data: &'a mut [u8], owner: &'a Pubkey, executable: bool, rent_epoch: u64, ) -> AccountInfo<'a>
pub fn deserialize_data<T>(&self) -> Result<T, Box<ErrorKind>>where
T: DeserializeOwned,
pub fn serialize_data<T>(&self, state: &T) -> Result<(), Box<ErrorKind>>where
T: Serialize,
Trait Implementations§
Source§impl AccountInfoTrait for AccountInfo<'_>
Implement trait for solana AccountInfo
impl AccountInfoTrait for AccountInfo<'_>
Implement trait for solana AccountInfo
type Pubkey = Pubkey
type DataRef<'b> = Ref<'b, [u8]> where AccountInfo<'_>: 'b
type DataRefMut<'b> = RefMut<'b, [u8]> where AccountInfo<'_>: 'b
Source§fn pubkey(&self) -> <AccountInfo<'_> as AccountInfoTrait>::Pubkey
fn pubkey(&self) -> <AccountInfo<'_> as AccountInfoTrait>::Pubkey
Source§fn pubkey_from_bytes(
bytes: [u8; 32],
) -> <AccountInfo<'_> as AccountInfoTrait>::Pubkey
fn pubkey_from_bytes( bytes: [u8; 32], ) -> <AccountInfo<'_> as AccountInfoTrait>::Pubkey
fn is_writable(&self) -> bool
fn is_signer(&self) -> bool
fn executable(&self) -> bool
fn lamports(&self) -> u64
fn data_len(&self) -> usize
Source§fn try_borrow_data(
&self,
) -> Result<<AccountInfo<'_> as AccountInfoTrait>::DataRef<'_>, AccountError>
fn try_borrow_data( &self, ) -> Result<<AccountInfo<'_> as AccountInfoTrait>::DataRef<'_>, AccountError>
fn try_borrow_mut_data( &self, ) -> Result<<AccountInfo<'_> as AccountInfoTrait>::DataRefMut<'_>, AccountError>
Source§fn is_owned_by(&self, program: &[u8; 32]) -> bool
fn is_owned_by(&self, program: &[u8; 32]) -> bool
Source§fn find_program_address(
seeds: &[&[u8]],
program_id: &[u8; 32],
) -> ([u8; 32], u8)
fn find_program_address( seeds: &[&[u8]], program_id: &[u8; 32], ) -> ([u8; 32], u8)
fn create_program_address( seeds: &[&[u8]], program_id: &[u8; 32], ) -> Result<[u8; 32], AccountError>
Source§fn get_min_rent_balance(size: usize) -> Result<u64, AccountError>
fn get_min_rent_balance(size: usize) -> Result<u64, AccountError>
fn data_is_empty(&self) -> bool
Source§impl<'info, B> Accounts<'info, B> for AccountInfo<'info>
impl<'info, B> Accounts<'info, B> for AccountInfo<'info>
Source§fn try_accounts(
_program_id: &Pubkey,
accounts: &mut &[AccountInfo<'info>],
_ix_data: &[u8],
_bumps: &mut B,
_reallocs: &mut BTreeSet<Pubkey>,
) -> Result<AccountInfo<'info>, Error>
fn try_accounts( _program_id: &Pubkey, accounts: &mut &[AccountInfo<'info>], _ix_data: &[u8], _bumps: &mut B, _reallocs: &mut BTreeSet<Pubkey>, ) -> Result<AccountInfo<'info>, Error>
Mint
account from the SPL token program in a particular
field, then it should be impossible for this method to return Ok
if
any other account type is given–from the SPL token program or elsewhere. Read moreSource§impl<'info> AccountsExit<'info> for AccountInfo<'info>
impl<'info> AccountsExit<'info> for AccountInfo<'info>
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<'info, T> AsRef<AccountInfo<'info>> for Account<'info, T>
impl<'info, T> AsRef<AccountInfo<'info>> for Account<'info, T>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info, T> AsRef<AccountInfo<'info>> for AccountLoader<'info, T>
impl<'info, T> AsRef<AccountInfo<'info>> for AccountLoader<'info, T>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info, T> AsRef<AccountInfo<'info>> for Interface<'info, T>
impl<'info, T> AsRef<AccountInfo<'info>> for Interface<'info, T>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info, T> AsRef<AccountInfo<'info>> for InterfaceAccount<'info, T>
impl<'info, T> AsRef<AccountInfo<'info>> for InterfaceAccount<'info, T>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info, T> AsRef<AccountInfo<'info>> for Program<'info, T>
impl<'info, T> AsRef<AccountInfo<'info>> for Program<'info, T>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info> AsRef<AccountInfo<'info>> for Signer<'info>
impl<'info> AsRef<AccountInfo<'info>> for Signer<'info>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info> AsRef<AccountInfo<'info>> for SystemAccount<'info>
impl<'info> AsRef<AccountInfo<'info>> for SystemAccount<'info>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info, T> AsRef<AccountInfo<'info>> for Sysvar<'info, T>where
T: Sysvar,
impl<'info, T> AsRef<AccountInfo<'info>> for Sysvar<'info, T>where
T: Sysvar,
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
Source§impl<'info> AsRef<AccountInfo<'info>> for UncheckedAccount<'info>
impl<'info> AsRef<AccountInfo<'info>> for UncheckedAccount<'info>
Source§fn as_ref(&self) -> &AccountInfo<'info>
fn as_ref(&self) -> &AccountInfo<'info>
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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AccountInfo<'_>
impl Debug for AccountInfo<'_>
Source§impl<'a, T> From<T> for AccountInfo<'a>where
T: IntoAccountInfo<'a>,
impl<'a, T> From<T> for AccountInfo<'a>where
T: IntoAccountInfo<'a>,
Source§fn from(src: T) -> AccountInfo<'a>
fn from(src: T) -> AccountInfo<'a>
Source§impl<'info> ToAccountInfos<'info> for AccountInfo<'info>
impl<'info> ToAccountInfos<'info> for AccountInfo<'info>
fn to_account_infos(&self) -> Vec<AccountInfo<'info>>
Source§impl ToAccountMetas for AccountInfo<'_>
impl ToAccountMetas for AccountInfo<'_>
Source§fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta>
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta>
is_signer
is given as an optional override for the signer meta field.
This covers the edge case when a program-derived-address needs to relay
a transaction from a client to another program but sign the transaction
before the relay. The client cannot mark the field as a signer, and so
we have to override the is_signer meta field given by the client.Auto Trait Implementations§
impl<'a> Freeze for AccountInfo<'a>
impl<'a> !RefUnwindSafe for AccountInfo<'a>
impl<'a> !Send for AccountInfo<'a>
impl<'a> !Sync for AccountInfo<'a>
impl<'a> Unpin for AccountInfo<'a>
impl<'a> !UnwindSafe for AccountInfo<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<'info, T> Lamports<'info> for Twhere
T: AsRef<AccountInfo<'info>>,
impl<'info, T> Lamports<'info> for Twhere
T: AsRef<AccountInfo<'info>>,
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.