pub trait Accounts<'info>: ToAccountMetas + ToAccountInfos<'info> + Sized {
    fn try_accounts(
        program_id: &Pubkey,
        accounts: &mut &[AccountInfo<'info>],
        ix_data: &[u8],
        bumps: &mut BTreeMap<String, u8>,
        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.

Required Methods

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.

Implementations on Foreign Types

Implementors