Unboxed-Software / solana-movie-frontend

Mozilla Public License 2.0
13 stars 80 forks source link

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

Open SergeyDevyatkov opened 7 months ago

SergeyDevyatkov commented 7 months ago

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 commented 7 months ago

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

SergeyDevyatkov commented 7 months ago

@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 commented 2 months ago

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.