-
Notifications
You must be signed in to change notification settings - Fork 203
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
Program security - Updated type cosplay lesson #411
base: main
Are you sure you want to change the base?
Program security - Updated type cosplay lesson #411
Conversation
… into fix-program-security-type-cosplay
- Use discriminators to distinguish between different account types | ||
- To implement a discriminator in Rust, include a field in the account struct to | ||
represent the account type | ||
- **Use discriminators** to distinguish between different account types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add:
- Discriminators are data written to account that determines the type of data stored inside
or something similar to make sure people know what they are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes adding it. Also, should I add a section to explain the concept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a bit of explanation in the same line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good start, but I have a few large-ish questions to resolve before getting it merged.
To solve this, you can add a discriminant field for each account type and set | ||
the discriminant when initializing an account. | ||
To resolve this, add a discriminant field for each account type and set the | ||
discriminant when initializing an account. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of complaint with the old lesson, but is a discriminant
the same thing as a discriminator? This is confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's a bit confusing to me as well initially but discriminant manages enum variants internally in the Rust and discriminator is an explicit identifier used to distinguish different account types within Solana programs.
@mikemaccana Answered the questions and resolved the comments. Let me know if there is any additional feedback. |
Problem
Summary of Changes
Fixes #
Unboxed PRs -
Starter - Unboxed-Software/solana-type-cosplay#1
Solution - Unboxed-Software/solana-type-cosplay#2