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

lang: add the InitSpace macro #2346

Merged
merged 19 commits into from Jan 26, 2023
Merged

lang: add the InitSpace macro #2346

merged 19 commits into from Jan 26, 2023

Conversation

Aursen
Copy link
Contributor

@Aursen Aursen commented Dec 27, 2022

Adds a new macro to automatically calculate the space.

#[account]
#[derive(InitSpace)]
pub struct DataAccount {
    pub data: u64,
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(mut)]
    pub payer: Signer<'info>,
    pub system_program: Program<'info, System>,
    #[account(init, payer=payer, space= 8 + DataAccount::INIT_SPACE)]
    pub data: Account<'info, DataAccount>,
}

What remains to be done is:

  • Fix the naming and the other stuffs like this (if needed)
  • Implement the macro directly in the account attribute
  • Add some docs in the proc macro
  • Fix the issue with max_len when the type is Vec<Vec<>>
  • Fix examples

@vercel
Copy link

vercel bot commented Dec 27, 2022

@Aursen is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@Aursen
Copy link
Contributor Author

Aursen commented Dec 28, 2022

@Henry-E What do you want for the name of the macro? InitSpace, MaxSpace, Space or other?

@Henry-E Henry-E marked this pull request as ready for review January 3, 2023 17:29
@Henry-E Henry-E marked this pull request as draft January 3, 2023 17:29
@Henry-E
Copy link
Contributor

Henry-E commented Jan 3, 2023

The InitSpace name looks good for now, I will try to run these tests locally tomorrow and figure out the issue.

Aside from the failing tests, is the PR feature complete now in your opinion?

@Aursen
Copy link
Contributor Author

Aursen commented Jan 3, 2023

Aside from the failing tests, is the PR feature complete now in your opinion?

I think so, I hope I haven't missed anything.

@Aursen Aursen marked this pull request as ready for review January 6, 2023 10:03
@Henry-E
Copy link
Contributor

Henry-E commented Jan 19, 2023

This looks good but we should give it a doc string similar to what the other macros have and maybe reference somewhere in the rest of the rust docs. I will look into adding this maybe.

Edit: Actually no, I see the doc string above the derive Init_space macro. That should surface on the front page of the rust docs.

I think these are outdated since we removed space from being part of the default `account` attribute macro
@Aursen
Copy link
Contributor Author

Aursen commented Jan 25, 2023

@Henry-E I added a test and fixed the issue normally

@Henry-E
Copy link
Contributor

Henry-E commented Jan 26, 2023

@Aursen final thing is just to add a changelog surfacing the new macro!

@Henry-E Henry-E merged commit a0ef4ed into coral-xyz:master Jan 26, 2023
@Henry-E
Copy link
Contributor

Henry-E commented Jan 26, 2023

Thanks for the great work!

@Aursen Aursen deleted the space branch January 26, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants