Program
Include instractions crate, and add the instruction branching after the account-owner-check:
pub mod instructions;
use crate::instructions::Instruction;
// ...
let mut state = State::try_from_slice(&account.data.borrow())?;
let ix = Instruction::unpack(instruction_data)?;
match ix {
Instruction::Increment => state.counter += 1,
Instruction::Decrement => state.counter -= 1,
Instruction::SetValue(val) => state.counter = val
}
state.serialize(&mut &mut account.data.borrow_mut()[..])?;
Don't forget to rename the variable name of instruction data
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8], // _instruction_data -> instruction_data
) -> entrypoint::ProgramResult {
// ...
}