account_compression/instructions/
batch_nullify.rs1use anchor_lang::prelude::*;
2use light_batched_merkle_tree::merkle_tree::{
3 BatchedMerkleTreeAccount, InstructionDataBatchNullifyInputs,
4};
5
6use crate::{
7 emit_indexer_event,
8 utils::check_signer_is_registered_or_authority::{
9 check_signer_is_registered_or_authority, GroupAccounts,
10 },
11 RegisteredProgram,
12};
13
14#[derive(Accounts)]
15pub struct BatchNullify<'info> {
16 pub authority: Signer<'info>,
18 pub registered_program_pda: Option<Account<'info, RegisteredProgram>>,
19 pub log_wrapper: UncheckedAccount<'info>,
21 #[account(mut)]
23 pub merkle_tree: AccountInfo<'info>,
24}
25
26impl<'info> GroupAccounts<'info> for BatchNullify<'info> {
27 fn get_authority(&self) -> &Signer<'info> {
28 &self.authority
29 }
30 fn get_registered_program_pda(&self) -> &Option<Account<'info, RegisteredProgram>> {
31 &self.registered_program_pda
32 }
33}
34
35pub fn process_batch_nullify<'a, 'b, 'c: 'info, 'info>(
45 ctx: &'a Context<'a, 'b, 'c, 'info, BatchNullify<'info>>,
46 instruction_data: InstructionDataBatchNullifyInputs,
47) -> Result<()> {
48 let merkle_tree =
50 &mut BatchedMerkleTreeAccount::state_from_account_info(&ctx.accounts.merkle_tree)
51 .map_err(ProgramError::from)?;
52 check_signer_is_registered_or_authority::<BatchNullify, BatchedMerkleTreeAccount>(
54 ctx,
55 merkle_tree,
56 )?;
57 let event = merkle_tree
59 .update_tree_from_input_queue(instruction_data)
60 .map_err(ProgramError::from)?;
61 emit_indexer_event(event.try_to_vec()?, &ctx.accounts.log_wrapper)
63}