diff --git a/Cargo.lock b/Cargo.lock index 0648522..d52bd5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1630,7 +1630,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.1.0", + "indexmap 2.2.6", "slab", "tokio", "tokio-util", @@ -1878,9 +1878,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -3206,6 +3206,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha1" version = "0.10.6" @@ -3367,6 +3380,22 @@ dependencies = [ "url", ] +[[package]] +name = "solana-cli-config" +version = "1.18.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7702ec83f471b3a0daffd7e7f6acbe50f9228f2bb66d1276e32b6ed253d45afb" +dependencies = [ + "dirs-next", + "lazy_static", + "serde", + "serde_derive", + "serde_yaml", + "solana-clap-utils", + "solana-sdk", + "url", +] + [[package]] name = "solana-cli-explorer" version = "0.4.0" @@ -3381,6 +3410,7 @@ dependencies = [ "num-format", "prettytable-rs", "solana-account-decoder", + "solana-cli-config", "solana-client", "solana-sdk", "solana-transaction-status", @@ -3403,7 +3433,7 @@ dependencies = [ "dashmap", "futures", "futures-util", - "indexmap 2.1.0", + "indexmap 2.2.6", "indicatif", "log", "quinn", @@ -3449,7 +3479,7 @@ dependencies = [ "bincode", "crossbeam-channel", "futures-util", - "indexmap 2.1.0", + "indexmap 2.2.6", "log", "rand 0.8.5", "rayon", @@ -3895,7 +3925,7 @@ dependencies = [ "crossbeam-channel", "futures-util", "histogram", - "indexmap 2.1.0", + "indexmap 2.2.6", "itertools", "libc", "log", @@ -3940,7 +3970,7 @@ dependencies = [ "async-trait", "bincode", "futures-util", - "indexmap 2.1.0", + "indexmap 2.2.6", "indicatif", "log", "rayon", @@ -4683,7 +4713,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.6", "toml_datetime", "winnow", ] @@ -4694,7 +4724,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.2.6", "toml_datetime", "winnow", ] @@ -4822,6 +4852,12 @@ dependencies = [ "void", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.7.1" diff --git a/Cargo.toml b/Cargo.toml index 7278530..cf84efe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ num-format = "0.4.4" prettytable-rs = "0.10.0" solana-account-decoder = "1.18.8" solana-client = "1.18.8" +solana-cli-config = "1.18.8" solana-sdk = "1.18.8" solana-transaction-status = "1.18.8" spl-token = "4.0.0" diff --git a/src/main.rs b/src/main.rs index 48e58d5..4f54249 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,9 @@ use std::str::FromStr; use clap::Parser; +use solana_cli_config::{Config, CONFIG_FILE}; use solana_sdk::{pubkey::Pubkey, signature::Signature}; +use utils::get_network; mod account; mod transaction; @@ -16,14 +18,9 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// The url/endpoint to use for any rpc requests. - #[arg( - long, - short = 'u', - default_value = "http://api.mainnet-beta.solana.com", - global = true - )] - rpc_url: String, + /// Specify your RPC endpoint with shortcuts (l=localnet, d=devnet, m=mainnet, t=testnet). Defaults to Solana CLI config. Alias: -u + #[clap(long, short = 'u', global = true)] + rpc_url: Option, } #[derive(Debug, Parser, Clone)] @@ -52,9 +49,19 @@ pub struct Account { #[tokio::main(flavor = "current_thread")] async fn main() { let args = ExplorerCli::parse(); + let config = match CONFIG_FILE.as_ref() { + Some(config_file) => Config::load(config_file).unwrap_or_else(|_| { + println!("Failed to load config file: {}", config_file); + Config::default() + }), + None => Config::default(), + }; + let network_url = &get_network(&args.rpc_url.unwrap_or(config.json_rpc_url)).to_string(); match args.command { - Command::Transaction(transaction) => transaction::handler(args.rpc_url, transaction).await, - Command::Account(account) => account::handler(args.rpc_url, account).await, + Command::Transaction(transaction) => { + transaction::handler(network_url.to_string(), transaction).await + } + Command::Account(account) => account::handler(network_url.to_string(), account).await, } }