From 7e2df7b4e4f36c306dbded283d90f724c8ca5ab8 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:44:26 +0900 Subject: [PATCH 01/22] upgrade clap version to `3.2.23` --- Cargo.lock | 2 +- token/cli/Cargo.toml | 2 +- token/cli/src/bench.rs | 2 +- token/cli/src/clap_app.rs | 2 +- token/cli/src/command.rs | 2 +- token/cli/src/config.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48c91011ecd..0dcbe773d5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7638,7 +7638,7 @@ dependencies = [ "serde_json", "serial_test", "solana-account-decoder", - "solana-clap-utils", + "solana-clap-v3-utils", "solana-cli-config", "solana-cli-output", "solana-client", diff --git a/token/cli/Cargo.toml b/token/cli/Cargo.toml index aeb46da3c3e..49df368ccef 100644 --- a/token/cli/Cargo.toml +++ b/token/cli/Cargo.toml @@ -13,7 +13,7 @@ walkdir = "2" [dependencies] base64 = "0.22.1" -clap = "2.33.3" +clap = "3.2.23" console = "0.15.8" futures = "0.3" serde = "1.0.209" diff --git a/token/cli/src/bench.rs b/token/cli/src/bench.rs index e6e04ebe241..537daeb4a76 100644 --- a/token/cli/src/bench.rs +++ b/token/cli/src/bench.rs @@ -2,7 +2,7 @@ use { crate::{clap_app::Error, command::CommandResult, config::Config}, clap::{value_t_or_exit, ArgMatches}, - solana_clap_utils::input_parsers::pubkey_of_signer, + solana_clap_v3_utils::input_parsers::pubkey_of_signer, solana_client::{ nonblocking::rpc_client::RpcClient, rpc_client::RpcClient as BlockingRpcClient, tpu_client::TpuClient, tpu_client::TpuClientConfig, diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 74c5f4bf186..69ca8aa1309 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -2,7 +2,7 @@ use { clap::{ crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgGroup, SubCommand, }, - solana_clap_utils::{ + solana_clap_v3_utils::{ fee_payer::fee_payer_arg, input_validators::{ is_amount, is_amount_or_all, is_parsable, is_pubkey, is_url_or_moniker, diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index cd9c9f12252..f441b0e31b6 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -16,7 +16,7 @@ use { parse_token::{get_token_account_mint, parse_token_v2, TokenAccountType, UiAccountState}, UiAccountData, }, - solana_clap_utils::{ + solana_clap_v3_utils::{ input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, value_of}, keypair::signer_from_path, }, diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 8157551d74b..aecb56e7bd2 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -1,7 +1,7 @@ use { crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG}, clap::ArgMatches, - solana_clap_utils::{ + solana_clap_v3_utils::{ input_parsers::{pubkey_of_signer, value_of}, input_validators::normalize_to_url_if_moniker, keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig}, From 12a68e320d1d7329bbe37feb5fce3de8bc985a87 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:55:29 +0900 Subject: [PATCH 02/22] remove lifetime parameters from `ArgMatches` --- token/cli/src/bench.rs | 2 +- token/cli/src/command.rs | 6 +++--- token/cli/src/config.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/token/cli/src/bench.rs b/token/cli/src/bench.rs index 537daeb4a76..89c6164d33b 100644 --- a/token/cli/src/bench.rs +++ b/token/cli/src/bench.rs @@ -22,7 +22,7 @@ use { }; pub(crate) async fn bench_process_command( - matches: &ArgMatches<'_>, + matches: &ArgMatches, config: &Config<'_>, mut signers: Vec>, wallet_manager: &mut Option>, diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index f441b0e31b6..37de23134a7 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -97,7 +97,7 @@ fn new_throwaway_signer() -> (Arc, Pubkey) { } fn get_signer( - matches: &ArgMatches<'_>, + matches: &ArgMatches, keypair_name: &str, wallet_manager: &mut Option>, ) -> Option<(Arc, Pubkey)> { @@ -109,7 +109,7 @@ fn get_signer( }) } -fn parse_amount_or_all(matches: &ArgMatches<'_>) -> Option { +fn parse_amount_or_all(matches: &ArgMatches) -> Option { match matches.value_of("amount").unwrap() { "ALL" => None, amount => Some(amount.parse::().unwrap()), @@ -3494,7 +3494,7 @@ struct ConfidentialTransferArgs { pub async fn process_command<'a>( sub_command: &CommandName, - sub_matches: &ArgMatches<'_>, + sub_matches: &ArgMatches, config: &Config<'a>, mut wallet_manager: Option>, mut bulk_signers: Vec>, diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index aecb56e7bd2..752a4dcd8ab 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -31,7 +31,7 @@ use { type SignersOf = Vec<(Arc, Pubkey)>; fn signers_of( - matches: &ArgMatches<'_>, + matches: &ArgMatches, name: &str, wallet_manager: &mut Option>, ) -> Result, Box> { @@ -76,7 +76,7 @@ pub struct Config<'a> { impl<'a> Config<'a> { pub async fn new( - matches: &ArgMatches<'_>, + matches: &ArgMatches, wallet_manager: &mut Option>, bulk_signers: &mut Vec>, multisigner_ids: &'a mut Vec, @@ -127,7 +127,7 @@ impl<'a> Config<'a> { } fn extract_multisig_signers( - matches: &ArgMatches<'_>, + matches: &ArgMatches, wallet_manager: &mut Option>, bulk_signers: &mut Vec>, multisigner_ids: &'a mut Vec, @@ -147,7 +147,7 @@ impl<'a> Config<'a> { } pub async fn new_with_clients_and_ws_url( - matches: &ArgMatches<'_>, + matches: &ArgMatches, wallet_manager: &mut Option>, bulk_signers: &mut Vec>, multisigner_ids: &'a mut Vec, @@ -358,7 +358,7 @@ impl<'a> Config<'a> { // return the associated token address for the default address. pub(crate) async fn associated_token_address_or_override( &self, - arg_matches: &ArgMatches<'_>, + arg_matches: &ArgMatches, override_name: &str, wallet_manager: &mut Option>, ) -> Result { @@ -377,7 +377,7 @@ impl<'a> Config<'a> { // return the associated token address for the default address. pub(crate) async fn associated_token_address_for_token_or_override( &self, - arg_matches: &ArgMatches<'_>, + arg_matches: &ArgMatches, override_name: &str, wallet_manager: &mut Option>, token: Option, @@ -409,7 +409,7 @@ impl<'a> Config<'a> { // address if there is one pub(crate) fn pubkey_or_default( &self, - arg_matches: &ArgMatches<'_>, + arg_matches: &ArgMatches, address_name: &str, wallet_manager: &mut Option>, ) -> Result { From 529229b3dc83fb61f0cdf9b17699c4f580541991 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:57:43 +0900 Subject: [PATCH 03/22] remove extra lifetime parameters from `Arg` --- token/cli/src/clap_app.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 69ca8aa1309..fdeb239cdd9 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -238,7 +238,7 @@ impl TryFrom for AuthorityType { } } -pub fn owner_address_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn owner_address_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(OWNER_ADDRESS_ARG.name) .long(OWNER_ADDRESS_ARG.long) .takes_value(true) @@ -247,7 +247,7 @@ pub fn owner_address_arg<'a, 'b>() -> Arg<'a, 'b> { .help(OWNER_ADDRESS_ARG.help) } -pub fn owner_keypair_arg_with_value_name<'a, 'b>(value_name: &'static str) -> Arg<'a, 'b> { +pub fn owner_keypair_arg_with_value_name<'a, 'b>(value_name: &'static str) -> Arg<'a> { Arg::with_name(OWNER_KEYPAIR_ARG.name) .long(OWNER_KEYPAIR_ARG.long) .takes_value(true) @@ -256,11 +256,11 @@ pub fn owner_keypair_arg_with_value_name<'a, 'b>(value_name: &'static str) -> Ar .help(OWNER_KEYPAIR_ARG.help) } -pub fn owner_keypair_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn owner_keypair_arg<'a, 'b>() -> Arg<'a> { owner_keypair_arg_with_value_name("OWNER_KEYPAIR") } -pub fn mint_address_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn mint_address_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(MINT_ADDRESS_ARG.name) .long(MINT_ADDRESS_ARG.long) .takes_value(true) @@ -273,7 +273,7 @@ fn is_mint_decimals(string: String) -> Result<(), String> { is_parsable::(string) } -pub fn mint_decimals_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn mint_decimals_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(MINT_DECIMALS_ARG.name) .long(MINT_DECIMALS_ARG.long) .takes_value(true) @@ -293,7 +293,7 @@ impl MintArgs for App<'_, '_> { } } -pub fn delegate_address_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn delegate_address_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(DELEGATE_ADDRESS_ARG.name) .long(DELEGATE_ADDRESS_ARG.long) .takes_value(true) @@ -302,7 +302,7 @@ pub fn delegate_address_arg<'a, 'b>() -> Arg<'a, 'b> { .help(DELEGATE_ADDRESS_ARG.help) } -pub fn transfer_lamports_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn transfer_lamports_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(TRANSFER_LAMPORTS_ARG.name) .long(TRANSFER_LAMPORTS_ARG.long) .takes_value(true) @@ -311,7 +311,7 @@ pub fn transfer_lamports_arg<'a, 'b>() -> Arg<'a, 'b> { .help(TRANSFER_LAMPORTS_ARG.help) } -pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a, 'b> { +pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a> { Arg::with_name(MULTISIG_SIGNER_ARG.name) .long(MULTISIG_SIGNER_ARG.long) .validator(is_valid_signer) @@ -353,50 +353,50 @@ where struct SignOnlyNeedsFullMintSpec {} impl offline::ArgsConfig for SignOnlyNeedsFullMintSpec { - fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_ADDRESS_ARG.name, MINT_DECIMALS_ARG.name]) } - fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn signer_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_ADDRESS_ARG.name, MINT_DECIMALS_ARG.name]) } } struct SignOnlyNeedsMintDecimals {} impl offline::ArgsConfig for SignOnlyNeedsMintDecimals { - fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_DECIMALS_ARG.name]) } - fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn signer_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_DECIMALS_ARG.name]) } } struct SignOnlyNeedsMintAddress {} impl offline::ArgsConfig for SignOnlyNeedsMintAddress { - fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_ADDRESS_ARG.name]) } - fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn signer_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[MINT_ADDRESS_ARG.name]) } } struct SignOnlyNeedsDelegateAddress {} impl offline::ArgsConfig for SignOnlyNeedsDelegateAddress { - fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[DELEGATE_ADDRESS_ARG.name]) } - fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn signer_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[DELEGATE_ADDRESS_ARG.name]) } } struct SignOnlyNeedsTransferLamports {} impl offline::ArgsConfig for SignOnlyNeedsTransferLamports { - fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn sign_only_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[TRANSFER_LAMPORTS_ARG.name]) } - fn signer_arg<'a, 'b>(&self, arg: Arg<'a, 'b>) -> Arg<'a, 'b> { + fn signer_arg<'a, 'b>(&self, arg: Arg<'a>) -> Arg<'a> { arg.requires_all(&[TRANSFER_LAMPORTS_ARG.name]) } } From 5d1c9ec487e0beac36022af91db4f6187513e47a Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:58:28 +0900 Subject: [PATCH 04/22] remove extra lifetime parameters from `App` --- token/cli/src/clap_app.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index fdeb239cdd9..b5561ff953b 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -286,7 +286,7 @@ pub trait MintArgs { fn mint_args(self) -> Self; } -impl MintArgs for App<'_, '_> { +impl MintArgs for App<'_> { fn mint_args(self) -> Self { self.arg(mint_address_arg().requires(MINT_DECIMALS_ARG.name)) .arg(mint_decimals_arg().requires(MINT_ADDRESS_ARG.name)) @@ -419,7 +419,7 @@ pub(crate) trait BenchSubCommand { fn bench_subcommand(self) -> Self; } -impl BenchSubCommand for App<'_, '_> { +impl BenchSubCommand for App<'_> { fn bench_subcommand(self) -> Self { self.subcommand( SubCommand::with_name("bench") @@ -560,7 +560,7 @@ pub fn app<'a, 'b>( default_decimals: &'a str, minimum_signers_help: &'b str, multisig_member_help: &'b str, -) -> App<'a, 'b> { +) -> App<'a> { App::new(crate_name!()) .about(crate_description!()) .version(crate_version!()) From 6dd2a6c63442de8f74832d6cdf875ff1cf0c6535 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:01:06 +0900 Subject: [PATCH 05/22] use `usize` type parameters for `min_values` and `max_values` --- token/cli/src/clap_app.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index b5561ff953b..89051dcdbc0 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -318,8 +318,8 @@ pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a> { .value_name("MULTISIG_SIGNER") .takes_value(true) .multiple(true) - .min_values(0u64) - .max_values(MAX_SIGNERS as u64) + .min_values(0_usize) + .max_values(MAX_SIGNERS) .help(MULTISIG_SIGNER_ARG.help) } @@ -1218,8 +1218,8 @@ pub fn app<'a, 'b>( .takes_value(true) .index(2) .required(true) - .min_values(MIN_SIGNERS as u64) - .max_values(MAX_SIGNERS as u64) + .min_values(MIN_SIGNERS) + .max_values(MAX_SIGNERS) .help(multisig_member_help), ) .arg( @@ -1408,7 +1408,7 @@ pub fn app<'a, 'b>( .value_name("PUBKEY:ROLE") .takes_value(true) .multiple(true) - .min_values(0u64) + .min_values(0_usize) .help("Additional pubkey(s) required for a transfer hook and their \ role, in the format \":\". The role must be \ \"readonly\", \"writable\". \"readonly-signer\", or \"writable-signer\".\ @@ -2247,7 +2247,7 @@ pub fn app<'a, 'b>( .value_name("ACCOUNT_ADDRESS") .takes_value(true) .multiple(true) - .min_values(0u64) + .min_values(0_usize) .help("The token accounts to withdraw from") ) .arg( From 6fccefeb4db94e6fb8289196affcd953f029c515 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:02:19 +0900 Subject: [PATCH 06/22] use `char` type parameters for `short` arguments --- token/cli/src/clap_app.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 89051dcdbc0..da05d35d304 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -567,7 +567,7 @@ pub fn app<'a, 'b>( .setting(AppSettings::SubcommandRequiredElseHelp) .arg( Arg::with_name("config_file") - .short("C") + .short('C') .long("config") .value_name("PATH") .takes_value(true) @@ -576,7 +576,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("verbose") - .short("v") + .short('v') .long("verbose") .takes_value(false) .global(true) @@ -601,7 +601,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("program_id") - .short("p") + .short('p') .long("program-id") .value_name("ADDRESS") .takes_value(true) @@ -612,7 +612,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("json_rpc_url") - .short("u") + .short('u') .long("url") .value_name("URL_OR_MONIKER") .takes_value(true) From 81dfff1aed7a93b67e3c0b3658ce100fe5a9b827 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:06:13 +0900 Subject: [PATCH 07/22] update syntax for custom validator functions --- token/cli/src/clap_app.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index da05d35d304..93fb0ba07f7 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -269,7 +269,7 @@ pub fn mint_address_arg<'a, 'b>() -> Arg<'a> { .help(MINT_ADDRESS_ARG.help) } -fn is_mint_decimals(string: String) -> Result<(), String> { +fn is_mint_decimals(string: &str) -> Result<(), String> { is_parsable::(string) } @@ -323,7 +323,7 @@ pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a> { .help(MULTISIG_SIGNER_ARG.help) } -fn is_multisig_minimum_signers(string: String) -> Result<(), String> { +fn is_multisig_minimum_signers(string: &str) -> Result<(), String> { let v = u8::from_str(&string).map_err(|e| e.to_string())? as usize; if v < MIN_SIGNERS { Err(format!("must be at least {}", MIN_SIGNERS)) From d0648fbf8da750103e4614a591521d1d8f8891bf Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:14:43 +0900 Subject: [PATCH 08/22] update pattern matching syntax for `subcommand` --- token/cli/src/bench.rs | 8 ++++---- token/cli/src/main.rs | 3 +-- token/cli/tests/command.rs | 6 ++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/token/cli/src/bench.rs b/token/cli/src/bench.rs index 89c6164d33b..db58f5db97f 100644 --- a/token/cli/src/bench.rs +++ b/token/cli/src/bench.rs @@ -30,7 +30,7 @@ pub(crate) async fn bench_process_command( assert!(!config.sign_only); match matches.subcommand() { - ("create-accounts", Some(arg_matches)) => { + Some(("create-accounts", arg_matches)) => { let token = pubkey_of_signer(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); @@ -42,7 +42,7 @@ pub(crate) async fn bench_process_command( command_create_accounts(config, signers, &token, n, &owner).await?; } - ("close-accounts", Some(arg_matches)) => { + Some(("close-accounts", arg_matches)) => { let token = pubkey_of_signer(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); @@ -53,7 +53,7 @@ pub(crate) async fn bench_process_command( command_close_accounts(config, signers, &token, n, &owner).await?; } - ("deposit-into", Some(arg_matches)) => { + Some(("deposit-into", arg_matches)) => { let token = pubkey_of_signer(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); @@ -68,7 +68,7 @@ pub(crate) async fn bench_process_command( ) .await?; } - ("withdraw-from", Some(arg_matches)) => { + Some(("withdraw-from", arg_matches)) => { let token = pubkey_of_signer(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); diff --git a/token/cli/src/main.rs b/token/cli/src/main.rs index 6566efe8d1e..1f93fad01e5 100644 --- a/token/cli/src/main.rs +++ b/token/cli/src/main.rs @@ -19,9 +19,8 @@ async fn main() -> Result<(), Error> { let mut wallet_manager = None; let mut bulk_signers: Vec> = Vec::new(); - let (sub_command, sub_matches) = app_matches.subcommand(); + let (sub_command, matches) = app_matches.subcommand().unwrap(); let sub_command = CommandName::from_str(sub_command).unwrap(); - let matches = sub_matches.unwrap(); let mut multisigner_ids = Vec::new(); let config = Config::new( diff --git a/token/cli/tests/command.rs b/token/cli/tests/command.rs index e13ce549c09..6b05c5b994b 100644 --- a/token/cli/tests/command.rs +++ b/token/cli/tests/command.rs @@ -439,9 +439,8 @@ where &multisig_member_help, ) .get_matches_from(args); - let (sub_command, sub_matches) = app_matches.subcommand(); + let (sub_command, matches) = app_matches.subcommand().unwrap(); let sub_command = CommandName::from_str(sub_command).unwrap(); - let matches = sub_matches.unwrap(); let wallet_manager = None; let bulk_signers: Vec> = vec![Arc::new(clone_keypair(payer))]; @@ -459,9 +458,8 @@ async fn exec_test_cmd>(config: &Config<'_>, args: &[T]) -> Comm &multisig_member_help, ) .get_matches_from(args); - let (sub_command, sub_matches) = app_matches.subcommand(); + let (sub_command, matches) = app_matches.subcommand().unwrap(); let sub_command = CommandName::from_str(sub_command).unwrap(); - let matches = sub_matches.unwrap(); let mut wallet_manager = None; let mut bulk_signers: Vec> = Vec::new(); From 39905c2c198b75609871aae290b458777c1c811d Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:38:01 +0900 Subject: [PATCH 09/22] update for new `possible_values` syntax --- token/cli/src/clap_app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 93fb0ba07f7..ce93993a69c 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1252,7 +1252,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority_type") .value_name("AUTHORITY_TYPE") .takes_value(true) - .possible_values(&CliAuthorityType::iter().map(Into::into).collect::>()) + .possible_values(&CliAuthorityType::iter().map(Into::<&str>::into).collect::>()) .index(2) .required(true) .help("The new authority type. \ From 5163cde11983f879c3bbb6bf9cc74e0f98f99544 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:39:38 +0900 Subject: [PATCH 10/22] allow deprecated input validation for now --- token/cli/src/clap_app.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index ce93993a69c..b7a58929cd3 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use { clap::{ crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgGroup, SubCommand, From c26a85a08a38c5ae2ca5da4fb7317c29afe49ea9 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:54:42 +0900 Subject: [PATCH 11/22] resolve lifetime specifier issue with higher order validator functions --- Cargo.lock | 4 +- token/cli/src/clap_app.rs | 308 +++++++++++++++++++------------------- 2 files changed, 156 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0dcbe773d5a..2d2fec0ff77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7629,7 +7629,7 @@ version = "4.1.1" dependencies = [ "assert_cmd", "base64 0.22.1", - "clap 2.34.0", + "clap 3.2.25", "console", "futures 0.3.30", "libtest-mimic", @@ -7638,7 +7638,7 @@ dependencies = [ "serde_json", "serial_test", "solana-account-decoder", - "solana-clap-v3-utils", + "solana-clap-utils", "solana-cli-config", "solana-cli-output", "solana-client", diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index b7a58929cd3..2199aee2b0c 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -240,34 +240,34 @@ impl TryFrom for AuthorityType { } } -pub fn owner_address_arg<'a, 'b>() -> Arg<'a> { +pub fn owner_address_arg<'a>() -> Arg<'a> { Arg::with_name(OWNER_ADDRESS_ARG.name) .long(OWNER_ADDRESS_ARG.long) .takes_value(true) .value_name("OWNER_ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .help(OWNER_ADDRESS_ARG.help) } -pub fn owner_keypair_arg_with_value_name<'a, 'b>(value_name: &'static str) -> Arg<'a> { +pub fn owner_keypair_arg_with_value_name<'a>(value_name: &'static str) -> Arg<'a> { Arg::with_name(OWNER_KEYPAIR_ARG.name) .long(OWNER_KEYPAIR_ARG.long) .takes_value(true) .value_name(value_name) - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .help(OWNER_KEYPAIR_ARG.help) } -pub fn owner_keypair_arg<'a, 'b>() -> Arg<'a> { +pub fn owner_keypair_arg<'a>() -> Arg<'a> { owner_keypair_arg_with_value_name("OWNER_KEYPAIR") } -pub fn mint_address_arg<'a, 'b>() -> Arg<'a> { +pub fn mint_address_arg<'a>() -> Arg<'a> { Arg::with_name(MINT_ADDRESS_ARG.name) .long(MINT_ADDRESS_ARG.long) .takes_value(true) .value_name("MINT_ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .help(MINT_ADDRESS_ARG.help) } @@ -275,7 +275,7 @@ fn is_mint_decimals(string: &str) -> Result<(), String> { is_parsable::(string) } -pub fn mint_decimals_arg<'a, 'b>() -> Arg<'a> { +pub fn mint_decimals_arg<'a>() -> Arg<'a> { Arg::with_name(MINT_DECIMALS_ARG.name) .long(MINT_DECIMALS_ARG.long) .takes_value(true) @@ -295,28 +295,28 @@ impl MintArgs for App<'_> { } } -pub fn delegate_address_arg<'a, 'b>() -> Arg<'a> { +pub fn delegate_address_arg<'a>() -> Arg<'a> { Arg::with_name(DELEGATE_ADDRESS_ARG.name) .long(DELEGATE_ADDRESS_ARG.long) .takes_value(true) .value_name("DELEGATE_ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .help(DELEGATE_ADDRESS_ARG.help) } -pub fn transfer_lamports_arg<'a, 'b>() -> Arg<'a> { +pub fn transfer_lamports_arg<'a>() -> Arg<'a> { Arg::with_name(TRANSFER_LAMPORTS_ARG.name) .long(TRANSFER_LAMPORTS_ARG.long) .takes_value(true) .value_name("LAMPORTS") - .validator(is_amount) + .validator(|s| is_amount(s)) .help(TRANSFER_LAMPORTS_ARG.help) } -pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a> { +pub fn multisig_signer_arg<'a>() -> Arg<'a> { Arg::with_name(MULTISIG_SIGNER_ARG.name) .long(MULTISIG_SIGNER_ARG.long) - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("MULTISIG_SIGNER") .takes_value(true) .multiple(true) @@ -326,7 +326,7 @@ pub fn multisig_signer_arg<'a, 'b>() -> Arg<'a> { } fn is_multisig_minimum_signers(string: &str) -> Result<(), String> { - let v = u8::from_str(&string).map_err(|e| e.to_string())? as usize; + let v = u8::from_str(string).map_err(|e| e.to_string())? as usize; if v < MIN_SIGNERS { Err(format!("must be at least {}", MIN_SIGNERS)) } else if v > MAX_SIGNERS { @@ -433,7 +433,7 @@ impl BenchSubCommand for App<'_> { .about("Create multiple token accounts for benchmarking") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -456,7 +456,7 @@ impl BenchSubCommand for App<'_> { .about("Close multiple token accounts used for benchmarking") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -479,7 +479,7 @@ impl BenchSubCommand for App<'_> { .about("Deposit tokens into multiple accounts") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -497,7 +497,7 @@ impl BenchSubCommand for App<'_> { ) .arg( Arg::with_name("amount") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(3) @@ -507,7 +507,7 @@ impl BenchSubCommand for App<'_> { .arg( Arg::with_name("from") .long("from") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("SOURCE_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The source token account address [default: associated token account for --owner]") @@ -519,7 +519,7 @@ impl BenchSubCommand for App<'_> { .about("Withdraw tokens from multiple accounts") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -537,7 +537,7 @@ impl BenchSubCommand for App<'_> { ) .arg( Arg::with_name("amount") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(3) @@ -547,7 +547,7 @@ impl BenchSubCommand for App<'_> { .arg( Arg::with_name("to") .long("to") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The recipient token account address [default: associated token account for --owner]") @@ -558,10 +558,10 @@ impl BenchSubCommand for App<'_> { } } -pub fn app<'a, 'b>( +pub fn app<'a>( default_decimals: &'a str, - minimum_signers_help: &'b str, - multisig_member_help: &'b str, + minimum_signers_help: &'a str, + multisig_member_help: &'a str, ) -> App<'a> { App::new(crate_name!()) .about(crate_description!()) @@ -590,7 +590,7 @@ pub fn app<'a, 'b>( .value_name("FORMAT") .global(true) .takes_value(true) - .possible_values(&["json", "json-compact"]) + .possible_values(["json", "json-compact"]) .help("Return information in specified output format"), ) .arg( @@ -608,8 +608,8 @@ pub fn app<'a, 'b>( .value_name("ADDRESS") .takes_value(true) .global(true) - .validator(is_valid_token_program_id) .conflicts_with("program_2022") + .validator(|s| is_valid_token_program_id(s)) .help("SPL Token program id"), ) .arg( @@ -619,7 +619,7 @@ pub fn app<'a, 'b>( .value_name("URL_OR_MONIKER") .takes_value(true) .global(true) - .validator(is_url_or_moniker) + .validator(|s| is_url_or_moniker(s)) .help( "URL for Solana's JSON RPC or moniker (or their first letter): \ [mainnet-beta, testnet, devnet, localhost] \ @@ -658,7 +658,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token_keypair") .value_name("TOKEN_KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .index(1) .help( @@ -672,7 +672,7 @@ pub fn app<'a, 'b>( .long("mint-authority") .alias("owner") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .help( "Specify the mint authority address. \ @@ -718,7 +718,7 @@ pub fn app<'a, 'b>( Arg::with_name("metadata_address") .long("metadata-address") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .conflicts_with("enable_metadata") .help( @@ -729,7 +729,7 @@ pub fn app<'a, 'b>( Arg::with_name("group_address") .long("group-address") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .conflicts_with("enable_group") .help( @@ -740,7 +740,7 @@ pub fn app<'a, 'b>( Arg::with_name("member_address") .long("member-address") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .conflicts_with("enable_member") .help( @@ -761,7 +761,7 @@ pub fn app<'a, 'b>( .long("default-account-state") .requires("enable_freeze") .takes_value(true) - .possible_values(&["initialized", "frozen"]) + .possible_values(["initialized", "frozen"]) .help("Specify that accounts have a default state. \ Note: specifying \"initialized\" adds an extension, which gives \ the option of specifying default frozen accounts in the future. \ @@ -823,7 +823,7 @@ pub fn app<'a, 'b>( .long("enable-confidential-transfers") .value_names(&["APPROVE-POLICY"]) .takes_value(true) - .possible_values(&["auto", "manual"]) + .possible_values(["auto", "manual"]) .help( "Enable accounts to make confidential transfers. If \"auto\" \ is selected, then accounts are automatically approved to make \ @@ -836,7 +836,7 @@ pub fn app<'a, 'b>( Arg::with_name("transfer_hook") .long("transfer-hook") .value_name("TRANSFER_HOOK_PROGRAM_ID") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .help("Enable the mint authority to set the transfer hook program for this mint"), ) @@ -869,7 +869,7 @@ pub fn app<'a, 'b>( .about("Set the interest rate for an interest-bearing token") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -885,7 +885,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("rate_authority") .long("rate-authority") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("SIGNER") .takes_value(true) .help( @@ -899,7 +899,7 @@ pub fn app<'a, 'b>( .about("Set the transfer hook program id for a token") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -908,7 +908,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("new_program_id") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("NEW_PROGRAM_ID") .takes_value(true) .required_unless("disable") @@ -926,7 +926,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority") .long("authority") .alias("owner") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("SIGNER") .takes_value(true) .help("Specify the authority keypair. Defaults to the client keypair address.") @@ -937,7 +937,7 @@ pub fn app<'a, 'b>( .about("Initialize metadata extension on a token mint") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -973,7 +973,7 @@ pub fn app<'a, 'b>( .long("mint-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the mint authority keypair. \ @@ -985,7 +985,7 @@ pub fn app<'a, 'b>( Arg::with_name("update_authority") .long("update-authority") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .help( "Specify the update authority address. \ @@ -998,7 +998,7 @@ pub fn app<'a, 'b>( .about("Update metadata on a token mint that has the extension") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1031,7 +1031,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("authority") .long("authority") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("SIGNER") .takes_value(true) .help("Specify the metadata update authority keypair. Defaults to the client keypair.") @@ -1045,7 +1045,7 @@ pub fn app<'a, 'b>( .about("Initialize group extension on a token mint") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1054,7 +1054,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("max_size") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("MAX_SIZE") .takes_value(true) .required(true) @@ -1066,7 +1066,7 @@ pub fn app<'a, 'b>( .long("mint-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the mint authority keypair. \ @@ -1078,7 +1078,7 @@ pub fn app<'a, 'b>( Arg::with_name("update_authority") .long("update-authority") .value_name("ADDRESS") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .help( "Specify the update authority address. \ @@ -1091,7 +1091,7 @@ pub fn app<'a, 'b>( .about("Updates the maximum number of members for a group.") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1100,7 +1100,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("new_max_size") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("NEW_MAX_SIZE") .takes_value(true) .required(true) @@ -1111,7 +1111,7 @@ pub fn app<'a, 'b>( Arg::with_name("update_authority") .long("update-authority") .value_name("SIGNER") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the update authority address. \ @@ -1124,7 +1124,7 @@ pub fn app<'a, 'b>( .about("Initialize group member extension on a token mint") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1133,7 +1133,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("group_token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("GROUP_TOKEN_ADDRESS") .takes_value(true) .required(true) @@ -1145,7 +1145,7 @@ pub fn app<'a, 'b>( .long("mint-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the mint authority keypair. \ @@ -1157,7 +1157,7 @@ pub fn app<'a, 'b>( Arg::with_name("group_update_authority") .long("group-update-authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the update authority keypair. \ @@ -1171,7 +1171,7 @@ pub fn app<'a, 'b>( .about("Create a new token account") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1181,7 +1181,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("account_keypair") .value_name("ACCOUNT_KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .index(2) .help( @@ -1216,7 +1216,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("multisig_member") .value_name("MULTISIG_MEMBER_PUBKEY") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .takes_value(true) .index(2) .required(true) @@ -1228,7 +1228,7 @@ pub fn app<'a, 'b>( Arg::with_name("address_keypair") .long("address-keypair") .value_name("ADDRESS_KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the address keypair. \ @@ -1243,7 +1243,7 @@ pub fn app<'a, 'b>( .about("Authorize a new signing keypair to a token or token account") .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -1254,7 +1254,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority_type") .value_name("AUTHORITY_TYPE") .takes_value(true) - .possible_values(&CliAuthorityType::iter().map(Into::<&str>::into).collect::>()) + .possible_values(CliAuthorityType::iter().map(Into::<&str>::into).collect::>()) .index(2) .required(true) .help("The new authority type. \ @@ -1264,7 +1264,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("new_authority") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("AUTHORITY_ADDRESS") .takes_value(true) .index(3) @@ -1276,7 +1276,7 @@ pub fn app<'a, 'b>( .long("authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the current authority keypair. \ @@ -1305,7 +1305,7 @@ pub fn app<'a, 'b>( .about("Transfer tokens between accounts") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1314,7 +1314,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount_or_all) + .validator(|s| is_amount_or_all(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -1323,7 +1323,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("recipient") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("RECIPIENT_WALLET_ADDRESS or RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(3) @@ -1334,7 +1334,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("from") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("SENDER_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("from") @@ -1398,7 +1398,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("expected_fee") .long("expected-fee") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .help("Expected fee amount collected during the transfer"), @@ -1406,7 +1406,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("transfer_hook_account") .long("transfer-hook-account") - .validator(validate_transfer_hook_account) + .validator(|s| validate_transfer_hook_account(s)) .value_name("PUBKEY:ROLE") .takes_value(true) .multiple(true) @@ -1435,7 +1435,7 @@ pub fn app<'a, 'b>( .about("Burn tokens from an account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1444,7 +1444,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount_or_all) + .validator(|s| is_amount_or_all(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -1469,7 +1469,7 @@ pub fn app<'a, 'b>( .about("Mint new tokens") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1478,7 +1478,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -1487,7 +1487,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("recipient") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("recipient_owner") @@ -1498,7 +1498,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("recipient_owner") .long("recipient-owner") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("RECIPIENT_WALLET_ADDRESS") .takes_value(true) .conflicts_with("recipient") @@ -1509,7 +1509,7 @@ pub fn app<'a, 'b>( .long("mint-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the mint authority keypair. \ @@ -1528,7 +1528,7 @@ pub fn app<'a, 'b>( .about("Freeze a token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1540,7 +1540,7 @@ pub fn app<'a, 'b>( .long("freeze-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the freeze authority keypair. \ @@ -1558,7 +1558,7 @@ pub fn app<'a, 'b>( .about("Thaw a token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1570,7 +1570,7 @@ pub fn app<'a, 'b>( .long("freeze-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the freeze authority keypair. \ @@ -1588,7 +1588,7 @@ pub fn app<'a, 'b>( .about("Wrap native SOL in a SOL token account") .arg( Arg::with_name("amount") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("AMOUNT") .takes_value(true) .index(1) @@ -1599,7 +1599,7 @@ pub fn app<'a, 'b>( Arg::with_name("wallet_keypair") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the keypair for the wallet which will have its native SOL wrapped. \ @@ -1630,7 +1630,7 @@ pub fn app<'a, 'b>( .about("Unwrap a SOL token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1641,7 +1641,7 @@ pub fn app<'a, 'b>( Arg::with_name("wallet_keypair") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the keypair for the wallet which owns the wrapped SOL. \ @@ -1660,7 +1660,7 @@ pub fn app<'a, 'b>( .about("Approve a delegate for a token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1669,7 +1669,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -1678,7 +1678,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("delegate") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("DELEGATE_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(3) @@ -1698,7 +1698,7 @@ pub fn app<'a, 'b>( .about("Revoke a delegate's authority") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1717,7 +1717,7 @@ pub fn app<'a, 'b>( .about("Close a token account") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1728,7 +1728,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("recipient") .long("recipient") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("REFUND_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the account to receive remaining SOL [default: --owner]"), @@ -1738,7 +1738,7 @@ pub fn app<'a, 'b>( .long("close-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's close authority if it has one, \ @@ -1750,7 +1750,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -1766,7 +1766,7 @@ pub fn app<'a, 'b>( .about("Close a token mint") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1776,7 +1776,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("recipient") .long("recipient") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("REFUND_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the account to receive remaining SOL [default: --owner]"), @@ -1785,7 +1785,7 @@ pub fn app<'a, 'b>( Arg::with_name("close_authority") .long("close-authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's close authority. \ @@ -1803,7 +1803,7 @@ pub fn app<'a, 'b>( .about("Get token account balance") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1813,7 +1813,7 @@ pub fn app<'a, 'b>( .arg(owner_address_arg().conflicts_with("address")) .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("address") @@ -1827,7 +1827,7 @@ pub fn app<'a, 'b>( .about("Get token supply") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1840,7 +1840,7 @@ pub fn app<'a, 'b>( .about("List all token accounts by owner") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1881,7 +1881,7 @@ pub fn app<'a, 'b>( .about("Get wallet address") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .long("token") @@ -1902,7 +1902,7 @@ pub fn app<'a, 'b>( .setting(AppSettings::Hidden) .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1915,7 +1915,7 @@ pub fn app<'a, 'b>( Arg::with_name(OWNER_ADDRESS_ARG.name) .takes_value(true) .value_name("OWNER_ADDRESS") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .help(OWNER_ADDRESS_ARG.help) .index(2) .conflicts_with("address") @@ -1925,7 +1925,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("address") @@ -1939,7 +1939,7 @@ pub fn app<'a, 'b>( .setting(AppSettings::Hidden) .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("MULTISIG_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1952,7 +1952,7 @@ pub fn app<'a, 'b>( .about("Query details of an SPL Token mint, account, or multisig by address") .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -1984,7 +1984,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("address") @@ -1997,7 +1997,7 @@ pub fn app<'a, 'b>( .about("Enable required transfer memos for token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2015,7 +2015,7 @@ pub fn app<'a, 'b>( .about("Disable required transfer memos for token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2033,7 +2033,7 @@ pub fn app<'a, 'b>( .about("Enable CPI Guard for token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2051,7 +2051,7 @@ pub fn app<'a, 'b>( .about("Disable CPI Guard for token account") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2069,7 +2069,7 @@ pub fn app<'a, 'b>( .about("Updates default account state for the mint. Requires the default account state extension.") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2080,7 +2080,7 @@ pub fn app<'a, 'b>( Arg::with_name("state") .value_name("STATE") .takes_value(true) - .possible_values(&["initialized", "frozen"]) + .possible_values(["initialized", "frozen"]) .index(2) .required(true) .help("The new default account state."), @@ -2089,7 +2089,7 @@ pub fn app<'a, 'b>( Arg::with_name("freeze_authority") .long("freeze-authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's freeze authority. \ @@ -2107,7 +2107,7 @@ pub fn app<'a, 'b>( .about("Updates metadata pointer address for the mint. Requires the metadata pointer extension.") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2117,7 +2117,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("metadata_address") .index(2) - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("METADATA_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2134,7 +2134,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority") .long("authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's metadata-pointer authority. \ @@ -2150,7 +2150,7 @@ pub fn app<'a, 'b>( .about("Updates group pointer address for the mint. Requires the group pointer extension.") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2160,7 +2160,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("group_address") .index(2) - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("GROUP_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2177,7 +2177,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority") .long("authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's group-pointer authority. \ @@ -2193,7 +2193,7 @@ pub fn app<'a, 'b>( .about("Updates group member pointer address for the mint. Requires the group member pointer extension.") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2203,7 +2203,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("member_address") .index(2) - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("MEMBER_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2220,7 +2220,7 @@ pub fn app<'a, 'b>( Arg::with_name("authority") .long("authority") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the token's group-member-pointer authority. \ @@ -2236,7 +2236,7 @@ pub fn app<'a, 'b>( .about("Withdraw withheld transfer fee tokens from mint and / or account(s)") .arg( Arg::with_name("account") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2245,7 +2245,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("source") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("ACCOUNT_ADDRESS") .takes_value(true) .multiple(true) @@ -2263,7 +2263,7 @@ pub fn app<'a, 'b>( .long("withdraw-withheld-authority") .alias("owner") .value_name("KEYPAIR") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .takes_value(true) .help( "Specify the withdraw withheld authority keypair. \ @@ -2286,7 +2286,7 @@ pub fn app<'a, 'b>( .about("Set the transfer fee for a token with a configured transfer fee") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -2302,7 +2302,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("maximum_fee") .value_name("TOKEN_AMOUNT") - .validator(is_amount) + .validator(|s| is_amount(s)) .takes_value(true) .required(true) .help("The new maximum transfer fee in UI amount"), @@ -2310,7 +2310,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("transfer_fee_authority") .long("transfer-fee-authority") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("SIGNER") .takes_value(true) .help( @@ -2326,7 +2326,7 @@ pub fn app<'a, 'b>( .about("Withdraw lamports from a Token Program owned account") .arg( Arg::with_name("from") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("SOURCE_ACCOUNT_ADDRESS") .takes_value(true) .required(true) @@ -2334,7 +2334,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("recipient") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("REFUND_ACCOUNT_ADDRESS") .takes_value(true) .required(true) @@ -2348,7 +2348,7 @@ pub fn app<'a, 'b>( .about("Update confidential transfer configuration for a token") .arg( Arg::with_name("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2360,7 +2360,7 @@ pub fn app<'a, 'b>( .long("approve-policy") .value_name("APPROVE_POLICY") .takes_value(true) - .possible_values(&["auto", "manual"]) + .possible_values(["auto", "manual"]) .help( "Policy for enabling accounts to make confidential transfers. If \"auto\" \ is selected, then accounts are automatically approved to make \ @@ -2392,7 +2392,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("confidential_transfer_authority") .long("confidential-transfer-authority") - .validator(is_valid_signer) + .validator(|s| is_valid_signer(s)) .value_name("SIGNER") .takes_value(true) .help( @@ -2409,7 +2409,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2419,7 +2419,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2451,7 +2451,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2461,7 +2461,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2480,7 +2480,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2490,7 +2490,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2509,7 +2509,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2519,7 +2519,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2538,7 +2538,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2548,7 +2548,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2567,7 +2567,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2576,7 +2576,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount_or_all) + .validator(|s| is_amount_or_all(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -2586,7 +2586,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ @@ -2605,7 +2605,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2614,7 +2614,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("amount") - .validator(is_amount_or_all) + .validator(|s| is_amount_or_all(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .index(2) @@ -2624,7 +2624,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ @@ -2643,7 +2643,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("token") .long("token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2653,7 +2653,7 @@ pub fn app<'a, 'b>( .arg( Arg::with_name("address") .long("address") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ From 6aecfbd3b2922fd89371055da4c1993cb6da0aa5 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 11:06:15 +0900 Subject: [PATCH 12/22] directly specify positional parameter indices --- token/cli/src/clap_app.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 2199aee2b0c..ea5aced1932 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1601,6 +1601,7 @@ pub fn app<'a>( .value_name("KEYPAIR") .validator(|s| is_valid_signer(s)) .takes_value(true) + .index(2) .help( "Specify the keypair for the wallet which will have its native SOL wrapped. \ This wallet will be assigned as the owner of the wrapped SOL token account. \ @@ -1643,6 +1644,7 @@ pub fn app<'a>( .value_name("KEYPAIR") .validator(|s| is_valid_signer(s)) .takes_value(true) + .index(2) .help( "Specify the keypair for the wallet which owns the wrapped SOL. \ This wallet will receive the unwrapped SOL. \ @@ -2250,6 +2252,7 @@ pub fn app<'a>( .takes_value(true) .multiple(true) .min_values(0_usize) + .index(2) .help("The token accounts to withdraw from") ) .arg( From bb18b5337cb7d800f0042d7032f860bd6a5e0359 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 11:17:59 +0900 Subject: [PATCH 13/22] remove non-functioning `owner` alias in some subcommands --- token/cli/src/clap_app.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index ea5aced1932..7280cc9749a 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1640,7 +1640,6 @@ pub fn app<'a>( ) .arg( Arg::with_name("wallet_keypair") - .alias("owner") .value_name("KEYPAIR") .validator(|s| is_valid_signer(s)) .takes_value(true) @@ -1738,7 +1737,6 @@ pub fn app<'a>( .arg( Arg::with_name("close_authority") .long("close-authority") - .alias("owner") .value_name("KEYPAIR") .validator(|s| is_valid_signer(s)) .takes_value(true) @@ -2264,7 +2262,6 @@ pub fn app<'a>( .arg( Arg::with_name("withdraw_withheld_authority") .long("withdraw-withheld-authority") - .alias("owner") .value_name("KEYPAIR") .validator(|s| is_valid_signer(s)) .takes_value(true) From c7122688bf0a03efd4e076e0909aab91cacf1bd8 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 16:32:08 +0900 Subject: [PATCH 14/22] remove long names for positional arguments --- token/cli/src/clap_app.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 7280cc9749a..93325d6cbaa 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -2408,7 +2408,6 @@ pub fn app<'a>( .about("Configure confidential transfers for token account") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2450,7 +2449,6 @@ pub fn app<'a>( for the first time, use `configure-confidential-transfer-account` instead.") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2479,7 +2477,6 @@ pub fn app<'a>( .about("Disable confidential transfers for token account") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2508,7 +2505,6 @@ pub fn app<'a>( .about("Enable non-confidential transfers for token account.") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2537,7 +2533,6 @@ pub fn app<'a>( .about("Disable non-confidential transfers for token account") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2566,7 +2561,6 @@ pub fn app<'a>( .about("Deposit amounts for confidential transfers") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2604,7 +2598,6 @@ pub fn app<'a>( .about("Withdraw amounts for confidential transfers") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -2642,7 +2635,6 @@ pub fn app<'a>( .about("Collect confidential tokens from pending to available balance") .arg( Arg::with_name("token") - .long("token") .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) From ea67826836d9ac84e221e0bc35fb6f1885ddae63 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 09:45:28 +0900 Subject: [PATCH 15/22] remove potential panice from `value_of` and `is_present` --- token/cli/src/config.rs | 50 +++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 752a4dcd8ab..0f57eecef41 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -26,7 +26,7 @@ use { }, token::ComputeUnitLimit, }, - std::{process::exit, rc::Rc, sync::Arc}, + std::{process::exit, rc::Rc, str::FromStr, sync::Arc}, }; type SignersOf = Vec<(Arc, Pubkey)>; @@ -227,11 +227,17 @@ impl<'a> Config<'a> { OutputFormat::Display }); - let nonce_account = pubkey_of_signer(matches, NONCE_ARG.name, wallet_manager) - .unwrap_or_else(|e| { - eprintln!("error: {}", e); - exit(1); - }); + let nonce_account = match pubkey_of_signer(matches, NONCE_ARG.name, wallet_manager) { + Ok(account) => account, + Err(e) => { + if e.is::() { + None + } else { + eprintln!("error: {}", e); + exit(1); + } + } + }; let nonce_authority = if nonce_account.is_some() { let (nonce_authority, _) = signer_from_path( matches, @@ -256,18 +262,28 @@ impl<'a> Config<'a> { None }; - let sign_only = matches.is_present(SIGN_ONLY_ARG.name); - let dump_transaction_message = matches.is_present(DUMP_TRANSACTION_MESSAGE.name); + let sign_only = matches.try_contains_id(SIGN_ONLY_ARG.name).unwrap_or(false); + let dump_transaction_message = matches + .try_contains_id(DUMP_TRANSACTION_MESSAGE.name) + .unwrap_or(false); + + let pubkey_from_matches = |name| { + matches + .try_get_one::(name) + .ok() + .flatten() + .and_then(|pubkey| Pubkey::from_str(pubkey).ok()) + }; let default_program_id = spl_token::id(); let (program_id, restrict_to_program_id) = if matches.is_present("program_2022") { (spl_token_2022::id(), true) - } else if let Some(program_id) = value_of(matches, "program_id") { + } else if let Some(program_id) = pubkey_from_matches("program_id") { (program_id, true) } else if !sign_only { - if let Some(address) = value_of(matches, "token") - .or_else(|| value_of(matches, "account")) - .or_else(|| value_of(matches, "address")) + if let Some(address) = pubkey_from_matches("token") + .or_else(|| pubkey_from_matches("account")) + .or_else(|| pubkey_from_matches("address")) { ( rpc_client @@ -290,7 +306,7 @@ impl<'a> Config<'a> { && !matches.is_present(COMPUTE_UNIT_LIMIT_ARG.name) { clap::Error::with_description( - &format!( + format!( "Need to set `{}` if `{}` and `--{}` are set", COMPUTE_UNIT_LIMIT_ARG.long, COMPUTE_UNIT_PRICE_ARG.long, BLOCKHASH_ARG.long, ), @@ -299,7 +315,12 @@ impl<'a> Config<'a> { .exit(); } - let nonce_blockhash = value_of(matches, BLOCKHASH_ARG.name); + let nonce_blockhash = matches + .try_get_one::(BLOCKHASH_ARG.name) + .ok() + .flatten() + .copied(); + let compute_unit_price = value_of(matches, COMPUTE_UNIT_PRICE_ARG.name); let compute_unit_limit = value_of(matches, COMPUTE_UNIT_LIMIT_ARG.name) .map(ComputeUnitLimit::Static) @@ -310,6 +331,7 @@ impl<'a> Config<'a> { ComputeUnitLimit::Simulated } }); + Self { default_signer, rpc_client, From 6779d261ac0580a792207dc129ade6e63caf01a2 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 09:45:36 +0900 Subject: [PATCH 16/22] add custom `signer_from_path` and `signer_from_path_with_config` --- token/cli/src/config.rs | 46 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 0f57eecef41..1ae673d196f 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -4,16 +4,16 @@ use { solana_clap_v3_utils::{ input_parsers::{pubkey_of_signer, value_of}, input_validators::normalize_to_url_if_moniker, - keypair::{signer_from_path, signer_from_path_with_config, SignerFromPathConfig}, + keypair::SignerFromPathConfig, nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG}, - offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGN_ONLY_ARG}, + offline::{BLOCKHASH_ARG, DUMP_TRANSACTION_MESSAGE, SIGNER_ARG, SIGN_ONLY_ARG}, }, solana_cli_output::OutputFormat, solana_client::nonblocking::rpc_client::RpcClient, solana_remote_wallet::remote_wallet::RemoteWalletManager, solana_sdk::{ account::Account as RawAccount, commitment_config::CommitmentConfig, hash::Hash, - pubkey::Pubkey, signature::Signer, + pubkey::Pubkey, signature::Signer, signer::null_signer::NullSigner, }, spl_associated_token_account_client::address::get_associated_token_address_with_program_id, spl_token_2022::{ @@ -560,3 +560,43 @@ impl<'a> Config<'a> { } } } + +// In clap v2, `value_of` returns `None` if the argument id is not previously specified in +// `Arg`. In contrast, in clap v3, `value_of` panics in this case. Therefore, compared +// to the same function in solana-clap-utils, `signer_from_path` in solana-clap-v3-utils errors +// early when `path` is a valid pubkey, but `SIGNER_ARG.name` is not specified in the args. +// This function behaves exactly as `signer_from_path` from solana-clap-utils by catching +// this special case. +fn signer_from_path( + matches: &ArgMatches, + path: &str, + keypair_name: &str, + wallet_manager: &mut Option>, +) -> Result, Box> { + let config = SignerFromPathConfig::default(); + signer_from_path_with_config(matches, path, keypair_name, wallet_manager, &config) +} + +fn signer_from_path_with_config( + matches: &ArgMatches, + path: &str, + keypair_name: &str, + wallet_manager: &mut Option>, + config: &SignerFromPathConfig, +) -> Result, Box> { + if let Ok(pubkey) = Pubkey::from_str(path) { + if matches.try_contains_id(SIGNER_ARG.name).is_err() + && (config.allow_null_signer || matches.try_contains_id(SIGN_ONLY_ARG.name)?) + { + return Ok(Box::new(NullSigner::new(&pubkey))); + } + } + + solana_clap_v3_utils::keypair::signer_from_path_with_config( + matches, + path, + keypair_name, + wallet_manager, + config, + ) +} From 2d6565fd0c96e70e8b813b341728fea2e8a491a3 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 10:58:57 +0900 Subject: [PATCH 17/22] cargo fmt --- token/cli/src/config.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 1ae673d196f..162ae2838f9 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -561,12 +561,13 @@ impl<'a> Config<'a> { } } -// In clap v2, `value_of` returns `None` if the argument id is not previously specified in -// `Arg`. In contrast, in clap v3, `value_of` panics in this case. Therefore, compared -// to the same function in solana-clap-utils, `signer_from_path` in solana-clap-v3-utils errors -// early when `path` is a valid pubkey, but `SIGNER_ARG.name` is not specified in the args. -// This function behaves exactly as `signer_from_path` from solana-clap-utils by catching -// this special case. +// In clap v2, `value_of` returns `None` if the argument id is not previously +// specified in `Arg`. In contrast, in clap v3, `value_of` panics in this case. +// Therefore, compared to the same function in solana-clap-utils, +// `signer_from_path` in solana-clap-v3-utils errors early when `path` is a +// valid pubkey, but `SIGNER_ARG.name` is not specified in the args. +// This function behaves exactly as `signer_from_path` from solana-clap-utils by +// catching this special case. fn signer_from_path( matches: &ArgMatches, path: &str, From 736759549eb85ad99c253b3ecaf2149483eb1309 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 12 Mar 2024 07:18:24 +0900 Subject: [PATCH 18/22] remove duplicate addition of args in invalid config test --- token/cli/tests/config.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/token/cli/tests/config.rs b/token/cli/tests/config.rs index ff0bfad9dfb..78c765abe0d 100644 --- a/token/cli/tests/config.rs +++ b/token/cli/tests/config.rs @@ -3,9 +3,8 @@ use assert_cmd::cmd::Command; #[test] fn invalid_config_will_cause_commands_to_fail() { let mut cmd = Command::cargo_bin("spl-token").unwrap(); - let args = &["address", "--config", "~/nonexistent/config.yml"]; - cmd.args(args) - .assert() + cmd.args(["address", "--config", "~/nonexistent/config.yml"]); + cmd.assert() .stderr("error: Could not find config file `~/nonexistent/config.yml`\n"); - cmd.args(args).assert().code(1).failure(); + cmd.assert().code(1).failure(); } From 19ee7ba588f74921528f0a4fb879be7b22550672 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Fri, 29 Mar 2024 17:35:39 +0900 Subject: [PATCH 19/22] use `try_get_one` to parse `compute_unit_price` and `compute_unit_limit` --- token/cli/src/config.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 162ae2838f9..20cc258b826 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -300,10 +300,13 @@ impl<'a> Config<'a> { (default_program_id, false) }; - // need to specify a compute limit if compute price and blockhash are specified - if matches.is_present(BLOCKHASH_ARG.name) - && matches.is_present(COMPUTE_UNIT_PRICE_ARG.name) - && !matches.is_present(COMPUTE_UNIT_LIMIT_ARG.name) + if matches.try_contains_id(BLOCKHASH_ARG.name).unwrap_or(false) + && matches + .try_contains_id(COMPUTE_UNIT_PRICE_ARG.name) + .unwrap_or(false) + && !matches + .try_contains_id(COMPUTE_UNIT_LIMIT_ARG.name) + .unwrap_or(false) { clap::Error::with_description( format!( @@ -321,8 +324,17 @@ impl<'a> Config<'a> { .flatten() .copied(); - let compute_unit_price = value_of(matches, COMPUTE_UNIT_PRICE_ARG.name); - let compute_unit_limit = value_of(matches, COMPUTE_UNIT_LIMIT_ARG.name) + let compute_unit_price = matches + .try_get_one::(COMPUTE_UNIT_PRICE_ARG.name) + .ok() + .flatten() + .copied(); + + let compute_unit_limit = matches + .try_get_one::(COMPUTE_UNIT_PRICE_ARG.name) + .ok() + .flatten() + .copied() .map(ComputeUnitLimit::Static) .unwrap_or_else(|| { if nonce_blockhash.is_some() { From f040679867d5e238ce157de776ca8424578170cb Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 28 Apr 2024 16:29:57 +0900 Subject: [PATCH 20/22] hard-code `signer_arg` and `OfflineArgs` --- token/cli/src/clap_app.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 93325d6cbaa..e30e4310332 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -78,6 +78,41 @@ pub const COMPUTE_UNIT_LIMIT_ARG: ArgConstant<'static> = ArgConstant { help: "Set compute unit limit for transaction, in compute units.", }; +// The `signer_arg` in clap-v3-utils` specifies the argument as a +// `PubkeySignature` type, but supporting `PubkeySignature` in the token-cli +// requires a significant re-structuring of the code. Therefore, hard-code the +// `signer_arg` and `OfflineArgs` from clap-utils` here and remove +// it in a subsequent PR. +fn signer_arg<'a>() -> Arg<'a> { + Arg::new(SIGNER_ARG.name) + .long(SIGNER_ARG.long) + .takes_value(true) + .value_name("PUBKEY=SIGNATURE") + .requires(BLOCKHASH_ARG.name) + .action(clap::ArgAction::Append) + .multiple_values(false) + .help(SIGNER_ARG.help) +} + +pub trait OfflineArgs { + fn offline_args(self) -> Self; + fn offline_args_config(self, config: &dyn ArgsConfig) -> Self; +} + +impl OfflineArgs for clap::Command<'_> { + fn offline_args_config(self, config: &dyn ArgsConfig) -> Self { + self.arg(config.blockhash_arg(blockhash_arg())) + .arg(config.sign_only_arg(sign_only_arg())) + .arg(config.signer_arg(signer_arg())) + .arg(config.dump_transaction_message_arg(dump_transaction_message())) + } + fn offline_args(self) -> Self { + struct NullArgsConfig {} + impl ArgsConfig for NullArgsConfig {} + self.offline_args_config(&NullArgsConfig {}) + } +} + pub static VALID_TOKEN_PROGRAM_IDS: [Pubkey; 2] = [spl_token_2022::ID, spl_token::ID]; #[derive(AsRefStr, Debug, Clone, Copy, PartialEq, EnumString, IntoStaticStr)] From f420049dbbfbceab1c7a25ccd198bd549561a295 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 10 Sep 2024 11:20:46 +0900 Subject: [PATCH 21/22] replace `value_of` function --- Cargo.lock | 2 +- token/cli/Cargo.toml | 2 +- token/cli/src/clap_app.rs | 7 +++--- token/cli/src/command.rs | 48 ++++++++++++++++++++++++++------------ token/cli/src/config.rs | 9 ++++--- token/cli/tests/command.rs | 3 ++- 6 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d2fec0ff77..2ff9d46cd05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7638,7 +7638,7 @@ dependencies = [ "serde_json", "serial_test", "solana-account-decoder", - "solana-clap-utils", + "solana-clap-v3-utils", "solana-cli-config", "solana-cli-output", "solana-client", diff --git a/token/cli/Cargo.toml b/token/cli/Cargo.toml index 49df368ccef..c2a5fbf21c3 100644 --- a/token/cli/Cargo.toml +++ b/token/cli/Cargo.toml @@ -20,7 +20,7 @@ serde = "1.0.209" serde_derive = "1.0.103" serde_json = "1.0.128" solana-account-decoder = "2.0.3" -solana-clap-utils = "2.0.3" +solana-clap-v3-utils = "2.0.3" solana-cli-config = "2.0.3" solana-cli-output = "2.0.3" solana-client = "2.0.3" diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index e30e4310332..db10548b517 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -825,7 +825,7 @@ pub fn app<'a>( .number_of_values(1) .conflicts_with("transfer_fee") .requires("transfer_fee_maximum_fee") - .validator(is_parsable::) + .value_parser(clap::value_parser!(u16)) .help( "Add transfer fee to the mint. \ The mint authority can set the fee.", @@ -839,7 +839,7 @@ pub fn app<'a>( .number_of_values(1) .conflicts_with("transfer_fee") .requires("transfer_fee_basis_points") - .validator(is_amount) + .value_parser(clap::value_parser!(f64)) .help( "Add a UI amount maximum transfer fee to the mint. \ The mint authority can set and collect fees" @@ -896,6 +896,7 @@ pub fn app<'a>( .takes_value(false) .help("Enables group member configurations in the mint. The mint authority must initialize the member."), ) + .arg(multisig_signer_arg()) .nonce_args(true) .arg(memo_arg()) ) @@ -1433,7 +1434,7 @@ pub fn app<'a>( .arg( Arg::with_name("expected_fee") .long("expected-fee") - .validator(|s| is_amount(s)) + .value_parser(clap::value_parser!(f64)) .value_name("TOKEN_AMOUNT") .takes_value(true) .help("Expected fee amount collected during the transfer"), diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index 37de23134a7..63a876631cf 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -17,7 +17,7 @@ use { UiAccountData, }, solana_clap_v3_utils::{ - input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, value_of}, + input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers}, keypair::signer_from_path, }, solana_cli_output::{ @@ -3533,11 +3533,12 @@ pub async fn process_command<'a>( ) }); - let tranfer_fee_basis_point = value_of::(arg_matches, "transfer_fee_basis_points"); - let transfer_fee_maximum_fee = value_of::(arg_matches, "transfer_fee_maximum_fee") - .map(|v| spl_token::ui_amount_to_amount(v, decimals)); - let transfer_fee = tranfer_fee_basis_point - .map(|v| (v, transfer_fee_maximum_fee.unwrap())) + let transfer_fee_basis_point = arg_matches.get_one::("transfer_fee_basis_points"); + let transfer_fee_maximum_fee = arg_matches + .get_one::("transfer_fee_maximum_fee") + .map(|v| spl_token::ui_amount_to_amount(*v, decimals)); + let transfer_fee = transfer_fee_basis_point + .map(|v| (*v, transfer_fee_maximum_fee.unwrap())) .or(transfer_fee); let (token_signer, token) = @@ -3660,7 +3661,9 @@ pub async fn process_command<'a>( _ => Field::Key(field.to_string()), }; let value = arg_matches.value_of("value").map(|v| v.to_string()); - let transfer_lamports = value_of::(arg_matches, TRANSFER_LAMPORTS_ARG.name); + let transfer_lamports = arg_matches + .get_one(TRANSFER_LAMPORTS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let bulk_signers = vec![authority_signer]; command_update_metadata( @@ -3766,7 +3769,10 @@ pub async fn process_command<'a>( .await } (CommandName::CreateMultisig, arg_matches) => { - let minimum_signers = value_of::(arg_matches, "minimum_signers").unwrap(); + let minimum_signers = arg_matches + .get_one("minimum_signers") + .map(|v: &String| v.parse::().unwrap()) + .unwrap(); let multisig_members = pubkeys_of_multiple_signers(arg_matches, "multisig_member", &mut wallet_manager) .unwrap_or_else(print_error_and_exit) @@ -3850,7 +3856,9 @@ pub async fn process_command<'a>( push_signer_with_dedup(owner_signer, &mut bulk_signers); } - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let fund_recipient = arg_matches.is_present("fund_recipient"); let allow_unfunded_recipient = arg_matches.is_present("allow_empty_recipient") || arg_matches.is_present("allow_unfunded_recipient"); @@ -3862,7 +3870,7 @@ pub async fn process_command<'a>( println_display(config, "recipient-is-ata-owner is now the default behavior. The option has been deprecated and will be removed in a future release.".to_string()); } let use_unchecked_instruction = arg_matches.is_present("use_unchecked_instruction"); - let expected_fee = value_of::(arg_matches, "expected_fee"); + let expected_fee = arg_matches.get_one::("expected_fee").copied(); let memo = value_t!(arg_matches, "memo", String).ok(); let transfer_hook_accounts = arg_matches.values_of("transfer_hook_account").map(|v| { v.into_iter() @@ -3906,7 +3914,9 @@ pub async fn process_command<'a>( let amount = parse_amount_or_all(arg_matches); let mint_address = pubkey_of_signer(arg_matches, MINT_ADDRESS_ARG.name, &mut wallet_manager).unwrap(); - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let use_unchecked_instruction = arg_matches.is_present("use_unchecked_instruction"); let memo = value_t!(arg_matches, "memo", String).ok(); command_burn( @@ -3933,7 +3943,9 @@ pub async fn process_command<'a>( .unwrap() .unwrap(); let amount = value_t_or_exit!(arg_matches, "amount", f64); - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let mint_info = config.get_mint_info(&token, mint_decimals).await?; let recipient = if let Some(address) = pubkey_of_signer(arg_matches, "recipient", &mut wallet_manager).unwrap() @@ -4058,7 +4070,9 @@ pub async fn process_command<'a>( .unwrap(); let mint_address = pubkey_of_signer(arg_matches, MINT_ADDRESS_ARG.name, &mut wallet_manager).unwrap(); - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let use_unchecked_instruction = arg_matches.is_present("use_unchecked_instruction"); command_approve( config, @@ -4395,7 +4409,9 @@ pub async fn process_command<'a>( let maximum_fee = value_t_or_exit!(arg_matches, "maximum_fee", f64); let (transfer_fee_authority_signer, transfer_fee_authority_pubkey) = config .signer_or_default(arg_matches, "transfer_fee_authority", &mut wallet_manager); - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let bulk_signers = vec![transfer_fee_authority_signer]; command_set_transfer_fee( @@ -4541,7 +4557,9 @@ pub async fn process_command<'a>( let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); - let mint_decimals = value_of::(arg_matches, MINT_DECIMALS_ARG.name); + let mint_decimals = arg_matches + .get_one(MINT_DECIMALS_ARG.name) + .map(|v: &String| v.parse::().unwrap()); let (instruction_type, elgamal_keypair, aes_key) = match c { CommandName::DepositConfidentialTokens => { diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 20cc258b826..97fd435a952 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -2,7 +2,7 @@ use { crate::clap_app::{Error, COMPUTE_UNIT_LIMIT_ARG, COMPUTE_UNIT_PRICE_ARG, MULTISIG_SIGNER_ARG}, clap::ArgMatches, solana_clap_v3_utils::{ - input_parsers::{pubkey_of_signer, value_of}, + input_parsers::pubkey_of_signer, input_validators::normalize_to_url_if_moniker, keypair::SignerFromPathConfig, nonce::{NONCE_ARG, NONCE_AUTHORITY_ARG}, @@ -103,7 +103,10 @@ impl<'a> Config<'a> { )); let sign_only = matches.is_present(SIGN_ONLY_ARG.name); let program_client: Arc> = if sign_only { - let blockhash = value_of(matches, BLOCKHASH_ARG.name).unwrap_or_default(); + let blockhash = matches + .get_one::(BLOCKHASH_ARG.name) + .copied() + .unwrap_or_default(); Arc::new(ProgramOfflineClient::new( blockhash, ProgramRpcClientSendTransaction, @@ -175,7 +178,7 @@ impl<'a> Config<'a> { let default_keypair = cli_config.keypair_path.clone(); let default_signer: Option> = { - if let Some(owner_path) = matches.value_of("owner") { + if let Some(owner_path) = matches.try_get_one::("owner").ok().flatten() { signer_from_path_with_config(matches, owner_path, "owner", wallet_manager, &config) .ok() } else { diff --git a/token/cli/tests/command.rs b/token/cli/tests/command.rs index 6b05c5b994b..58c6b035b62 100644 --- a/token/cli/tests/command.rs +++ b/token/cli/tests/command.rs @@ -517,9 +517,10 @@ async fn create_token_2022(test_validator: &TestValidator, payer: &Keypair) { &multisig_member_help, ) .get_matches_from(args); + let (_, matches) = app_matches.subcommand().unwrap(); let config = Config::new_with_clients_and_ws_url( - &app_matches, + matches, &mut wallet_manager, &mut bulk_signers, &mut multisigner_ids, From 6e7265df5b1d65713796a0a5c01246ccf81b7bf0 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 22 Oct 2024 13:09:58 +0900 Subject: [PATCH 22/22] revert direct parser for `is_amount` validation --- token/cli/src/clap_app.rs | 4 ++-- token/cli/src/command.rs | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index db10548b517..83183d88aa5 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -839,7 +839,7 @@ pub fn app<'a>( .number_of_values(1) .conflicts_with("transfer_fee") .requires("transfer_fee_basis_points") - .value_parser(clap::value_parser!(f64)) + .validator(|s| is_amount(s)) .help( "Add a UI amount maximum transfer fee to the mint. \ The mint authority can set and collect fees" @@ -1434,7 +1434,7 @@ pub fn app<'a>( .arg( Arg::with_name("expected_fee") .long("expected-fee") - .value_parser(clap::value_parser!(f64)) + .validator(|s| is_amount(s)) .value_name("TOKEN_AMOUNT") .takes_value(true) .help("Expected fee amount collected during the transfer"), diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index 63a876631cf..e30eb7eb2ab 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -3535,8 +3535,11 @@ pub async fn process_command<'a>( let transfer_fee_basis_point = arg_matches.get_one::("transfer_fee_basis_points"); let transfer_fee_maximum_fee = arg_matches - .get_one::("transfer_fee_maximum_fee") - .map(|v| spl_token::ui_amount_to_amount(*v, decimals)); + .get_one::("transfer_fee_maximum_fee") + .map(|str| { + let v = str.parse::().unwrap(); // inputs are validated so this is safe + spl_token::ui_amount_to_amount(v, decimals) + }); let transfer_fee = transfer_fee_basis_point .map(|v| (*v, transfer_fee_maximum_fee.unwrap())) .or(transfer_fee); @@ -3870,7 +3873,9 @@ pub async fn process_command<'a>( println_display(config, "recipient-is-ata-owner is now the default behavior. The option has been deprecated and will be removed in a future release.".to_string()); } let use_unchecked_instruction = arg_matches.is_present("use_unchecked_instruction"); - let expected_fee = arg_matches.get_one::("expected_fee").copied(); + let expected_fee = arg_matches + .get_one::("expected_fee") + .map(|str| str.parse::().unwrap()); // unwrap safe since inputs are validated let memo = value_t!(arg_matches, "memo", String).ok(); let transfer_hook_accounts = arg_matches.values_of("transfer_hook_account").map(|v| { v.into_iter()