Replies: 1 comment 1 reply
-
There is a tricky part which is that the state cache should encompass all keys which implement #[public]
fn total_supply(context: Context<state_keys::TotalSupply>) {} For instance, we would not be able to fetch the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
State scheme
Why do we need it ?
We need typed keys. They are currently typed at runtime and we would like to avoid this, since it could create foot guns.
For instance, to get a value from a key we write
@richardpringle proposed something very similar to diesel:
What the diesel macro (diesel::table!) does is that it creates modules, a struct, and helpers. For instance, with this macro
You can check the docs produced by running
cargo doc --open
.Here, the dsl module that is generated would be of interest for us.
The diesel docs explains it very well for us what is this macro doing: https://diesel.rs/guides/schema-in-depth.html
Proposition
Say we have this macro:
This would create a module named state_keys (the old state_keys macro should be deprecated with this so there won’t be collisions. If we still need it we should find another name to avoid collisions.
This module would have each type which would really just be unit and tuple structs such as:
They should all implement a trait called Schema (or something else) which would expose a type which would be the return type. This type should be BorshSerialize and BorshDeserialize. End result:
Now, the get and store methods of the state struct inside of the program should accept a key which implements the trait Schema. This way, we could be able to return Schema::SchemaType
Beta Was this translation helpful? Give feedback.
All reactions