(
program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
)
| 43 | |
| 44 | #[allow(clippy::clone_double_ref)] |
| 45 | pub fn process_instruction( |
| 46 | program_id: &Pubkey, |
| 47 | accounts: &[AccountInfo], |
| 48 | _instruction_data: &[u8], |
| 49 | ) -> ProgramResult { |
| 50 | let accounts_mut = accounts.clone(); |
| 51 | let account = &mut accounts_mut.iter(); |
| 52 | // 0. `[]` signer |
| 53 | let signer_account = next_account_info(account)?; |
| 54 | if !signer_account.is_signer { |
| 55 | msg!("signer account needs to be passed in first place"); |
| 56 | return Err(ProgramError::IllegalOwner); |
| 57 | } |
| 58 | // Initialize new merkle tree account. |
| 59 | if _instruction_data.len() >= 9 && _instruction_data[8] == 240 { |
| 60 | let merkle_tree_storage_acc = next_account_info(account)?; |
| 61 | // Check whether signer is merkle_tree_init_authority. |
| 62 | if *signer_account.key != Pubkey::new(&MERKLE_TREE_INIT_AUTHORITY) { |
| 63 | msg!("Signer is not merkle tree init authority."); |
| 64 | return Err(ProgramError::IllegalOwner); |
| 65 | } |
| 66 | let rent_sysvar_info = next_account_info(account)?; |
| 67 | let rent = &Rent::from_account_info(rent_sysvar_info)?; |
| 68 | if !rent.is_exempt( |
| 69 | **merkle_tree_storage_acc.lamports.borrow(), |
| 70 | merkle_tree_storage_acc.data.borrow().len(), |
| 71 | ) { |
| 72 | msg!("Account is not rent exempt."); |
| 73 | return Err(ProgramError::AccountNotRentExempt); |
| 74 | } |
| 75 | let mut merkle_tree_processor = |
| 76 | MerkleTreeProcessor::new(None, Some(merkle_tree_storage_acc), *program_id)?; |
| 77 | merkle_tree_processor |
| 78 | .initialize_new_merkle_tree_from_bytes(&config::INIT_BYTES_MERKLE_TREE_18[..]) |
| 79 | } |
| 80 | // Initialize new onchain user account. |
| 81 | else if _instruction_data.len() >= 9 && _instruction_data[8] == 100 { |
| 82 | let user_account = next_account_info(account)?; |
| 83 | let rent_sysvar_info = next_account_info(account)?; |
| 84 | let rent = &Rent::from_account_info(rent_sysvar_info)?; |
| 85 | initialize_user_account(user_account, *signer_account.key, *rent) |
| 86 | } |
| 87 | // Transact with shielded pool. |
| 88 | // This instruction has to be called 1502 times to perform all computation. |
| 89 | // There are different instructions which have to be executed in a specific order. |
| 90 | // The instruction order is hardcoded in IX_ORDER. |
| 91 | // After every instruction the program increments an internal counter (current_instruction_index). |
| 92 | // The current_instruction_index is stored in a temporary storage pda on-chain. |
| 93 | else { |
| 94 | // 1. `[writable]` tmp_storage_pda stores intermediate state. |
| 95 | let tmp_storage_pda = next_account_info(account)?; |
| 96 | |
| 97 | // Unpack the current_instruction_index. |
| 98 | let tmp_storage_pda_data = InstructionIndex::unpack(&tmp_storage_pda.data.borrow()); |
| 99 | msg!("tmp_storage_pda_data: {:?}", tmp_storage_pda_data); |
| 100 | // Check whether tmp_storage_pda is initialized, if not try create and initialize. |
| 101 | // First instruction will always create and initialize a new tmp_storage_pda. |
| 102 | match tmp_storage_pda_data { |
nothing calls this directly
no test coverage detected