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