Struct AccountInfo

Source
#[repr(C)]
pub struct AccountInfo { /* private fields */ }
Expand description

Wrapper struct for an Account.

This struct provides safe access to the data in an Account. It is also used to track borrows of the account data and lamports, given that an account can be “shared” across multiple AccountInfo instances.

Implementations§

Source§

impl AccountInfo

Source

pub fn key(&self) -> &Pubkey

Public key of the account.

Source

pub fn owner(&self) -> &Pubkey

Program that owns this account.

Source

pub fn is_signer(&self) -> bool

Indicates whether the transaction was signed by this account.

Source

pub fn is_writable(&self) -> bool

Indicates whether the account is writable.

Source

pub fn executable(&self) -> bool

Indicates whether this account represents a program.

Program accounts are always read-only.

Source

pub fn data_len(&self) -> usize

Returns the size of the data in the account.

Source

pub fn data_is_empty(&self) -> bool

Indicates whether the account data is empty.

An account is considered empty if the data length is zero.

Source

pub fn assign(&self, new_owner: &Pubkey)

Changes the owner of the account.

Source

pub unsafe fn unchecked_borrow_lamports(&self) -> &u64

Returns a read-only reference to the lamports in the account.

§SAFETY

This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.

Source

pub unsafe fn unchecked_borrow_mut_lamports(&self) -> &mut u64

Returns a mutable reference to the lamports in the account.

§SAFETY

This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.

Source

pub unsafe fn unchecked_borrow_data(&self) -> &[u8]

Returns a read-only reference to the data in the account.

§SAFETY

This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.

Source

pub unsafe fn unchecked_borrow_mut_data(&self) -> &mut [u8]

Returns a mutable reference to the data in the account.

§SAFETY

This does not check or modify the 4-bit refcell. Useful when instruction has verified non-duplicate accounts.

Source

pub fn try_borrow_lamports(&self) -> Result<Ref<'_, u64>, ProgramError>

Tries to get a read-only reference to the lamport field, failing if the field is already mutable borrowed or if 7 borrows already exist.

Source

pub fn try_borrow_mut_lamports(&self) -> Result<RefMut<'_, u64>, ProgramError>

Tries to get a read only reference to the lamport field, failing if the field is already borrowed in any form.

Source

pub fn try_borrow_data(&self) -> Result<Ref<'_, [u8]>, ProgramError>

Tries to get a read only reference to the data field, failing if the field is already mutable borrowed or if 7 borrows already exist.

Source

pub fn try_borrow_mut_data(&self) -> Result<RefMut<'_, [u8]>, ProgramError>

Tries to get a read only reference to the data field, failing if the field is already borrowed in any form.

Source

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.

Trait Implementations§

Source§

impl Clone for AccountInfo

Source§

fn clone(&self) -> AccountInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<&AccountInfo> for CAccountInfo

Source§

fn from(account: &AccountInfo) -> Self

Converts to this type from the input type.
Source§

impl From<&AccountInfo> for CAccountMeta

Source§

fn from(account: &AccountInfo) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for AccountInfo

Source§

fn eq(&self, other: &AccountInfo) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AccountInfo

Source§

impl StructuralPartialEq for AccountInfo

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AbiExample for T

Source§

default fn example() -> T

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V