From a5a34dc97629efa4d5926d7dd4c71e64811fb543 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:44:26 +0900 Subject: [PATCH 01/20] upgrade clap version to `3.2.23` --- Cargo.lock | 4 ++-- token/cli/Cargo.toml | 12 ++++++------ 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, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7cf21564ad5..d11c6b44ebd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7605,7 +7605,7 @@ version = "3.4.1" dependencies = [ "assert_cmd", "base64 0.22.0", - "clap 2.34.0", + "clap 3.2.25", "console", "futures 0.3.30", "libtest-mimic", @@ -7614,7 +7614,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 ee1a6197df4..bb674430cd0 100644 --- a/token/cli/Cargo.toml +++ b/token/cli/Cargo.toml @@ -13,14 +13,14 @@ walkdir = "2" [dependencies] base64 = "0.22.0" -clap = "2.33.3" +clap = "3.2.23" console = "0.15.8" futures = "0.3" serde = "1.0.198" serde_derive = "1.0.103" serde_json = "1.0.116" solana-account-decoder = ">=1.18.11,<=2" -solana-clap-utils = ">=1.18.11,<=2" +solana-clap-v3-utils = ">=1.18.11,<=2" solana-cli-config = ">=1.18.11,<=2" solana-cli-output = ">=1.18.11,<=2" solana-client = ">=1.18.11,<=2" @@ -29,19 +29,19 @@ solana-remote-wallet = ">=1.18.11,<=2" solana-sdk = ">=1.18.11,<=2" solana-transaction-status = ">=1.18.11,<=2" spl-token = { version = "4.0", path = "../program", features = [ - "no-entrypoint", + "no-entrypoint", ] } spl-token-2022 = { version = "3.0.2", path = "../program-2022", features = [ - "no-entrypoint", + "no-entrypoint", ] } spl-token-client = { version = "0.10.0", path = "../client" } spl-token-metadata-interface = { version = "0.3.3", path = "../../token-metadata/interface" } spl-token-group-interface = { version = "0.2.3", path = "../../token-group/interface" } spl-associated-token-account = { version = "3.0.2", path = "../../associated-token-account/program", features = [ - "no-entrypoint", + "no-entrypoint", ] } spl-memo = { version = "4.0", path = "../../memo/program", features = [ - "no-entrypoint", + "no-entrypoint", ] } strum = "0.26" strum_macros = "0.26" diff --git a/token/cli/src/bench.rs b/token/cli/src/bench.rs index 644cdc55333..dcde40ba786 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 b9817bff002..36ab5302bb7 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 ee675b4e853..4edd0789dc7 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -15,7 +15,7 @@ use { parse_token::{get_token_account_mint, parse_token, 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 89137a51b31..348a977a989 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 48f95be5361b8b0166ccb6394200442be7db05d4 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:55:29 +0900 Subject: [PATCH 02/20] 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 dcde40ba786..f879e7aae60 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 4edd0789dc7..a6784cc93a8 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -96,7 +96,7 @@ fn new_throwaway_signer() -> (Arc, Pubkey) { } fn get_signer( - matches: &ArgMatches<'_>, + matches: &ArgMatches, keypair_name: &str, wallet_manager: &mut Option>, ) -> Option<(Arc, Pubkey)> { @@ -108,7 +108,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()), @@ -3444,7 +3444,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 348a977a989..28ad58dcd2d 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, @@ -357,7 +357,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 { @@ -376,7 +376,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, @@ -408,7 +408,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 2aca375aab2f96d293d23cf82edb03efb57997ad Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:57:43 +0900 Subject: [PATCH 03/20] 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 36ab5302bb7..c39e4b9a379 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 02eb06706cba32809d3e11f6c2f5bb21d3439530 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 09:58:28 +0900 Subject: [PATCH 04/20] 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 c39e4b9a379..dfc69af0669 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 70e025aac5d3a25dc8c50fbaa615bfeeb08944ad Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:01:06 +0900 Subject: [PATCH 05/20] 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 dfc69af0669..a7155f71ce5 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) } @@ -1178,8 +1178,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( @@ -1368,7 +1368,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\".\ @@ -2207,7 +2207,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 1119b85f7c2148dc01a2e9a9dc34b6e4c1e25256 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:02:19 +0900 Subject: [PATCH 06/20] 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 a7155f71ce5..ee9aaecf8c7 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) @@ -593,7 +593,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) @@ -603,7 +603,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 ec3e909d32c4c51b647fbbbc608ba722d34d37a6 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:06:13 +0900 Subject: [PATCH 07/20] 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 ee9aaecf8c7..d34ef4a0cff 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 ac5d43ba5ba5815a8255448008af4453feb7956f Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:14:43 +0900 Subject: [PATCH 08/20] 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 f879e7aae60..8eca7e0e81b 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 f89d5b3d668..661b15c42c2 100644 --- a/token/cli/tests/command.rs +++ b/token/cli/tests/command.rs @@ -437,9 +437,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))]; @@ -457,9 +456,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 3ab988a8099165b3e26ced51854e070715dfdac2 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:38:01 +0900 Subject: [PATCH 09/20] 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 d34ef4a0cff..7f8c75248d9 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1212,7 +1212,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 814a29c4a25cd0e80412f35fa471c493341aee50 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:39:38 +0900 Subject: [PATCH 10/20] 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 7f8c75248d9..4138328218f 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 1dcc501778e81abc40edd366dab0e10ed1b4ee42 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 10:54:42 +0900 Subject: [PATCH 11/20] resolve lifetime specifier issue with higher order validator functions --- token/cli/src/clap_app.rs | 308 +++++++++++++++++++------------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 4138328218f..bf5f59068e9 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( @@ -600,7 +600,7 @@ pub fn app<'a, 'b>( .value_name("ADDRESS") .takes_value(true) .global(true) - .validator(is_valid_token_program_id) + .validator(|s| is_valid_token_program_id(s)) .help("SPL Token program id"), ) .arg( @@ -610,7 +610,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] \ @@ -649,7 +649,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( @@ -663,7 +663,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. \ @@ -709,7 +709,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( @@ -720,7 +720,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( @@ -731,7 +731,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( @@ -752,7 +752,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. \ @@ -783,7 +783,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 \ @@ -796,7 +796,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"), ) @@ -829,7 +829,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) @@ -845,7 +845,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( @@ -859,7 +859,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) @@ -868,7 +868,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") @@ -886,7 +886,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.") @@ -897,7 +897,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) @@ -933,7 +933,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. \ @@ -945,7 +945,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. \ @@ -958,7 +958,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) @@ -991,7 +991,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.") @@ -1005,7 +1005,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) @@ -1014,7 +1014,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) @@ -1026,7 +1026,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. \ @@ -1038,7 +1038,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. \ @@ -1051,7 +1051,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) @@ -1060,7 +1060,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) @@ -1071,7 +1071,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. \ @@ -1084,7 +1084,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) @@ -1093,7 +1093,7 @@ pub fn app<'a, 'b>( ) .arg( Arg::with_name("group_token") - .validator(is_valid_pubkey) + .validator(|s| is_valid_pubkey(s)) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1105,7 +1105,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. \ @@ -1117,7 +1117,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. \ @@ -1131,7 +1131,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) @@ -1141,7 +1141,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( @@ -1176,7 +1176,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) @@ -1188,7 +1188,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. \ @@ -1203,7 +1203,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) @@ -1214,7 +1214,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. \ @@ -1224,7 +1224,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) @@ -1236,7 +1236,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. \ @@ -1265,7 +1265,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) @@ -1274,7 +1274,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) @@ -1283,7 +1283,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) @@ -1294,7 +1294,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") @@ -1358,7 +1358,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"), @@ -1366,7 +1366,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) @@ -1395,7 +1395,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) @@ -1404,7 +1404,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) @@ -1429,7 +1429,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) @@ -1438,7 +1438,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) @@ -1447,7 +1447,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") @@ -1458,7 +1458,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") @@ -1469,7 +1469,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. \ @@ -1488,7 +1488,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) @@ -1500,7 +1500,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. \ @@ -1518,7 +1518,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) @@ -1530,7 +1530,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. \ @@ -1548,7 +1548,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) @@ -1559,7 +1559,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. \ @@ -1590,7 +1590,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) @@ -1601,7 +1601,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. \ @@ -1620,7 +1620,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) @@ -1629,7 +1629,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) @@ -1638,7 +1638,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) @@ -1658,7 +1658,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) @@ -1677,7 +1677,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) @@ -1688,7 +1688,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]"), @@ -1698,7 +1698,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, \ @@ -1710,7 +1710,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") @@ -1726,7 +1726,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) @@ -1736,7 +1736,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]"), @@ -1745,7 +1745,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. \ @@ -1763,7 +1763,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) @@ -1773,7 +1773,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") @@ -1787,7 +1787,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) @@ -1800,7 +1800,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) @@ -1841,7 +1841,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") @@ -1862,7 +1862,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) @@ -1875,7 +1875,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") @@ -1885,7 +1885,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") @@ -1899,7 +1899,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) @@ -1912,7 +1912,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) @@ -1944,7 +1944,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") @@ -1957,7 +1957,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) @@ -1975,7 +1975,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) @@ -1993,7 +1993,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) @@ -2011,7 +2011,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) @@ -2029,7 +2029,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) @@ -2040,7 +2040,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."), @@ -2049,7 +2049,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. \ @@ -2067,7 +2067,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) @@ -2077,7 +2077,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") @@ -2094,7 +2094,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. \ @@ -2110,7 +2110,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) @@ -2120,7 +2120,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") @@ -2137,7 +2137,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. \ @@ -2153,7 +2153,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) @@ -2163,7 +2163,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") @@ -2180,7 +2180,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. \ @@ -2196,7 +2196,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) @@ -2205,7 +2205,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) @@ -2223,7 +2223,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. \ @@ -2239,7 +2239,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) @@ -2255,7 +2255,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"), @@ -2263,7 +2263,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( @@ -2279,7 +2279,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) @@ -2287,7 +2287,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) @@ -2301,7 +2301,7 @@ pub fn app<'a, 'b>( .about("Update confidential transfer configuation 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) @@ -2313,7 +2313,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 \ @@ -2345,7 +2345,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( @@ -2362,7 +2362,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) @@ -2372,7 +2372,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") @@ -2404,7 +2404,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) @@ -2414,7 +2414,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") @@ -2433,7 +2433,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) @@ -2443,7 +2443,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") @@ -2462,7 +2462,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) @@ -2472,7 +2472,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") @@ -2491,7 +2491,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) @@ -2501,7 +2501,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") @@ -2520,7 +2520,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) @@ -2529,7 +2529,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) @@ -2539,7 +2539,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 \ @@ -2558,7 +2558,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) @@ -2567,7 +2567,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) @@ -2577,7 +2577,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 \ @@ -2596,7 +2596,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) @@ -2606,7 +2606,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 4ed62698b9f774e7019e2d3e3f325984176a4a62 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 11:06:15 +0900 Subject: [PATCH 12/20] 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 bf5f59068e9..5d2ebc8bd48 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1561,6 +1561,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. \ @@ -1603,6 +1604,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. \ @@ -2210,6 +2212,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 bbf982c6173f6fca2a384578d87f838ba1adcd3b Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 11:17:59 +0900 Subject: [PATCH 13/20] 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 5d2ebc8bd48..01523d1ad86 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1600,7 +1600,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) @@ -1698,7 +1697,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) @@ -2224,7 +2222,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 6ded6069c61627e4c442c179b5b605ca63c2f16e Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sat, 9 Mar 2024 16:32:08 +0900 Subject: [PATCH 14/20] 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 01523d1ad86..6dde9365073 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -2361,7 +2361,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) @@ -2403,7 +2402,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) @@ -2432,7 +2430,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) @@ -2461,7 +2458,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) @@ -2490,7 +2486,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) @@ -2519,7 +2514,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) @@ -2557,7 +2551,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) @@ -2595,7 +2588,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 73b4caf97623a6c232772200913f113122c42032 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 09:45:28 +0900 Subject: [PATCH 15/20] 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 28ad58dcd2d..e8fc5dbfcc3 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,17 +262,27 @@ 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 let Some(program_id) = value_of(matches, "program_id") { + 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 @@ -289,7 +305,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, ), @@ -298,7 +314,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) @@ -309,6 +330,7 @@ impl<'a> Config<'a> { ComputeUnitLimit::Simulated } }); + Self { default_signer, rpc_client, From 18336eca0f074c22c249be32a0fcc4df41883c10 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 09:45:36 +0900 Subject: [PATCH 16/20] 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 e8fc5dbfcc3..f29690978f7 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::*, spl_token_2022::{ @@ -559,3 +559,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 b48c1551ef5103368fadb9b97aaa17c098cff2c8 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Mon, 11 Mar 2024 10:58:57 +0900 Subject: [PATCH 17/20] 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 f29690978f7..f5f6ed52379 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -560,12 +560,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 b84bb8b665941f7236ea1e4c0a92c232a76e4bd4 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 12 Mar 2024 07:18:24 +0900 Subject: [PATCH 18/20] 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 c3760448e35f0bdf31066727608fc20138cd2778 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Fri, 29 Mar 2024 17:35:39 +0900 Subject: [PATCH 19/20] 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 f5f6ed52379..e5726e4076e 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -299,10 +299,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!( @@ -320,8 +323,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 07450df419631a126e34b2d26ad37f9a69cb0ab5 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 28 Apr 2024 16:29:57 +0900 Subject: [PATCH 20/20] 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 6dde9365073..92a945bd135 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)]