I know the most common and recommended way is separate "initialize" and "update" instructions and pack them inside the single transaction in the client-side. However, I am wondering is there any way to achieve the kind of logic on the program.
Here's the code, I got the 2 function with exactly same amount of required accounts and function argument, only difference is their logic for initializing and updating the state. I thought I will receive a run time error, but I got deserialization failure instead.
Can anyone gives me an explanation for getting BorshIoError and any further solutions ?
instruction (1): process initialize_deposit
fn process(...)->ProgramResult{
{
Logic...
}
//calling update_deposit ix
crate::processor::update_deposit::process(program_id, accounts, update_idx, amount)?;
Ok(())
}
instruction (2): process update_deposit
fn process(program_id, accounts, update_idx, amount)->ProgramResult{
...
let registrar: Registrar = Registrar::try_from_slice(®istrar_info.try_borrow_data()?)?;
// this failed to serialize the data
let mut depositor: Depositor = Voter::try_from_slice(&depositor_info.try_borrow_mut_data()?)?;
}
Initial idea in Anchor framework source code