pub trait Accounts<'info, B>: Sized + ToAccountMetas + ToAccountInfos<'info> {
    // 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, Error>;
}
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§

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

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§

§

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

§

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

Implementors§

source§

impl<'info> Accounts<'info, PermissionSetBumps> for PermissionSet<'info>
where 'info: 'info,

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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