0

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(&registrar_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

Jarek Lin
  • 11
  • 2
  • What borsh error did you get?? You really need to provide more detail here. – Frank C. Jun 21 '22 at 09:02
  • @FrankC. sorry for limited info, this is the message I got, `value: TransactionError(InstructionError(0, BorshIoError("Unknown")`, it is unknown so I didn't mention it in the post. the problem here is **depositor account** being marked writable and I have initialized and serialized the data in first instruction, but fail in second instruction when trying to deserialize the data again. – Jarek Lin Jun 21 '22 at 10:48

0 Answers0