Skip to content

Commit

Permalink
cli: Always convert IDLs (#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 21, 2024
1 parent 9671271 commit dac2271
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- avm: Ask whether to install if the version is not installed with the `use` command ([#3230](https://github.com/coral-xyz/anchor/pull/3230)).
- cli: Warn if a manifest has `solana-program` dependency ([#3250](https://github.com/coral-xyz/anchor/pull/3250)).
- cli: Add completions command to generate shell completions via the clap_complete crate ([#3251](https://github.com/coral-xyz/anchor/pull/3251)).
- cli: Always convert IDLs ([#3265](https://github.com/coral-xyz/anchor/pull/3265)).

### Fixes

Expand Down
23 changes: 10 additions & 13 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,9 +1972,8 @@ fn _build_solidity_cwd(
.unwrap_or(PathBuf::from("."))
.join(format!("{}.json", name));

let idl = fs::read_to_string(idl_path)?;

let idl: Idl = serde_json::from_str(&idl)?;
let idl = fs::read(idl_path)?;
let idl = convert_idl(&idl)?;

// TS out path.
let ts_out = match idl_ts_out {
Expand Down Expand Up @@ -2339,8 +2338,8 @@ fn idl_init(
with_workspace(cfg_override, |cfg| {
let keypair = cfg.provider.wallet.to_string();

let bytes = fs::read(idl_filepath)?;
let idl: Idl = serde_json::from_reader(&*bytes)?;
let idl = fs::read(idl_filepath)?;
let idl = convert_idl(&idl)?;

let idl_address = create_idl_account(cfg, &keypair, &program_id, &idl, priority_fee)?;

Expand Down Expand Up @@ -2373,8 +2372,8 @@ fn idl_write_buffer(
with_workspace(cfg_override, |cfg| {
let keypair = cfg.provider.wallet.to_string();

let bytes = fs::read(idl_filepath)?;
let idl: Idl = serde_json::from_reader(&*bytes)?;
let idl = fs::read(idl_filepath)?;
let idl = convert_idl(&idl)?;

let idl_buffer = create_idl_buffer(cfg, &keypair, &program_id, &idl, priority_fee)?;
idl_write(cfg, &program_id, &idl, idl_buffer, priority_fee)?;
Expand Down Expand Up @@ -2939,8 +2938,8 @@ fn account(
})
},
|idl_path| {
let bytes = fs::read(idl_path).expect("Unable to read IDL.");
let idl: Idl = serde_json::from_reader(&*bytes).expect("Invalid IDL format.");
let idl = fs::read(idl_path)?;
let idl = convert_idl(&idl)?;
if idl.metadata.name != program_name {
return Err(anyhow!("IDL does not match program {program_name}."));
}
Expand Down Expand Up @@ -3573,10 +3572,8 @@ fn stream_logs(config: &WithPath<Config>, rpc_url: &str) -> Result<Vec<std::proc
fs::create_dir_all(program_logs_dir)?;
let mut handles = vec![];
for program in config.read_all_programs()? {
let mut file = File::open(format!("target/idl/{}.json", program.lib_name))?;
let mut contents = vec![];
file.read_to_end(&mut contents)?;
let idl: Idl = serde_json::from_slice(&contents)?;
let idl = fs::read(format!("target/idl/{}.json", program.lib_name))?;
let idl = convert_idl(&idl)?;

let log_file = File::create(format!(
"{}/{}.{}.log",
Expand Down

0 comments on commit dac2271

Please sign in to comment.