Browse Source

cli: Fix incorrect metadata.address generation (#2485)

Currently when running 'anchor deploy --program-name <name> --program-keypair <specified keypair>' the cli still uses the auto-generated keypair when fetching the program id to add to the IDL metadata at the end. It should instead use the address from the specified keypair.

---------

Co-authored-by: acheron <acheroncrypto@gmail.com>
Ryan De La O 2 years ago
parent
commit
89e94d1d6a
2 changed files with 13 additions and 5 deletions
  1. 1 0
      CHANGELOG.md
  2. 12 5
      cli/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -21,6 +21,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 
 - ts: Narrowed `AccountClient` type to it's appropriate account type ([#2440](https://github.com/coral-xyz/anchor/pull/2440))
 - lang: Fix inability to use identifiers `program_id`, `accounts`, `ix_data`, `remaining_accounts` in instruction arguments ([#2464](https://github.com/coral-xyz/anchor/pull/2464))
+- cli: Fix incorrect `metadata.address` generation in IDL after deploying with a custom keypair ([#2485](https://github.com/coral-xyz/anchor/pull/2485))
 
 ### Breaking
 

+ 12 - 5
cli/src/lib.rs

@@ -3024,9 +3024,17 @@ fn deploy(
 
             println!("Program path: {binary_path}...");
 
-            let program_keypair_filepath = match &program_keypair {
-                Some(program_keypair) => program_keypair.clone(),
-                None => program.keypair_file()?.path().display().to_string(),
+            let (program_keypair_filepath, program_id) = match &program_keypair {
+                Some(path) => (
+                    path.clone(),
+                    solana_sdk::signature::read_keypair_file(path)
+                        .map_err(|_| anyhow!("Unable to read keypair file"))?
+                        .pubkey(),
+                ),
+                None => (
+                    program.keypair_file()?.path().display().to_string(),
+                    program.pubkey()?,
+                ),
             };
 
             // Send deploy transactions.
@@ -3049,11 +3057,10 @@ fn deploy(
                 std::process::exit(exit.status.code().unwrap_or(1));
             }
 
-            let program_pubkey = program.pubkey()?;
             if let Some(mut idl) = program.idl.as_mut() {
                 // Add program address to the IDL.
                 idl.metadata = Some(serde_json::to_value(IdlTestMetadata {
-                    address: program_pubkey.to_string(),
+                    address: program_id.to_string(),
                 })?);
 
                 // Persist it.