diff --git a/token/cli/src/bench.rs b/token/cli/src/bench.rs index 209591cefdd..bd91f0d3e60 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::ArgMatches, - solana_clap_v3_utils::input_parsers::{pubkey_of_signer, Amount}, + solana_clap_v3_utils::input_parsers::{pubkey_of_signer, signer::SignerSource, Amount}, solana_client::{ nonblocking::rpc_client::RpcClient, rpc_client::RpcClient as BlockingRpcClient, tpu_client::TpuClient, tpu_client::TpuClientConfig, @@ -31,7 +31,7 @@ pub(crate) async fn bench_process_command( match matches.subcommand() { Some(("create-accounts", arg_matches)) => { - let token = pubkey_of_signer(arg_matches, "token", wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); let n = *arg_matches.get_one::("n").unwrap(); @@ -43,7 +43,7 @@ pub(crate) async fn bench_process_command( command_create_accounts(config, signers, &token, n, &owner).await?; } Some(("close-accounts", arg_matches)) => { - let token = pubkey_of_signer(arg_matches, "token", wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); let n = *arg_matches.get_one::("n").unwrap(); @@ -54,7 +54,7 @@ pub(crate) async fn bench_process_command( command_close_accounts(config, signers, &token, n, &owner).await?; } Some(("deposit-into", arg_matches)) => { - let token = pubkey_of_signer(arg_matches, "token", wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); let n = *arg_matches.get_one::("n").unwrap(); @@ -62,14 +62,14 @@ pub(crate) async fn bench_process_command( let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", wallet_manager); signers.push(owner_signer); - let from = pubkey_of_signer(arg_matches, "from", wallet_manager).unwrap(); + let from = SignerSource::try_get_pubkey(arg_matches, "from", wallet_manager).unwrap(); command_deposit_into_or_withdraw_from( config, signers, &token, n, &owner, ui_amount, from, true, ) .await?; } Some(("withdraw-from", arg_matches)) => { - let token = pubkey_of_signer(arg_matches, "token", wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", wallet_manager) .unwrap() .unwrap(); let n = *arg_matches.get_one::("n").unwrap(); @@ -77,7 +77,7 @@ pub(crate) async fn bench_process_command( let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", wallet_manager); signers.push(owner_signer); - let to = pubkey_of_signer(arg_matches, "to", wallet_manager).unwrap(); + let to = SignerSource::try_get_pubkey(arg_matches, "to", wallet_manager).unwrap(); command_deposit_into_or_withdraw_from( config, signers, &token, n, &owner, ui_amount, to, false, ) diff --git a/token/cli/src/clap_app.rs b/token/cli/src/clap_app.rs index 33aa0343728..1e3eab345bd 100644 --- a/token/cli/src/clap_app.rs +++ b/token/cli/src/clap_app.rs @@ -1,4 +1,5 @@ use { + crate::print_error_and_exit, clap::{ crate_description, crate_name, crate_version, App, AppSettings, Arg, ArgGroup, SubCommand, }, @@ -298,7 +299,7 @@ pub fn mint_address_arg<'a>() -> Arg<'a> { .long(MINT_ADDRESS_ARG.long) .takes_value(true) .value_name("MINT_ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .help(MINT_ADDRESS_ARG.help) } @@ -327,7 +328,7 @@ pub fn delegate_address_arg<'a>() -> Arg<'a> { .long(DELEGATE_ADDRESS_ARG.long) .takes_value(true) .value_name("DELEGATE_ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .help(DELEGATE_ADDRESS_ARG.help) } @@ -363,20 +364,12 @@ fn is_multisig_minimum_signers(string: &str) -> Result<(), String> { } } -fn is_valid_token_program_id(string: T) -> Result<(), String> -where - T: AsRef + fmt::Display, -{ - match is_pubkey(string.as_ref()) { - Ok(()) => { - let program_id = string.as_ref().parse::().unwrap(); - if VALID_TOKEN_PROGRAM_IDS.contains(&program_id) { - Ok(()) - } else { - Err(format!("Unrecognized token program id: {}", program_id)) - } - } - Err(e) => Err(e), +fn parse_token_program_id(arg: &str) -> Result { + let program_id = arg.parse::().unwrap_or_else(print_error_and_exit); + if VALID_TOKEN_PROGRAM_IDS.contains(&program_id) { + Ok(program_id) + } else { + Err(format!("Unrecognized token program id: {}", program_id)) } } @@ -460,7 +453,7 @@ impl BenchSubCommand for App<'_> { .about("Create multiple token accounts for benchmarking") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -483,7 +476,7 @@ impl BenchSubCommand for App<'_> { .about("Close multiple token accounts used for benchmarking") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -506,7 +499,7 @@ impl BenchSubCommand for App<'_> { .about("Deposit tokens into multiple accounts") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -534,7 +527,7 @@ impl BenchSubCommand for App<'_> { .arg( Arg::with_name("from") .long("from") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("SOURCE_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The source token account address [default: associated token account for --owner]") @@ -546,7 +539,7 @@ impl BenchSubCommand for App<'_> { .about("Withdraw tokens from multiple accounts") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -574,7 +567,7 @@ impl BenchSubCommand for App<'_> { .arg( Arg::with_name("to") .long("to") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The recipient token account address [default: associated token account for --owner]") @@ -636,7 +629,7 @@ pub fn app<'a>( .takes_value(true) .global(true) .conflicts_with("program_2022") - .validator(|s| is_valid_token_program_id(s)) + .value_parser(parse_token_program_id) .help("SPL Token program id"), ) .arg( @@ -699,7 +692,7 @@ pub fn app<'a>( .long("mint-authority") .alias("owner") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .help( "Specify the mint authority address. \ @@ -745,7 +738,7 @@ pub fn app<'a>( Arg::with_name("metadata_address") .long("metadata-address") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .conflicts_with("enable_metadata") .help( @@ -756,7 +749,7 @@ pub fn app<'a>( Arg::with_name("group_address") .long("group-address") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_pubkey().build()) .takes_value(true) .conflicts_with("enable_group") .help( @@ -767,7 +760,7 @@ pub fn app<'a>( Arg::with_name("member_address") .long("member-address") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_pubkey().build()) .takes_value(true) .conflicts_with("enable_member") .help( @@ -863,7 +856,7 @@ pub fn app<'a>( Arg::with_name("transfer_hook") .long("transfer-hook") .value_name("TRANSFER_HOOK_PROGRAM_ID") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .help("Enable the mint authority to set the transfer hook program for this mint"), ) @@ -897,7 +890,7 @@ pub fn app<'a>( .about("Set the interest rate for an interest-bearing token") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -927,7 +920,7 @@ pub fn app<'a>( .about("Set the transfer hook program id for a token") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -936,7 +929,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("new_program_id") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("NEW_PROGRAM_ID") .takes_value(true) .required_unless("disable") @@ -965,7 +958,7 @@ pub fn app<'a>( .about("Initialize metadata extension on a token mint") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1013,7 +1006,7 @@ pub fn app<'a>( Arg::with_name("update_authority") .long("update-authority") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .help( "Specify the update authority address. \ @@ -1026,7 +1019,7 @@ pub fn app<'a>( .about("Update metadata on a token mint that has the extension") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1073,7 +1066,7 @@ pub fn app<'a>( .about("Initialize group extension on a token mint") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1106,7 +1099,7 @@ pub fn app<'a>( Arg::with_name("update_authority") .long("update-authority") .value_name("ADDRESS") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .help( "Specify the update authority address. \ @@ -1119,7 +1112,7 @@ pub fn app<'a>( .about("Updates the maximum number of members for a group.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1152,7 +1145,7 @@ pub fn app<'a>( .about("Initialize group member extension on a token mint") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -1161,7 +1154,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("group_token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("GROUP_TOKEN_ADDRESS") .takes_value(true) .required(true) @@ -1199,7 +1192,7 @@ pub fn app<'a>( .about("Create a new token account") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1244,7 +1237,7 @@ pub fn app<'a>( .arg( Arg::with_name("multisig_member") .value_name("MULTISIG_MEMBER_PUBKEY") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .takes_value(true) .index(2) .required(true) @@ -1271,7 +1264,7 @@ pub fn app<'a>( .about("Authorize a new signing keypair to a token or token account") .arg( Arg::with_name("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -1292,7 +1285,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("new_authority") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("AUTHORITY_ADDRESS") .takes_value(true) .index(3) @@ -1333,7 +1326,7 @@ pub fn app<'a>( .about("Transfer tokens between accounts") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1351,7 +1344,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("recipient") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("RECIPIENT_WALLET_ADDRESS or RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(3) @@ -1362,7 +1355,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("from") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("SENDER_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("from") @@ -1463,7 +1456,7 @@ pub fn app<'a>( .about("Burn tokens from an account") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1497,7 +1490,7 @@ pub fn app<'a>( .about("Mint new tokens") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1515,7 +1508,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("recipient") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("recipient_owner") @@ -1526,7 +1519,7 @@ pub fn app<'a>( .arg( Arg::with_name("recipient_owner") .long("recipient-owner") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("RECIPIENT_WALLET_ADDRESS") .takes_value(true) .conflicts_with("recipient") @@ -1556,7 +1549,7 @@ pub fn app<'a>( .about("Freeze a token account") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1586,7 +1579,7 @@ pub fn app<'a>( .about("Thaw a token account") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1659,7 +1652,7 @@ pub fn app<'a>( .about("Unwrap a SOL token account") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1689,7 +1682,7 @@ pub fn app<'a>( .about("Approve a delegate for a token account") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1707,7 +1700,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("delegate") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("DELEGATE_TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(3) @@ -1727,7 +1720,7 @@ pub fn app<'a>( .about("Revoke a delegate's authority") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1746,7 +1739,7 @@ pub fn app<'a>( .about("Close a token account") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1778,7 +1771,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -1795,7 +1788,7 @@ pub fn app<'a>( .about("Close a token mint") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1856,7 +1849,7 @@ pub fn app<'a>( .about("Get token supply") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1869,7 +1862,7 @@ pub fn app<'a>( .about("List all token accounts by owner") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -1910,7 +1903,7 @@ pub fn app<'a>( .about("Get wallet address") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .long("token") @@ -1954,7 +1947,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("address") @@ -1968,7 +1961,7 @@ pub fn app<'a>( .setting(AppSettings::Hidden) .arg( Arg::with_name("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("MULTISIG_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -1981,7 +1974,7 @@ pub fn app<'a>( .about("Query details of an SPL Token mint, account, or multisig by address") .arg( Arg::with_name("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ADDRESS") .takes_value(true) .index(1) @@ -2013,7 +2006,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .long("address") @@ -2098,7 +2091,7 @@ pub fn app<'a>( .about("Updates default account state for the mint. Requires the default account state extension.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2136,7 +2129,7 @@ pub fn app<'a>( .about("Updates metadata pointer address for the mint. Requires the metadata pointer extension.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2146,7 +2139,7 @@ pub fn app<'a>( .arg( Arg::with_name("metadata_address") .index(2) - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_pubkey().build()) .value_name("METADATA_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2179,7 +2172,7 @@ pub fn app<'a>( .about("Updates group pointer address for the mint. Requires the group pointer extension.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2189,7 +2182,7 @@ pub fn app<'a>( .arg( Arg::with_name("group_address") .index(2) - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_pubkey().build()) .value_name("GROUP_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2222,7 +2215,7 @@ pub fn app<'a>( .about("Updates group member pointer address for the mint. Requires the group member pointer extension.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2232,7 +2225,7 @@ pub fn app<'a>( .arg( Arg::with_name("member_address") .index(2) - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_pubkey().build()) .value_name("MEMBER_ADDRESS") .takes_value(true) .required_unless("disable") @@ -2265,7 +2258,7 @@ pub fn app<'a>( .about("Withdraw withheld transfer fee tokens from mint and / or account(s)") .arg( Arg::with_name("account") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .index(1) @@ -2274,7 +2267,7 @@ pub fn app<'a>( ) .arg( Arg::with_name("source") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("ACCOUNT_ADDRESS") .takes_value(true) .multiple(true) @@ -2315,7 +2308,7 @@ pub fn app<'a>( .about("Set the transfer fee for a token with a configured transfer fee") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .required(true) @@ -2377,7 +2370,7 @@ pub fn app<'a>( .about("Update confidential transfer configuration for a token") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2437,7 +2430,7 @@ pub fn app<'a>( .about("Configure confidential transfers for token account") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2447,7 +2440,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2478,7 +2471,7 @@ pub fn app<'a>( for the first time, use `configure-confidential-transfer-account` instead.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2488,7 +2481,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2506,7 +2499,7 @@ pub fn app<'a>( .about("Disable confidential transfers for token account") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2516,7 +2509,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2534,7 +2527,7 @@ pub fn app<'a>( .about("Enable non-confidential transfers for token account.") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2544,7 +2537,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2562,7 +2555,7 @@ pub fn app<'a>( .about("Disable non-confidential transfers for token account") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2572,7 +2565,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .conflicts_with("token") @@ -2590,7 +2583,7 @@ pub fn app<'a>( .about("Deposit amounts for confidential transfers") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2609,7 +2602,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ @@ -2627,7 +2620,7 @@ pub fn app<'a>( .about("Withdraw amounts for confidential transfers") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2646,7 +2639,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ @@ -2664,7 +2657,7 @@ pub fn app<'a>( .about("Collect confidential tokens from pending to available balance") .arg( Arg::with_name("token") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) .index(1) @@ -2674,7 +2667,7 @@ pub fn app<'a>( .arg( Arg::with_name("address") .long("address") - .validator(|s| is_valid_pubkey(s)) + .value_parser(SignerSourceParserBuilder::default().allow_all().build()) .value_name("TOKEN_ACCOUNT_ADDRESS") .takes_value(true) .help("The address of the token account to configure confidential transfers for \ diff --git a/token/cli/src/command.rs b/token/cli/src/command.rs index 01bc2226d5b..d5b18af7225 100644 --- a/token/cli/src/command.rs +++ b/token/cli/src/command.rs @@ -18,7 +18,9 @@ use { UiAccountData, }, solana_clap_v3_utils::{ - input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, Amount}, + input_parsers::{ + pubkey_of_signer, pubkeys_of_multiple_signers, signer::SignerSource, Amount, + }, keypair::signer_from_path, }, solana_cli_output::{ @@ -3548,9 +3550,15 @@ pub async fn process_command<'a>( config.pubkey_or_default(arg_matches, "mint_authority", &mut wallet_manager)?; let memo = value_t!(arg_matches, "memo", String).ok(); let rate_bps = value_t!(arg_matches, "interest_rate", i16).ok(); - let metadata_address = value_t!(arg_matches, "metadata_address", Pubkey).ok(); - let group_address = value_t!(arg_matches, "group_address", Pubkey).ok(); - let member_address = value_t!(arg_matches, "member_address", Pubkey).ok(); + let metadata_address = + SignerSource::try_get_pubkey(arg_matches, "metadata_address", &mut wallet_manager) + .unwrap(); + let group_address = + SignerSource::try_get_pubkey(arg_matches, "group_address", &mut wallet_manager) + .unwrap(); + let member_address = + SignerSource::try_get_pubkey(arg_matches, "member_address", &mut wallet_manager) + .unwrap(); let transfer_fee = arg_matches.values_of("transfer_fee").map(|mut v| { println_display(config,"transfer-fee has been deprecated and will be removed in a future release. Please specify --transfer-fee-basis-points and --transfer-fee-maximum-fee with a UI amount".to_string()); @@ -3587,7 +3595,8 @@ pub async fn process_command<'a>( _ => unreachable!(), }); let transfer_hook_program_id = - pubkey_of_signer(arg_matches, "transfer_hook", &mut wallet_manager).unwrap(); + SignerSource::try_get_pubkey(arg_matches, "transfer_hook", &mut wallet_manager) + .unwrap(); let confidential_transfer_auto_approve = arg_matches .value_of("enable_confidential_transfers") @@ -3619,9 +3628,10 @@ pub async fn process_command<'a>( .await } (CommandName::SetInterestRate, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let rate_bps = value_t_or_exit!(arg_matches, "rate", i16); let (rate_authority_signer, rate_authority_pubkey) = config.signer_or_default(arg_matches, "rate_authority", &mut wallet_manager); @@ -3637,11 +3647,13 @@ pub async fn process_command<'a>( .await } (CommandName::SetTransferHook, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let new_program_id = - pubkey_of_signer(arg_matches, "new_program_id", &mut wallet_manager).unwrap(); + SignerSource::try_get_pubkey(arg_matches, "new_program_id", &mut wallet_manager) + .unwrap(); let (authority_signer, authority_pubkey) = config.signer_or_default(arg_matches, "authority", &mut wallet_manager); let bulk_signers = vec![authority_signer]; @@ -3656,9 +3668,10 @@ pub async fn process_command<'a>( .await } (CommandName::InitializeMetadata, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let name = arg_matches.value_of("name").unwrap().to_string(); let symbol = arg_matches.value_of("symbol").unwrap().to_string(); let uri = arg_matches.value_of("uri").unwrap().to_string(); @@ -3681,9 +3694,10 @@ pub async fn process_command<'a>( .await } (CommandName::UpdateMetadata, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let (authority_signer, authority) = config.signer_or_default(arg_matches, "authority", &mut wallet_manager); let field = arg_matches.value_of("field").unwrap(); @@ -3711,9 +3725,10 @@ pub async fn process_command<'a>( .await } (CommandName::InitializeGroup, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let max_size = *arg_matches.get_one::("max_size").unwrap(); let (mint_authority_signer, mint_authority) = config.signer_or_default(arg_matches, "mint_authority", &mut wallet_manager); @@ -3732,9 +3747,10 @@ pub async fn process_command<'a>( .await } (CommandName::UpdateGroupMaxSize, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let new_max_size = *arg_matches.get_one::("new_max_size").unwrap(); let (update_authority_signer, update_authority) = config.signer_or_default(arg_matches, "update_authority", &mut wallet_manager); @@ -3750,11 +3766,12 @@ pub async fn process_command<'a>( .await } (CommandName::InitializeMember, arg_matches) => { - let member_token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let member_token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let group_token_pubkey = - pubkey_of_signer(arg_matches, "group_token", &mut wallet_manager) + SignerSource::try_get_pubkey(arg_matches, "group_token", &mut wallet_manager) .unwrap() .unwrap(); let (mint_authority_signer, mint_authority) = @@ -3778,7 +3795,7 @@ pub async fn process_command<'a>( .await } (CommandName::CreateAccount, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); @@ -3807,9 +3824,9 @@ pub async fn process_command<'a>( .map(|v: &String| v.parse::().unwrap()) .unwrap(); let multisig_members = - pubkeys_of_multiple_signers(arg_matches, "multisig_member", &mut wallet_manager) + SignerSource::try_get_pubkeys(arg_matches, "multisig_member", &mut wallet_manager) .unwrap_or_else(print_error_and_exit) - .unwrap(); + .unwrap_or_default(); if minimum_signers as usize > multisig_members.len() { eprintln!( "error: MINIMUM_SIGNERS cannot be greater than the number \ @@ -3824,7 +3841,7 @@ pub async fn process_command<'a>( command_create_multisig(config, signer, minimum_signers, multisig_members).await } (CommandName::Authorize, arg_matches) => { - let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager) + let address = SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager) .unwrap() .unwrap(); let authority_type = arg_matches.value_of("authority_type").unwrap(); @@ -3837,7 +3854,8 @@ pub async fn process_command<'a>( } let new_authority = - pubkey_of_signer(arg_matches, "new_authority", &mut wallet_manager).unwrap(); + SignerSource::try_get_pubkey(arg_matches, "new_authority", &mut wallet_manager) + .unwrap(); let force_authorize = arg_matches.is_present("force"); command_authorize( config, @@ -3851,14 +3869,16 @@ pub async fn process_command<'a>( .await } (CommandName::Transfer, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); let amount = *arg_matches.get_one::("amount").unwrap(); - let recipient = pubkey_of_signer(arg_matches, "recipient", &mut wallet_manager) - .unwrap() - .unwrap(); - let sender = pubkey_of_signer(arg_matches, "from", &mut wallet_manager).unwrap(); + let recipient = + SignerSource::try_get_pubkey(arg_matches, "recipient", &mut wallet_manager) + .unwrap() + .unwrap(); + let sender = + SignerSource::try_get_pubkey(arg_matches, "from", &mut wallet_manager).unwrap(); let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); @@ -3932,7 +3952,7 @@ pub async fn process_command<'a>( .await } (CommandName::Burn, arg_matches) => { - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + let account = SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); @@ -3970,18 +3990,19 @@ pub async fn process_command<'a>( push_signer_with_dedup(mint_authority_signer, &mut bulk_signers); } - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); let amount = *arg_matches.get_one::("amount").unwrap(); let mint_decimals = arg_matches.get_one::(MINT_DECIMALS_ARG.name).copied(); 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() + SignerSource::try_get_pubkey(arg_matches, "recipient", &mut wallet_manager).unwrap() { address } else if let Some(address) = - pubkey_of_signer(arg_matches, "recipient_owner", &mut wallet_manager).unwrap() + SignerSource::try_get_pubkey(arg_matches, "recipient_owner", &mut wallet_manager) + .unwrap() { get_associated_token_address_with_program_id(&address, &token, &config.program_id) } else { @@ -4015,7 +4036,7 @@ pub async fn process_command<'a>( push_signer_with_dedup(freeze_authority_signer, &mut bulk_signers); } - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + let account = SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); let mint_address = @@ -4036,7 +4057,7 @@ pub async fn process_command<'a>( push_signer_with_dedup(freeze_authority_signer, &mut bulk_signers); } - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + let account = SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); let mint_address = @@ -4080,7 +4101,8 @@ pub async fn process_command<'a>( config.signer_or_default(arg_matches, "wallet_keypair", &mut wallet_manager); push_signer_with_dedup(wallet_signer, &mut bulk_signers); - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager).unwrap(); + let account = + SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager).unwrap(); command_unwrap(config, wallet_address, account, bulk_signers).await } (CommandName::Approve, arg_matches) => { @@ -4090,15 +4112,20 @@ pub async fn process_command<'a>( push_signer_with_dedup(owner_signer, &mut bulk_signers); } - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + let account = SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); let amount = *arg_matches.get_one::("amount").unwrap(); - let delegate = pubkey_of_signer(arg_matches, "delegate", &mut wallet_manager) - .unwrap() - .unwrap(); - let mint_address = - pubkey_of_signer(arg_matches, MINT_ADDRESS_ARG.name, &mut wallet_manager).unwrap(); + let delegate = + SignerSource::try_get_pubkey(arg_matches, "delegate", &mut wallet_manager) + .unwrap() + .unwrap(); + let mint_address = SignerSource::try_get_pubkey( + arg_matches, + MINT_ADDRESS_ARG.name, + &mut wallet_manager, + ) + .unwrap(); let mint_decimals = arg_matches .get_one(MINT_DECIMALS_ARG.name) .map(|v: &String| v.parse::().unwrap()); @@ -4123,7 +4150,7 @@ pub async fn process_command<'a>( push_signer_with_dedup(owner_signer, &mut bulk_signers); } - let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + let account = SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); let delegate_address = @@ -4153,7 +4180,7 @@ pub async fn process_command<'a>( command_close(config, address, close_authority, recipient, bulk_signers).await } (CommandName::CloseMint, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); let (close_authority_signer, close_authority) = @@ -4173,13 +4200,14 @@ pub async fn process_command<'a>( command_balance(config, address).await } (CommandName::Supply, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); command_supply(config, token).await } (CommandName::Accounts, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager).unwrap(); let owner = config.pubkey_or_default(arg_matches, "owner", &mut wallet_manager)?; let filter = if arg_matches.is_present("delegated") { AccountFilter::Delegated @@ -4199,7 +4227,8 @@ pub async fn process_command<'a>( .await } (CommandName::Address, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager).unwrap(); let owner = config.pubkey_or_default(arg_matches, "owner", &mut wallet_manager)?; command_address(config, token, owner).await } @@ -4210,13 +4239,13 @@ pub async fn process_command<'a>( command_display(config, address).await } (CommandName::MultisigInfo, arg_matches) => { - let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager) + let address = SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager) .unwrap() .unwrap(); command_display(config, address).await } (CommandName::Display, arg_matches) => { - let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager) + let address = SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager) .unwrap() .unwrap(); command_display(config, address).await @@ -4307,7 +4336,7 @@ pub async fn process_command<'a>( } (CommandName::UpdateDefaultAccountState, arg_matches) => { // Since account is required argument it will always be present - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); let (freeze_authority_signer, freeze_authority) = @@ -4332,7 +4361,7 @@ pub async fn process_command<'a>( } (CommandName::UpdateMetadataAddress, arg_matches) => { // Since account is required argument it will always be present - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); @@ -4341,7 +4370,9 @@ pub async fn process_command<'a>( if config.multisigner_pubkeys.is_empty() { push_signer_with_dedup(authority_signer, &mut bulk_signers); } - let metadata_address = value_t!(arg_matches, "metadata_address", Pubkey).ok(); + let metadata_address = + SignerSource::try_get_pubkey(arg_matches, "metadata_address", &mut wallet_manager) + .unwrap(); command_update_pointer_address( config, @@ -4355,7 +4386,7 @@ pub async fn process_command<'a>( } (CommandName::UpdateGroupAddress, arg_matches) => { // Since account is required argument it will always be present - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); @@ -4364,7 +4395,9 @@ pub async fn process_command<'a>( if config.multisigner_pubkeys.is_empty() { push_signer_with_dedup(authority_signer, &mut bulk_signers); } - let group_address = value_t!(arg_matches, "group_address", Pubkey).ok(); + let group_address = + SignerSource::try_get_pubkey(arg_matches, "group_address", &mut wallet_manager) + .unwrap(); command_update_pointer_address( config, @@ -4378,7 +4411,7 @@ pub async fn process_command<'a>( } (CommandName::UpdateMemberAddress, arg_matches) => { // Since account is required argument it will always be present - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); @@ -4387,7 +4420,9 @@ pub async fn process_command<'a>( if config.multisigner_pubkeys.is_empty() { push_signer_with_dedup(authority_signer, &mut bulk_signers); } - let member_address = value_t!(arg_matches, "member_address", Pubkey).ok(); + let member_address = + SignerSource::try_get_pubkey(arg_matches, "member_address", &mut wallet_manager) + .unwrap(); command_update_pointer_address( config, @@ -4410,15 +4445,14 @@ pub async fn process_command<'a>( } // Since destination is required it will always be present let destination_token_account = - pubkey_of_signer(arg_matches, "account", &mut wallet_manager) + SignerSource::try_get_pubkey(arg_matches, "account", &mut wallet_manager) .unwrap() .unwrap(); let include_mint = arg_matches.is_present("include_mint"); - let source_accounts = arg_matches - .values_of("source") - .unwrap_or_default() - .map(|s| Pubkey::from_str(s).unwrap_or_else(print_error_and_exit)) - .collect::>(); + let source_accounts = + SignerSource::try_get_pubkeys(arg_matches, "source", &mut wallet_manager) + .unwrap() + .unwrap_or_default(); command_withdraw_withheld_tokens( config, destination_token_account, @@ -4430,9 +4464,10 @@ pub async fn process_command<'a>( .await } (CommandName::SetTransferFee, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let transfer_fee_basis_points = value_t_or_exit!(arg_matches, "transfer_fee_basis_points", u16); let maximum_fee = *arg_matches.get_one::("maximum_fee").unwrap(); @@ -4467,9 +4502,10 @@ pub async fn process_command<'a>( .await } (CommandName::UpdateConfidentialTransferSettings, arg_matches) => { - let token_pubkey = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) - .unwrap() - .unwrap(); + let token_pubkey = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) + .unwrap() + .unwrap(); let auto_approve = arg_matches.value_of("approve_policy").map(|b| b == "auto"); @@ -4497,12 +4533,14 @@ pub async fn process_command<'a>( .await } (CommandName::ConfigureConfidentialTransferAccount, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager).unwrap(); let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); - let account = pubkey_of_signer(arg_matches, "address", &mut wallet_manager).unwrap(); + let account = + SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager).unwrap(); // Deriving ElGamal and AES key from signer. Custom ElGamal and AES keys will be // supported in the future once upgrading to clap-v3. @@ -4543,12 +4581,14 @@ pub async fn process_command<'a>( | (c @ CommandName::DisableConfidentialCredits, arg_matches) | (c @ CommandName::EnableNonConfidentialCredits, arg_matches) | (c @ CommandName::DisableNonConfidentialCredits, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager).unwrap(); let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); - let account = pubkey_of_signer(arg_matches, "address", &mut wallet_manager).unwrap(); + let account = + SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager).unwrap(); if config.multisigner_pubkeys.is_empty() { push_signer_with_dedup(owner_signer, &mut bulk_signers); @@ -4575,11 +4615,12 @@ pub async fn process_command<'a>( } (c @ CommandName::DepositConfidentialTokens, arg_matches) | (c @ CommandName::WithdrawConfidentialTokens, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager) + let token = SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager) .unwrap() .unwrap(); let amount = *arg_matches.get_one::("amount").unwrap(); - let account = pubkey_of_signer(arg_matches, "address", &mut wallet_manager).unwrap(); + let account = + SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager).unwrap(); let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); @@ -4627,12 +4668,14 @@ pub async fn process_command<'a>( .await } (CommandName::ApplyPendingBalance, arg_matches) => { - let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager).unwrap(); let (owner_signer, owner) = config.signer_or_default(arg_matches, "owner", &mut wallet_manager); - let account = pubkey_of_signer(arg_matches, "address", &mut wallet_manager).unwrap(); + let account = + SignerSource::try_get_pubkey(arg_matches, "address", &mut wallet_manager).unwrap(); // Deriving ElGamal and AES key from signer. Custom ElGamal and AES keys will be // supported in the future once upgrading to clap-v3. diff --git a/token/cli/src/config.rs b/token/cli/src/config.rs index 65c20dd5f76..72be7f30495 100644 --- a/token/cli/src/config.rs +++ b/token/cli/src/config.rs @@ -281,19 +281,17 @@ impl<'a> Config<'a> { .try_contains_id(DUMP_TRANSACTION_MESSAGE.name) .unwrap_or(false); - let pubkey_from_matches = |name| { - matches - .try_get_one::(name) + let mut pubkey_from_matches = |name| { + SignerSource::try_get_pubkey(matches, name, wallet_manager) .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) = pubkey_from_matches("program_id") { - (program_id, true) + } else if let Some(program_id) = matches.get_one::("program_id") { + (*program_id, true) } else if !sign_only { if let Some(address) = pubkey_from_matches("token") .or_else(|| pubkey_from_matches("account")) @@ -424,8 +422,9 @@ impl<'a> Config<'a> { wallet_manager: &mut Option>, token: Option, ) -> Result { - if let Some(address) = pubkey_of_signer(arg_matches, override_name, wallet_manager) - .map_err(|e| -> Error { e.to_string().into() })? + if let Some(address) = + SignerSource::try_get_pubkey(arg_matches, override_name, wallet_manager) + .map_err(|e| -> Error { e.to_string().into() })? { return Ok(address); }