Support monikers in solana-tokens (#29693)

This commit is contained in:
Tyera 2023-01-12 23:27:34 -07:00 committed by GitHub
parent 5eab3fb314
commit 055c6a5ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -8,7 +8,7 @@ use {
}, },
solana_clap_utils::{ solana_clap_utils::{
input_parsers::{pubkey_of_signer, value_of}, input_parsers::{pubkey_of_signer, value_of},
input_validators::{is_amount, is_valid_pubkey, is_valid_signer}, input_validators::{is_amount, is_url_or_moniker, is_valid_pubkey, is_valid_signer},
keypair::{pubkey_from_path, signer_from_path}, keypair::{pubkey_from_path, signer_from_path},
}, },
solana_cli_config::CONFIG_FILE, solana_cli_config::CONFIG_FILE,
@ -28,6 +28,7 @@ where
.version(solana_version::version!()) .version(solana_version::version!())
.arg( .arg(
Arg::with_name("config_file") Arg::with_name("config_file")
.short("C")
.long("config") .long("config")
.takes_value(true) .takes_value(true)
.value_name("FILEPATH") .value_name("FILEPATH")
@ -35,12 +36,17 @@ where
.help("Config file"), .help("Config file"),
) )
.arg( .arg(
Arg::with_name("url") Arg::with_name("json_rpc_url")
.short("u")
.long("url") .long("url")
.global(true) .value_name("URL_OR_MONIKER")
.takes_value(true) .takes_value(true)
.value_name("URL") .global(true)
.help("RPC entrypoint address. i.e. http://api.devnet.solana.com"), .validator(is_url_or_moniker)
.help(
"URL for Solana's JSON RPC or moniker (or their first letter): \
[mainnet-beta, testnet, devnet, localhost]",
),
) )
.subcommand( .subcommand(
SubCommand::with_name("distribute-tokens") SubCommand::with_name("distribute-tokens")

View File

@ -1,4 +1,5 @@
use { use {
solana_clap_utils::input_validators::normalize_to_url_if_moniker,
solana_cli_config::{Config, CONFIG_FILE}, solana_cli_config::{Config, CONFIG_FILE},
solana_rpc_client::rpc_client::RpcClient, solana_rpc_client::rpc_client::RpcClient,
solana_tokens::{arg_parser::parse_args, args::Command, commands, spl_token}, solana_tokens::{arg_parser::parse_args, args::Command, commands, spl_token},
@ -26,7 +27,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
Config::default() Config::default()
}; };
let json_rpc_url = command_args.url.unwrap_or(config.json_rpc_url); let json_rpc_url = normalize_to_url_if_moniker(command_args.url.unwrap_or(config.json_rpc_url));
let client = RpcClient::new(json_rpc_url); let client = RpcClient::new(json_rpc_url);
let exit = Arc::new(AtomicBool::default()); let exit = Arc::new(AtomicBool::default());