Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for anchor idl fetch to work outside anchor workspace #1509

Merged
merged 5 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ incremented for features.
* cli: Add `anchor clean` command that's the same as `cargo clean` but preserves keypairs inside `target/deploy` ([#1470](https://github.com/project-serum/anchor/issues/1470)).
* lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)).
* spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)).
* cli: Add support for `anchor idl fetch` to work outside anchor workspace ([#1509](https://github.com/project-serum/anchor/pull/1509)).
* ts: Add provider parameter to `Spl.token` factory method ([#1597](https://github.com/project-serum/anchor/pull/1597)).

### Fixes
Expand Down
13 changes: 4 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ serde = { version = "1.0.122", features = ["derive"] }
solana-sdk = "1.8.5"
solana-program = "1.8.5"
solana-client = "1.8.5"
solana-cli-config = "1.8.5"
serum-common = { git = "https://github.com/project-serum/serum-dex", features = ["client"] }
dirs = "3.0"
heck = "0.3.1"
Expand Down
12 changes: 12 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use anyhow::{anyhow, Error, Result};
use clap::{ArgEnum, Parser};
use heck::SnakeCase;
use serde::{Deserialize, Serialize};
use solana_cli_config::{Config as SolanaConfig, CONFIG_FILE};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, Signer};
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::fs::{self, File};
use std::io;
use std::io::prelude::*;
use std::ops::Deref;
use std::path::Path;
Expand Down Expand Up @@ -445,6 +447,16 @@ impl FromStr for Config {
}
}

pub fn get_solana_cfg_url() -> Result<String, io::Error> {
let config_file = CONFIG_FILE.as_ref().ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
"Default Solana config was not found",
)
})?;
SolanaConfig::load(config_file).map(|config| config.json_rpc_url)
}

NBNARADHYA marked this conversation as resolved.
Show resolved Hide resolved
fn ser_programs(
programs: &BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>,
) -> BTreeMap<String, BTreeMap<String, serde_json::Value>> {
Expand Down
17 changes: 15 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,8 +1400,21 @@ pub enum BinVerificationState {

// Fetches an IDL for the given program_id.
fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
let cfg = Config::discover(cfg_override)?.expect("Inside a workspace");
let url = cluster_url(&cfg);
let url = match Config::discover(cfg_override)? {
Some(cfg) => cluster_url(&cfg),
None => {
// If the command is not run inside a workspace,
// cluster_url will be used from default solana config
// provider.cluster option can be used to override this

if let Some(cluster) = cfg_override.cluster.clone() {
cluster.url().to_string()
} else {
config::get_solana_cfg_url()?
}
}
};

let client = RpcClient::new(url);

let mut account = client
Expand Down