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

[idea] more compact way to indicate an account stores a particular struct? #3184

Open
mikemaccana opened this issue Aug 20, 2024 · 1 comment

Comments

@mikemaccana
Copy link
Contributor

mikemaccana commented Aug 20, 2024

So right now we tell Anchor that space is derived from the (currently constant) discriminator size plus INIT_SPACE for the struct:

#[account(
    ...
    space = ANCHOR_DISCRIMINATOR + Offer::INIT_SPACE,
    ...
)]
pub offer: Account<'info, Offer>,

And as you mentioned in #3005 we could have just SPACE (including whatever size the discriminator is):

#[account(
    ...
    space = Offer::SPACE,
    ...
)]
pub offer: Account<'info, Offer>,

Is there any reason we couldn't do something like:

#[account(
    ...
    stores = Offer,
    ...
)]
pub offer: Account<'info, Offer>,

or even:

#[account(
    ...
)]
pub offer: Account<'info, Offer>,

With space being determined by the generic provided to Account<>?

The programmer's intention is to store a struct of a particular type. The fact that the account needs to match the size of the struct is really a dependency of that goal. Also it's easier to reason about!

@acheroncrypto
Copy link
Collaborator

Yeah, I've been working on something related that also requires automatic space calculation, so I'm thinking about making the space constraint optional again (it was like that a long time ago).

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

No branches or pull requests

2 participants