Trait anchor_lang::Accounts

source ·
pub trait Accounts<'info, B>: ToAccountMetas + ToAccountInfos<'info> + Sized {
    // Required method
    fn try_accounts(
        program_id: &Pubkey,
        accounts: &mut &'info [AccountInfo<'info>],
        ix_data: &[u8],
        bumps: &mut B,
        reallocs: &mut BTreeSet<Pubkey>
    ) -> Result<Self>;
}
Expand description

A data structure of validated accounts that can be deserialized from the input to a Solana program. Implementations of this trait should perform any and all requisite constraint checks on accounts to ensure the accounts maintain any invariants required for the program to run securely. In most cases, it’s recommended to use the Accounts derive macro to implement this trait.

Generics:

  • B: the type of the PDA bumps cache struct generated by the Accounts struct. For example,
pub struct Example<'info> {
    #[account(
        init,
        seeds = [...],
        bump,
    )]
    pub pda_1: UncheckedAccount<'info>,
    pub not_pda: UncheckedAccount<'info>,
}

generates:

pub struct ExampleBumps {
    pub pda_1: u8,
}

Required Methods§

source

fn try_accounts( program_id: &Pubkey, accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet<Pubkey> ) -> Result<Self>

Returns the validated accounts struct. What constitutes “valid” is program dependent. However, users of these types should never have to worry about account substitution attacks. For example, if a program expects a 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.

program_id is the currently executing program. accounts is the set of accounts to construct the type from. For every account used, the implementation should mutate the slice, consuming the used entry so that it cannot be used again.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Option<T>

source§

fn try_accounts( program_id: &Pubkey, accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet<Pubkey> ) -> Result<Self>

source§

impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Box<T>

source§

fn try_accounts( program_id: &Pubkey, accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet<Pubkey> ) -> Result<Self>

source§

impl<'info, B, T: Accounts<'info, B>> Accounts<'info, B> for Vec<T>

source§

fn try_accounts( program_id: &Pubkey, accounts: &mut &'info [AccountInfo<'info>], ix_data: &[u8], bumps: &mut B, reallocs: &mut BTreeSet<Pubkey> ) -> Result<Self>

Implementors§

source§

impl<'info> Accounts<'info, AdvanceNonceAccountBumps> for AdvanceNonceAccount<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, AllocateBumps> for Allocate<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, AllocateWithSeedBumps> for AllocateWithSeed<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, AssignBumps> for Assign<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, AssignWithSeedBumps> for AssignWithSeed<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, AuthorizeNonceAccountBumps> for AuthorizeNonceAccount<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, CreateAccountBumps> for CreateAccount<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, CreateAccountWithSeedBumps> for CreateAccountWithSeed<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, CreateNonceAccountBumps> for CreateNonceAccount<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, CreateNonceAccountWithSeedBumps> for CreateNonceAccountWithSeed<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, TransferBumps> for Transfer<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, TransferWithSeedBumps> for TransferWithSeed<'info>
where 'info: 'info,

source§

impl<'info> Accounts<'info, WithdrawNonceAccountBumps> for WithdrawNonceAccount<'info>
where 'info: 'info,

source§

impl<'info, B> Accounts<'info, B> for Signer<'info>

source§

impl<'info, B> Accounts<'info, B> for SystemAccount<'info>

source§

impl<'info, B> Accounts<'info, B> for UncheckedAccount<'info>

source§

impl<'info, B> Accounts<'info, B> for AccountInfo<'info>

source§

impl<'info, B, T> Accounts<'info, B> for Account<'info, T>

source§

impl<'info, B, T: Sysvar> Accounts<'info, B> for Sysvar<'info, T>

source§

impl<'info, B, T: AccountSerialize + AccountDeserialize + CheckOwner + Clone> Accounts<'info, B> for InterfaceAccount<'info, T>

source§

impl<'info, B, T: CheckId> Accounts<'info, B> for Interface<'info, T>

source§

impl<'info, B, T: Id> Accounts<'info, B> for Program<'info, T>

source§

impl<'info, B, T: ZeroCopy + Owner> Accounts<'info, B> for AccountLoader<'info, T>