Skip to content

lang, ts, examples: Remove associated keyword#612

Merged
armaniferrante merged 9 commits intomasterfrom
armani/remove
Aug 15, 2021
Merged

lang, ts, examples: Remove associated keyword#612
armaniferrante merged 9 commits intomasterfrom
armani/remove

Conversation

@armaniferrante
Copy link
Contributor

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
Contributor 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