From b2298aef5a722b631c0d57e3210b47e2439c9c14 Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Mon, 8 Jan 2024 10:12:10 -0600 Subject: [PATCH 1/8] update rpc_url arg --- Cargo.lock | 36 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 35 +++++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5185254..3a75758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3117,6 +3117,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "serde_yaml" +version = "0.9.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" +dependencies = [ + "indexmap 2.1.0", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "sha1" version = "0.10.6" @@ -3272,6 +3285,22 @@ dependencies = [ "url", ] +[[package]] +name = "solana-cli-config" +version = "1.17.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03306d693c5e6d9b395de28d346491d1730ce9c4a14ab64823dfd9c5d91bfb01" +dependencies = [ + "dirs-next", + "lazy_static", + "serde", + "serde_derive", + "serde_yaml", + "solana-clap-utils", + "solana-sdk", + "url", +] + [[package]] name = "solana-cli-explorer" version = "0.1.0" @@ -3280,6 +3309,7 @@ dependencies = [ "colored", "num-format", "prettytable-rs", + "solana-cli-config", "solana-client", "solana-sdk", "solana-transaction-status", @@ -4662,6 +4692,12 @@ dependencies = [ "void", ] +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" + [[package]] name = "untrusted" version = "0.7.1" diff --git a/Cargo.toml b/Cargo.toml index c1ea106..3d3d325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ num-format = "0.4.4" prettytable-rs = "0.10.0" solana-client = "1.16.24" solana-sdk = "1.17.15" +solana-cli-config = "1.17.15" solana-transaction-status = "1.17.15" terminal_size = "0.3.0" tokio = { version = "1.33.0", features = ["time", "rt", "macros"] } diff --git a/src/main.rs b/src/main.rs index 45b5641..42c9c91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use clap::Parser; +use solana_cli_config::{Config, CONFIG_FILE}; use solana_sdk::{pubkey::Pubkey, signature::Signature}; mod account; @@ -16,14 +17,18 @@ 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, + /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. + #[clap(global = true, short = 'u', long)] + rpc_url: Option, +} + +pub fn get_network(network_str: &str) -> &str { + match network_str { + "devnet" | "dev" | "d" => "https://api.devnet.solana.com", + "mainnet" | "main" | "m" | "mainnet-beta" => "https://api.mainnet-beta.solana.com", + "localnet" | "localhost" | "l" | "local" => "http://localhost:8899", + _ => network_str, + } } #[derive(Debug, Parser, Clone)] @@ -52,9 +57,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, } } From ee6c76ded63f2c617b74764054d6e40295bf0ae4 Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Mon, 8 Jan 2024 10:19:40 -0600 Subject: [PATCH 2/8] add final fallback value for rpc_url --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 42c9c91..b9c7956 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,12 @@ pub struct ExplorerCli { command: Command, /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. - #[clap(global = true, short = 'u', long)] + #[clap( + long, + short = 'u', + default_value = "http://api.mainnet-beta.solana.com", + global = true + )] rpc_url: Option, } From 838a2d40d92990c3212a0df3e4e1140c09801379 Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Mon, 8 Jan 2024 10:27:11 -0600 Subject: [PATCH 3/8] remove default value lol --- src/main.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9c7956..f570e93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,13 +17,8 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. - #[clap( - long, - short = 'u', - default_value = "http://api.mainnet-beta.solana.com", - global = true - )] + /// Specify an RPC endpoint using "local", "dev", or "main" for defaults, or provide a custom URL. Falls back to the Solana CLI configuration if unspecified. Alias: -u + #[clap(long, short = 'u', global = true)] rpc_url: Option, } From 72d3a3b0277b1d51952878d6cd4b1549690c028d Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Mon, 8 Jan 2024 10:29:15 -0600 Subject: [PATCH 4/8] use get_network fn from utils --- src/main.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index f570e93..012551b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ 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; @@ -17,20 +18,11 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// Specify an RPC endpoint using "local", "dev", or "main" for defaults, or provide a custom URL. Falls back to the Solana CLI configuration if unspecified. Alias: -u + /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. #[clap(long, short = 'u', global = true)] rpc_url: Option, } -pub fn get_network(network_str: &str) -> &str { - match network_str { - "devnet" | "dev" | "d" => "https://api.devnet.solana.com", - "mainnet" | "main" | "m" | "mainnet-beta" => "https://api.mainnet-beta.solana.com", - "localnet" | "localhost" | "l" | "local" => "http://localhost:8899", - _ => network_str, - } -} - #[derive(Debug, Parser, Clone)] pub enum Command { /// Provide a transaction signature to inspect status, accounts, logs. From d7e388ab7964612b087b33bfba72705e7c98eece Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Mon, 8 Jan 2024 10:31:25 -0600 Subject: [PATCH 5/8] suggest alias command for arg --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 012551b..711867e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. + /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. Alias: -u #[clap(long, short = 'u', global = true)] rpc_url: Option, } From 8ad6a7b27610406ac2e603148c5038802e61c537 Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Thu, 28 Mar 2024 10:53:44 -0400 Subject: [PATCH 6/8] document cluster aliases for rpc url config --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 711867e..29bb8c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// Optionally include your RPC endpoint. Use "local", "dev", "main" for default endpoints. Defaults to your Solana CLI config file. Alias: -u + /// Specify your RPC endpoint with shortcuts (l=local, d=dev, m=main, t=test) or full names. Defaults to Solana CLI config. Alias: -u #[clap(long, short = 'u', global = true)] rpc_url: Option, } From c3d139e5af043524d2fc2d511719d6f6f989182c Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Thu, 28 Mar 2024 11:01:20 -0400 Subject: [PATCH 7/8] add solana cli config dep --- Cargo.lock | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 1 + 2 files changed, 46 insertions(+), 9 deletions(-) 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" From 848cd8e0df7079ba00f80b23436c8bda8ed33e5e Mon Sep 17 00:00:00 2001 From: Eliascm17 Date: Thu, 28 Mar 2024 11:02:41 -0400 Subject: [PATCH 8/8] more intuitive url docs --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 70d4459..4f54249 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ pub struct ExplorerCli { #[command(subcommand)] command: Command, - /// Specify your RPC endpoint with shortcuts (l=local, d=dev, m=main, t=test) or full names. Defaults to Solana CLI config. Alias: -u + /// 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, }