use {
bytemuck::Pod,
solana_program::{instruction::Instruction, msg, program_error::ProgramError, pubkey::Pubkey},
solana_zk_token_sdk::{
instruction::ZkProofData, zk_token_proof_instruction::ProofInstruction,
zk_token_proof_program,
},
std::num::NonZeroI8,
};
pub fn decode_proof_instruction_context<T: Pod + ZkProofData<U>, U: Pod>(
expected: ProofInstruction,
instruction: &Instruction,
) -> Result<&U, ProgramError> {
if instruction.program_id != zk_token_proof_program::id()
|| ProofInstruction::instruction_type(&instruction.data) != Some(expected)
{
msg!("Unexpected proof instruction");
return Err(ProgramError::InvalidInstructionData);
}
ProofInstruction::proof_data::<T, U>(&instruction.data)
.map(ZkProofData::context_data)
.ok_or(ProgramError::InvalidInstructionData)
}
#[derive(Clone, Copy)]
pub enum ProofLocation<'a, T> {
InstructionOffset(NonZeroI8, &'a T),
ContextStateAccount(&'a Pubkey),
}
#[derive(Clone, Copy)]
pub struct SplitContextStateAccountsConfig {
pub no_op_on_uninitialized_split_context_state: bool,
pub close_split_context_state_on_execution: bool,
}