Skip to content

Commit

Permalink
cli: Fix incorrect metadata.address generation (coral-xyz#2485)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rdelao and acheroncrypto authored May 13, 2023
1 parent 714d524 commit 89e94d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 12 additions & 5 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 89e94d1

Please sign in to comment.