瀏覽代碼

lang: clarify owner check (#1404)

Armani Ferrante 3 年之前
父節點
當前提交
a14a829a89
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      lang/syn/src/codegen/accounts/constraints.rs

+ 4 - 4
lang/syn/src/codegen/accounts/constraints.rs

@@ -365,7 +365,7 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     }
 
                     let pa: #ty_decl = #from_account_info;
-                    if !(!#if_needed || #field.as_ref().owner == &anchor_lang::solana_program::system_program::ID) {
+                    if #if_needed {
                         if pa.mint != #mint.key() {
                             return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
                         }
@@ -400,7 +400,7 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                         anchor_spl::associated_token::create(cpi_ctx)?;
                     }
                     let pa: #ty_decl = #from_account_info;
-                    if !(!#if_needed || #field.as_ref().owner == &anchor_lang::solana_program::system_program::ID) {
+                    if #if_needed {
                         if pa.mint != #mint.key() {
                             return Err(anchor_lang::__private::ErrorCode::ConstraintTokenMint.into());
                         }
@@ -453,7 +453,7 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                         anchor_spl::token::initialize_mint(cpi_ctx, #decimals, &#owner.key(), #freeze_authority)?;
                     }
                     let pa: #ty_decl = #from_account_info;
-                    if !(!#if_needed || #field.as_ref().owner == &anchor_lang::solana_program::system_program::ID) {
+                    if #if_needed {
                         if pa.mint_authority != anchor_lang::solana_program::program_option::COption::Some(#owner.key()) {
                             return Err(anchor_lang::__private::ErrorCode::ConstraintMintMintAuthority.into());
                         }
@@ -538,7 +538,7 @@ fn generate_constraint_init_group(f: &Field, c: &ConstraintInitGroup) -> proc_ma
                     let pa: #ty_decl = #from_account_info;
 
                     // Assert the account was created correctly.
-                    if !(!#if_needed || actual_owner == &anchor_lang::solana_program::system_program::ID) {
+                    if #if_needed {
                         if space != actual_field.data_len() {
                             return Err(anchor_lang::__private::ErrorCode::ConstraintSpace.into());
                         }