-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add a constant for ANCHOR_DISCRIMINATOR_SIZE? #3005
Comments
There are plans to support dynamic discriminator length which would make this redundant. This is also one of the main reasons why the new IDL spec have required
Yeah, tbh I think I also think it's possible to completely hide the discriminator logic from the user's POV. |
The macro needs to be rewrite totally. The thing with the approach is to differentiate account struct and included struct in the derive macro. Also derive automatically basic types to be able to call for example |
FYI, you can use MyAccount::DISCRIMINATOR.len() rather than hardcoding or declaring a new constant, which also works with custom discriminators:
Closing as this solves the "magic number" problem, and #3184 is more fitting for future discussions. |
Thanks @acheroncrypto ! I gather |
It also exists in v0.30.1, but it's not exported from use anchor_lang::Discriminator; The import won't be needed in the next version (#3075). |
Heya! @nickfrosty and I were talking and wondering what you think here.
Right now when teaching Anchor we avoid magic numbers by getting people to add
pub const ANCHOR_DISCRIMINATOR: usize = 8;
to almost every new project, and get people to write......when they need to initialize new accounts. I'm wondering what a better solution would be:
ANCHOR_DISCRIMINATOR
const out of the box?INIT_SPACE
that included the discriminator size, egTOTAL_SPACE
or similar?I'm happy to send a PR. Just LMK what you think.
The text was updated successfully, but these errors were encountered: