Add support for `anchor idl fetch` to work outside anchor workspace (#1509)
This commit is contained in:
parent
54c07be511
commit
00488b512c
|
@ -17,6 +17,7 @@ incremented for features.
|
||||||
* lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)).
|
* lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)).
|
||||||
* lang: Replace `std::io::Cursor` with a custom `Write` impl that uses the Solana mem syscalls ([#1589](https://github.com/project-serum/anchor/pull/1589)).
|
* lang: Replace `std::io::Cursor` with a custom `Write` impl that uses the Solana mem syscalls ([#1589](https://github.com/project-serum/anchor/pull/1589)).
|
||||||
* spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)).
|
* 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)).
|
* ts: Add provider parameter to `Spl.token` factory method ([#1597](https://github.com/project-serum/anchor/pull/1597)).
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
|
@ -165,6 +165,7 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serum-common",
|
"serum-common",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
|
"solana-cli-config",
|
||||||
"solana-client",
|
"solana-client",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
|
@ -1089,12 +1090,6 @@ dependencies = [
|
||||||
"syn 0.15.44",
|
"syn 0.15.44",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dtoa"
|
|
||||||
version = "0.4.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ed25519"
|
name = "ed25519"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -2844,12 +2839,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_yaml"
|
name = "serde_yaml"
|
||||||
version = "0.8.21"
|
version = "0.8.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
|
checksum = "a4a521f2940385c165a24ee286aa8599633d162077a54bdcae2a6fd5a7bfa7a0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dtoa",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
|
"ryu",
|
||||||
"serde",
|
"serde",
|
||||||
"yaml-rust",
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
|
@ -27,6 +27,7 @@ serde = { version = "1.0.122", features = ["derive"] }
|
||||||
solana-sdk = "1.8.5"
|
solana-sdk = "1.8.5"
|
||||||
solana-program = "1.8.5"
|
solana-program = "1.8.5"
|
||||||
solana-client = "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"] }
|
serum-common = { git = "https://github.com/project-serum/serum-dex", features = ["client"] }
|
||||||
dirs = "3.0"
|
dirs = "3.0"
|
||||||
heck = "0.3.1"
|
heck = "0.3.1"
|
||||||
|
|
|
@ -4,11 +4,13 @@ use anyhow::{anyhow, Error, Result};
|
||||||
use clap::{ArgEnum, Parser};
|
use clap::{ArgEnum, Parser};
|
||||||
use heck::SnakeCase;
|
use heck::SnakeCase;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use solana_cli_config::{Config as SolanaConfig, CONFIG_FILE};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, Signer};
|
use solana_sdk::signature::{Keypair, Signer};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
fn ser_programs(
|
fn ser_programs(
|
||||||
programs: &BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>,
|
programs: &BTreeMap<Cluster, BTreeMap<String, ProgramDeployment>>,
|
||||||
) -> BTreeMap<String, BTreeMap<String, serde_json::Value>> {
|
) -> BTreeMap<String, BTreeMap<String, serde_json::Value>> {
|
||||||
|
|
|
@ -1400,8 +1400,21 @@ pub enum BinVerificationState {
|
||||||
|
|
||||||
// Fetches an IDL for the given program_id.
|
// Fetches an IDL for the given program_id.
|
||||||
fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
|
fn fetch_idl(cfg_override: &ConfigOverride, idl_addr: Pubkey) -> Result<Idl> {
|
||||||
let cfg = Config::discover(cfg_override)?.expect("Inside a workspace");
|
let url = match Config::discover(cfg_override)? {
|
||||||
let url = cluster_url(&cfg);
|
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 client = RpcClient::new(url);
|
||||||
|
|
||||||
let mut account = client
|
let mut account = client
|
||||||
|
|
Loading…
Reference in New Issue