Explorar el Código

Minor clean up in IDL accounts (#1144)

Kevin Aud hace 3 años
padre
commit
e056cca519
Se han modificado 2 ficheros con 12 adiciones y 10 borrados
  1. 2 4
      cli/src/lib.rs
  2. 10 6
      lang/src/idl.rs

+ 2 - 4
cli/src/lib.rs

@@ -3,7 +3,7 @@ use crate::config::{
     ProgramWorkspace, ScriptsConfig, TestValidator, WithPath, SHUTDOWN_WAIT, STARTUP_WAIT,
 };
 use anchor_client::Cluster;
-use anchor_lang::idl::{IdlAccount, IdlInstruction};
+use anchor_lang::idl::{IdlAccount, IdlInstruction, ERASED_AUTHORITY};
 use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize};
 use anchor_syn::idl::Idl;
 use anyhow::{anyhow, Context, Result};
@@ -1681,9 +1681,7 @@ fn idl_erase_authority(cfg_override: &ConfigOverride, program_id: Pubkey) -> Res
         return Ok(());
     }
 
-    // Program will treat the zero authority as erased.
-    let new_authority = Pubkey::new_from_array([0u8; 32]);
-    idl_set_authority(cfg_override, program_id, None, new_authority)?;
+    idl_set_authority(cfg_override, program_id, None, ERASED_AUTHORITY)?;
 
     Ok(())
 }

+ 10 - 6
lang/src/idl.rs

@@ -29,6 +29,10 @@ use solana_program::pubkey::Pubkey;
 // Sha256(anchor:idl)[..8];
 pub const IDL_IX_TAG: u64 = 0x0a69e9a778bcf440;
 
+// The Pubkey that is stored as the 'authority' on the IdlAccount when the authority
+// is "erased".
+pub const ERASED_AUTHORITY: Pubkey = Pubkey::new_from_array([0u8; 32]);
+
 #[derive(AnchorSerialize, AnchorDeserialize)]
 pub enum IdlInstruction {
     // One time initializer for creating the program's idl account.
@@ -52,8 +56,8 @@ pub struct IdlAccounts<'info> {
     #[account(mut, has_one = authority)]
     #[allow(deprecated)]
     pub idl: ProgramAccount<'info, IdlAccount>,
-    #[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
-    pub authority: AccountInfo<'info>,
+    #[account(constraint = authority.key != &ERASED_AUTHORITY)]
+    pub authority: Signer<'info>,
 }
 
 // Accounts for creating an idl buffer.
@@ -62,8 +66,8 @@ pub struct IdlCreateBuffer<'info> {
     #[account(zero)]
     #[allow(deprecated)]
     pub buffer: ProgramAccount<'info, IdlAccount>,
-    #[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
-    pub authority: AccountInfo<'info>,
+    #[account(constraint = authority.key != &ERASED_AUTHORITY)]
+    pub authority: Signer<'info>,
 }
 
 // Accounts for upgrading the canonical IdlAccount with the buffer.
@@ -77,8 +81,8 @@ pub struct IdlSetBuffer<'info> {
     #[account(mut, has_one = authority)]
     #[allow(deprecated)]
     pub idl: ProgramAccount<'info, IdlAccount>,
-    #[account(signer, constraint = authority.key != &Pubkey::new_from_array([0u8; 32]))]
-    pub authority: AccountInfo<'info>,
+    #[account(constraint = authority.key != &ERASED_AUTHORITY)]
+    pub authority: Signer<'info>,
 }
 
 // The account holding a program's IDL. This is stored on chain so that clients