Skip to content

lang: add the InitSpace macro#2346

Merged
Henry-E merged 19 commits into
otter-sec:masterfrom
Aursen:space
Jan 26, 2023
Merged

lang: add the InitSpace macro#2346
Henry-E merged 19 commits into
otter-sec:masterfrom
Aursen:space

Conversation

@Aursen

@Aursen Aursen commented Dec 27, 2022

Copy link
Copy Markdown
Contributor

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

vercel Bot commented Dec 27, 2022

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

Comment thread lang/derive/space/src/lib.rs Outdated
Comment thread lang/derive/space/src/lib.rs
@Aursen

Aursen commented Dec 28, 2022

Copy link
Copy Markdown
Contributor Author

@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

Henry-E commented Jan 3, 2023

Copy link
Copy Markdown

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

Aursen commented Jan 3, 2023

Copy link
Copy Markdown
Contributor Author

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

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

Comment thread lang/attribute/account/src/lib.rs Outdated
Comment thread tests/multisig/programs/multisig/src/lib.rs
@Aursen Aursen marked this pull request as ready for review January 6, 2023 10:03
@Henry-E

Henry-E commented Jan 19, 2023

Copy link
Copy Markdown

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
Comment thread lang/derive/space/src/lib.rs
@Aursen

Aursen commented Jan 25, 2023

Copy link
Copy Markdown
Contributor Author

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

@Henry-E

Henry-E commented Jan 26, 2023

Copy link
Copy Markdown

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

@Henry-E Henry-E merged commit a0ef4ed into otter-sec:master Jan 26, 2023
@Henry-E

Henry-E commented Jan 26, 2023

Copy link
Copy Markdown

Thanks for the great work!

@Aursen Aursen deleted the space branch January 26, 2023 14:01
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
@jamie-osec jamie-osec added this to the Pre-1.0 milestone Jun 24, 2026
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.

3 participants