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 theAccounts
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§
sourcefn try_accounts(
program_id: &Pubkey,
accounts: &mut &'info [AccountInfo<'info>],
ix_data: &[u8],
bumps: &mut B,
reallocs: &mut BTreeSet<Pubkey>
) -> Result<Self>
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.