1

I'm getting this error

     Error: Invalid option endTime
      at OptionLayout.decode (node_modules/@project-serum/borsh/src/index.ts:148:11)
      at Structure.decode (node_modules/buffer-layout/lib/Layout.js:1234:32)
      at Sequence.decode (node_modules/buffer-layout/lib/Layout.js:1090:34)
      at Structure.decode (node_modules/buffer-layout/lib/Layout.js:1234:32)

while trying to use console.log(await program.account.vester.fetch(vesterPda))

The program executes just fine .

here is the account struct

#[derive(Default,AnchorSerialize, AnchorDeserialize,Clone,Debug,Copy)]
pub struct Purchase {
    purch_no: u16,
    purchased_nodes: u16,
}

#[derive(AnchorSerialize, AnchorDeserialize,Clone,Debug,Copy)]
pub struct VestingInfo {
    pk: Pubkey,
    start_time: i64,
    purchs: [Purchase;10],
    end_time: Option<i64>,
    cur_rate : u64,
    metadata: Option<Pubkey>
}
//space : 4 + (32 + 8 + (4+(2+2)*10)+ 8) *15
#[account(zero_copy)]
pub struct Vester {
    schedule : [VestingInfo;15]
}

the end_timefield is throwing error cuase it has Optiontype.

1 Answer 1

2

According to the code, this error is thrown when the given discriminator is neither 0 nor 1, which means that there's some other data there: https://github.com/project-serum/serum-ts/blob/ec11b30fd373336806cd8e2df1873ac887c4e6e2/packages/borsh/src/index.ts#L148

This could mean that your TS code is out of sync with your Rust types. To make sure, you can compare the exact bytes in the account in your on-chain program to the bytes fetched on the client / TypeScript side. Most likely, they're the same, but the TypeScript decoder is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.