use account_compression::{
program::AccountCompression, utils::constants::CPI_AUTHORITY_PDA_SEED, StateMerkleTreeAccount,
};
use anchor_lang::prelude::*;
use crate::epoch::register_epoch::ForesterEpochPda;
#[derive(Accounts)]
pub struct NullifyLeaves<'info> {
#[account(mut)]
pub registered_forester_pda: Option<Account<'info, ForesterEpochPda>>,
pub authority: Signer<'info>,
#[account(seeds = [CPI_AUTHORITY_PDA_SEED], bump)]
pub cpi_authority: AccountInfo<'info>,
pub registered_program_pda: AccountInfo<'info>,
pub account_compression_program: Program<'info, AccountCompression>,
pub log_wrapper: UncheckedAccount<'info>,
#[account(mut)]
pub merkle_tree: AccountLoader<'info, StateMerkleTreeAccount>,
#[account(mut)]
pub nullifier_queue: AccountInfo<'info>,
}
pub fn process_nullify(
ctx: &Context<NullifyLeaves>,
bump: u8,
change_log_indices: Vec<u64>,
leaves_queue_indices: Vec<u16>,
indices: Vec<u64>,
proofs: Vec<Vec<[u8; 32]>>,
) -> Result<()> {
let bump = &[bump];
let seeds = [CPI_AUTHORITY_PDA_SEED, bump];
let signer_seeds = &[&seeds[..]];
let accounts = account_compression::cpi::accounts::NullifyLeaves {
authority: ctx.accounts.cpi_authority.to_account_info(),
registered_program_pda: Some(ctx.accounts.registered_program_pda.to_account_info()),
log_wrapper: ctx.accounts.log_wrapper.to_account_info(),
merkle_tree: ctx.accounts.merkle_tree.to_account_info(),
nullifier_queue: ctx.accounts.nullifier_queue.to_account_info(),
};
let cpi_ctx = CpiContext::new_with_signer(
ctx.accounts.account_compression_program.to_account_info(),
accounts,
signer_seeds,
);
account_compression::cpi::nullify_leaves(
cpi_ctx,
change_log_indices,
leaves_queue_indices,
indices,
proofs,
)
}