solana-example-helloworld
solana-example-helloworld copied to clipboard
QUESTION: how to add custom props/fields to the GreetingAccount struct?
First of all, awesome tutorial.
I'm experimenting with the example hello world solana chain app, and I want to add a another field/property to the GreetingAccount struct but I can't seem to get it to work. I'm new to solana/rust so I think I'm just not understanding something about either or both.
Here's what I want to do:
/// Define the type of state stored in accounts
#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct GreetingAccount {
/// number of greetings
pub counter: u64,
/// add this new field
pub counter2: u32,
}
I want to add that new counter2 field so I can figure out how to add new fields and use them in the on-chain program.
I think it has something to do with the BorshDeserialize try_from_slice
method.
The error when I run the the rust tests is:
---- test::test_sanity stdout ----
Account Data len(): [0, 0, 0, 0]
thread 'test::test_sanity' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: InvalidInput, error: "Unexpected length of input" }', src/lib.rs:89:18
So it looks like I need to match the size but the weird thing is the account was created, shouldn't the size being deserialized work out-of-the-box?
I'm studying up on some rust as I'm new to it as we speak.