diff --git a/CHANGELOG.md b/CHANGELOG.md index 6285baf532..729deb0f8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ incremented for features. ## [Unreleased] +### Breaking Changes + +* lang: `#[account(owner = )]` now requires a `Pubkey` instead of an account ([#691](https://github.com/project-serum/anchor/pull/691)). + ## [0.15.0] - 2021-09-07 ### Features diff --git a/examples/tutorial/basic-3/programs/puppet-master/src/lib.rs b/examples/tutorial/basic-3/programs/puppet-master/src/lib.rs index d066463d2d..f3d80b3e0c 100644 --- a/examples/tutorial/basic-3/programs/puppet-master/src/lib.rs +++ b/examples/tutorial/basic-3/programs/puppet-master/src/lib.rs @@ -1,6 +1,6 @@ // #region core use anchor_lang::prelude::*; -use puppet::{Puppet, SetData}; +use puppet::{self, Puppet, SetData}; declare_id!("HmbTLCmaGvZhKnn1Zfa1JVnp7vkMV4DYVxPLWBVoN65L"); @@ -19,8 +19,9 @@ mod puppet_master { #[derive(Accounts)] pub struct PullStrings<'info> { - #[account(mut, owner = puppet_program)] + #[account(mut)] pub puppet: Account<'info, Puppet>, + #[account(address = puppet::ID)] pub puppet_program: AccountInfo<'info>, } // #endregion core diff --git a/lang/syn/src/codegen/accounts/constraints.rs b/lang/syn/src/codegen/accounts/constraints.rs index 1f78be9087..070f7fed4e 100644 --- a/lang/syn/src/codegen/accounts/constraints.rs +++ b/lang/syn/src/codegen/accounts/constraints.rs @@ -244,9 +244,9 @@ pub fn generate_constraint_raw(c: &ConstraintRaw) -> proc_macro2::TokenStream { pub fn generate_constraint_owner(f: &Field, c: &ConstraintOwner) -> proc_macro2::TokenStream { let ident = &f.ident; - let owner_target = c.owner_target.clone(); + let owner_address = &c.owner_address; quote! { - if #ident.to_account_info().owner != #owner_target.to_account_info().key { + if #ident.to_account_info().owner != &#owner_address { return Err(anchor_lang::__private::ErrorCode::ConstraintOwner.into()); } } diff --git a/lang/syn/src/lib.rs b/lang/syn/src/lib.rs index 69143dde20..c6894bb460 100644 --- a/lang/syn/src/lib.rs +++ b/lang/syn/src/lib.rs @@ -561,7 +561,7 @@ pub struct ConstraintRaw { #[derive(Debug, Clone)] pub struct ConstraintOwner { - pub owner_target: Expr, + pub owner_address: Expr, } #[derive(Debug, Clone)] diff --git a/lang/syn/src/parser/accounts/constraints.rs b/lang/syn/src/parser/accounts/constraints.rs index fde4bf25af..f4cbc023ce 100644 --- a/lang/syn/src/parser/accounts/constraints.rs +++ b/lang/syn/src/parser/accounts/constraints.rs @@ -156,7 +156,7 @@ pub fn parse_token(stream: ParseStream) -> ParseResult { "owner" => ConstraintToken::Owner(Context::new( span, ConstraintOwner { - owner_target: stream.parse()?, + owner_address: stream.parse()?, }, )), "rent_exempt" => ConstraintToken::RentExempt(Context::new( @@ -447,14 +447,6 @@ impl<'ty> ConstraintGroupBuilder<'ty> { }; } - let (owner, pda_owner) = { - if seeds.is_some() { - (None, owner.map(|o| o.owner_target.clone())) - } else { - (owner, None) - } - }; - let seeds = seeds.map(|c| ConstraintSeedsGroup { is_init: init.is_some(), seeds: c.seeds.clone(), @@ -491,7 +483,7 @@ impl<'ty> ConstraintGroupBuilder<'ty> { } } else { InitKind::Program { - owner: pda_owner.clone(), + owner: owner.as_ref().map(|o| o.owner_address.clone()), } }, })).transpose()?, diff --git a/tests/cfo/programs/cfo/src/lib.rs b/tests/cfo/programs/cfo/src/lib.rs index f4f185c64c..c596cf16f3 100644 --- a/tests/cfo/programs/cfo/src/lib.rs +++ b/tests/cfo/programs/cfo/src/lib.rs @@ -364,7 +364,7 @@ pub struct CreateOfficerToken<'info> { payer = payer, )] token: Account<'info, TokenAccount>, - #[account(owner = token_program)] + #[account(owner = spl_token::ID)] mint: AccountInfo<'info>, #[account(mut, signer)] payer: AccountInfo<'info>, @@ -392,7 +392,7 @@ pub struct SweepFees<'info> { officer: Account<'info, Officer>, #[account( mut, - owner = dex.token_program, + owner = spl_token::ID, seeds = [officer.key().as_ref(), mint.key().as_ref()], bump, )] @@ -423,12 +423,12 @@ pub struct SwapToUsdc<'info> { officer: Account<'info, Officer>, market: DexMarketAccounts<'info>, #[account( - owner = token_program, + owner = spl_token::ID, constraint = &officer.treasury != from_vault.key, constraint = &officer.stake != from_vault.key, )] from_vault: AccountInfo<'info>, - #[account(owner = token_program)] + #[account(owner = spl_token::ID)] quote_vault: AccountInfo<'info>, #[account(seeds = [officer.key().as_ref(), mint::USDC.as_ref()], bump)] usdc_vault: AccountInfo<'info>, @@ -452,12 +452,12 @@ pub struct SwapToSrm<'info> { officer: Account<'info, Officer>, market: DexMarketAccounts<'info>, #[account( - owner = token_program, + owner = spl_token::ID, constraint = &officer.treasury != from_vault.key, constraint = &officer.stake != from_vault.key, )] from_vault: AccountInfo<'info>, - #[account(owner = token_program)] + #[account(owner = spl_token::ID)] quote_vault: AccountInfo<'info>, #[account( seeds = [officer.key().as_ref(), mint::SRM.as_ref()], @@ -518,10 +518,7 @@ pub struct Distribute<'info> { officer: Account<'info, Officer>, treasury: AccountInfo<'info>, stake: AccountInfo<'info>, - #[account( - owner = token_program, - constraint = srm_vault.mint == mint::SRM, - )] + #[account(constraint = srm_vault.mint == mint::SRM)] srm_vault: Account<'info, TokenAccount>, #[account(address = mint::SRM)] mint: AccountInfo<'info>, @@ -551,7 +548,7 @@ pub struct DropStakeReward<'info> { mint: AccountInfo<'info>, srm: DropStakeRewardPool<'info>, msrm: DropStakeRewardPool<'info>, - #[account(owner = registry_program)] + #[account(owner = *registry_program.key)] msrm_registrar: Box>, #[account(address = token::ID)] token_program: AccountInfo<'info>, diff --git a/tests/misc/programs/misc/src/context.rs b/tests/misc/programs/misc/src/context.rs index 49f7e5740e..d228bdb63e 100644 --- a/tests/misc/programs/misc/src/context.rs +++ b/tests/misc/programs/misc/src/context.rs @@ -96,7 +96,7 @@ pub struct Initialize<'info> { #[derive(Accounts)] pub struct TestOwner<'info> { - #[account(owner = misc)] + #[account(owner = *misc.key)] pub data: AccountInfo<'info>, pub misc: AccountInfo<'info>, }