Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why borsh schema for Movie has different order of fields in serialize/deserialize #11

Open
SergeyDevyatkov opened this issue Apr 14, 2024 · 3 comments

Comments

@SergeyDevyatkov
Copy link

Trying to understand, not explained anywhere, why the fields order is different in serialize and deserialize methods in movie model?

...
static borshSchema: borsh.Layout<Movie> = borsh.struct([
    borsh.u8("variant"),
    borsh.str("title"),
    borsh.u8("rating"),
    borsh.str("description"),
  ]);

  static borshAccountSchema: borsh.Layout<Movie> = borsh.struct([
    borsh.u8("initialized"),
    borsh.u8("rating"),
    borsh.str("title"),
    borsh.str("description"),
  ]);
...
@zarex5
Copy link

zarex5 commented Apr 14, 2024

not only the order is different but variant/initialized are two very different properties (albeit of the same type)

  • the 1st schema is an instruction schema, that you send to your program to execute an action
    • with 'variant' being used to choose witch action if you program handles multiple
  • the 2nd is an account schema, that matches the storage account created by your program
    • with 'initialized' being used by your program to check if the account already exists

@SergeyDevyatkov
Copy link
Author

SergeyDevyatkov commented Apr 15, 2024

@zarex5
so it means that when a new portion of data was committed to Solana backend, the Rust-written program itself was responsible for deserializing that data and storing it in this specific order (namely rating, title and description)?

@lalalazero1
Copy link

thanks for this issue.

I was having problems sorting the movies data. but I didn't notice the borsh schema was different.

now I understand more clearly for this process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants