pub fn next_account_info<'a, 'b, I>(
    iter: &mut I
) -> Result<<I as Iterator>::Item, ProgramError>
where I: Iterator<Item = &'a AccountInfo<'b>>,
Expand description

Convenience function for accessing the next item in an AccountInfo iterator.

This is simply a wrapper around Iterator::next that returns a ProgramError instead of an option.

§Errors

Returns ProgramError::NotEnoughAccountKeys if there are no more items in the iterator.

§Examples

use solana_program::{
   account_info::{AccountInfo, next_account_info},
   entrypoint::ProgramResult,
   pubkey::Pubkey,
};

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    let accounts_iter = &mut accounts.iter();
    let signer = next_account_info(accounts_iter)?;
    let payer = next_account_info(accounts_iter)?;

    // do stuff ...

    Ok(())
}