Add CloseAccountData proof program plumbing
This commit is contained in:
parent
00fa5a93b8
commit
8b15d7bc28
|
@ -1,6 +1,7 @@
|
|||
#![forbid(unsafe_code)]
|
||||
|
||||
use {
|
||||
bytemuck::Pod,
|
||||
solana_sdk::{
|
||||
ic_msg, instruction::InstructionError, process_instruction::InvokeContext, pubkey::Pubkey,
|
||||
},
|
||||
|
@ -8,6 +9,21 @@ use {
|
|||
std::result::Result,
|
||||
};
|
||||
|
||||
fn verify<T: Pod + Verifiable>(
|
||||
input: &[u8],
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let proof = ProofInstruction::decode_data::<T>(input).ok_or_else(|| {
|
||||
ic_msg!(invoke_context, "invalid proof data");
|
||||
InstructionError::InvalidInstructionData
|
||||
})?;
|
||||
|
||||
proof.verify().map_err(|err| {
|
||||
ic_msg!(invoke_context, "proof verification failed: {:?}", err);
|
||||
InstructionError::InvalidInstructionData
|
||||
})
|
||||
}
|
||||
|
||||
pub fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
input: &[u8],
|
||||
|
@ -16,15 +32,13 @@ pub fn process_instruction(
|
|||
match ProofInstruction::decode_type(program_id, input)
|
||||
.ok_or(InstructionError::InvalidInstructionData)?
|
||||
{
|
||||
ProofInstruction::VerifyUpdateAccountPkData => {
|
||||
ic_msg!(invoke_context, "VerifyUpdateAccountPkData");
|
||||
let proof = ProofInstruction::decode_data::<UpdateAccountPkData>(input)
|
||||
.ok_or(InstructionError::InvalidInstructionData)?;
|
||||
|
||||
proof.verify().map_err(|err| {
|
||||
ic_msg!(invoke_context, "proof verification failed: {:?}", err);
|
||||
InstructionError::InvalidInstructionData
|
||||
})
|
||||
ProofInstruction::VerifyUpdateAccountPk => {
|
||||
ic_msg!(invoke_context, "VerifyUpdateAccountPk");
|
||||
verify::<UpdateAccountPkData>(input, invoke_context)
|
||||
}
|
||||
ProofInstruction::VerifyCloseAccount => {
|
||||
ic_msg!(invoke_context, "VerifyCloseAccount");
|
||||
verify::<CloseAccountData>(input, invoke_context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue