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, ts, examples: Remove associated keyword #612

Merged
merged 9 commits into from
Aug 15, 2021
Merged

Conversation

armaniferrante
Copy link
Member

Closes #491.

@armaniferrante armaniferrante marked this pull request as ready for review August 15, 2021 23:32
@armaniferrante armaniferrante merged commit 6e55078 into master Aug 15, 2021
@armaniferrante armaniferrante deleted the armani/remove branch August 15, 2021 23:36
@michaelhly
Copy link
Contributor

@armaniferrante, was it not possible to just deprecate the associated attribute instead of removing these outright?

@armaniferrante
Copy link
Member Author

armaniferrante commented Aug 20, 2021

@armaniferrante, was it not possible to just deprecate the associated attribute instead of removing these outright?

On the next release, you can update your code from

#[derive(Accounts)]
pub struct Ix {
  #[account(associated = <target>, with = <target>)]
}

#[associated]
pub struct MyAccount {...}

To the more explicit

#[derive(Accounts)]
pub struct Ix {
  #[account(
     seeds = [b"anchor", <target>.key().as_ref(), <with-target>.key().as_ref()], 
     bump,
  )] 
}

#[account]
#[derive(Default)]
pub struct MyAccount {
 ...
  __nonce: u8,
}

Without breaking changes. If this doesn't work for whatever reason please let me know.

Note that bump will "find" the bump seed for the account and use it. Alternatively, it can be explicitly provided via bump = <u8-expression>, which is recommended to save compute, since Pubkey::create_program_address is cheaper than Pubkey::find_program_address (the syntax for this is subject to change prior to the next release based on feedback).

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

Successfully merging this pull request may close these issues.

lang: Consider removing associated keyword
2 participants