From 422502defcffded6645f8eeafa0da3581b8b3051 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 30 Jun 2024 12:31:43 +0900 Subject: [PATCH 1/6] repalce `Arg::with_name` to `Arg::new` --- token/transfer-hook/cli/Cargo.toml | 2 +- token/transfer-hook/cli/src/main.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/token/transfer-hook/cli/Cargo.toml b/token/transfer-hook/cli/Cargo.toml index 60906352aa3..292b37f51ed 100644 --- a/token/transfer-hook/cli/Cargo.toml +++ b/token/transfer-hook/cli/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/solana-labs/solana-program-library" version = "0.2.0" [dependencies] -clap = { version = "3", features = ["cargo"] } +clap = { version = "3", features = ["cargo", "deprecated"] } futures-util = "0.3.30" solana-clap-v3-utils = "2.0.0" solana-cli-config = "2.0.0" diff --git a/token/transfer-hook/cli/src/main.rs b/token/transfer-hook/cli/src/main.rs index 5566fe7266a..6c7335e3611 100644 --- a/token/transfer-hook/cli/src/main.rs +++ b/token/transfer-hook/cli/src/main.rs @@ -233,7 +233,7 @@ async fn main() -> Result<(), Box> { Command::new("create-extra-metas") .about("Create the extra account metas account for a transfer hook program") .arg( - Arg::with_name("program_id") + Arg::new("program_id") .value_parser(SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()) .value_name("TRANSFER_HOOK_PROGRAM") .takes_value(true) @@ -242,7 +242,7 @@ async fn main() -> Result<(), Box> { .help("The transfer hook program id"), ) .arg( - Arg::with_name("token") + Arg::new("token") .value_parser(SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -251,7 +251,7 @@ async fn main() -> Result<(), Box> { .help("The token mint address for the transfer hook"), ) .arg( - Arg::with_name("transfer_hook_accounts") + Arg::new("transfer_hook_accounts") .value_parser(parse_transfer_hook_account_arg) .value_name("TRANSFER_HOOK_ACCOUNTS") .takes_value(true) @@ -317,7 +317,7 @@ extraMetas: Command::new("update-extra-metas") .about("Update the extra account metas account for a transfer hook program") .arg( - Arg::with_name("program_id") + Arg::new("program_id") .value_parser(SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()) .value_name("TRANSFER_HOOK_PROGRAM") .takes_value(true) @@ -326,7 +326,7 @@ extraMetas: .help("The transfer hook program id"), ) .arg( - Arg::with_name("token") + Arg::new("token") .value_parser(SignerSourceParserBuilder::default().allow_pubkey().allow_file_path().build()) .value_name("TOKEN_MINT_ADDRESS") .takes_value(true) @@ -335,7 +335,7 @@ extraMetas: .help("The token mint address for the transfer hook"), ) .arg( - Arg::with_name("transfer_hook_accounts") + Arg::new("transfer_hook_accounts") .value_parser(parse_transfer_hook_account_arg) .value_name("TRANSFER_HOOK_ACCOUNTS") .takes_value(true) From 6b86ef10d8d019b701f105620988e8480f4b6355 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 30 Jun 2024 12:32:52 +0900 Subject: [PATCH 2/6] repalce `multiple` with `ArgAction::Append` --- token/transfer-hook/cli/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/token/transfer-hook/cli/src/main.rs b/token/transfer-hook/cli/src/main.rs index 6c7335e3611..d44e22ed4da 100644 --- a/token/transfer-hook/cli/src/main.rs +++ b/token/transfer-hook/cli/src/main.rs @@ -2,7 +2,7 @@ pub mod meta; use { crate::meta::parse_transfer_hook_account_arg, - clap::{crate_description, crate_name, crate_version, Arg, Command}, + clap::{crate_description, crate_name, crate_version, Arg, ArgAction, Command}, solana_clap_v3_utils::{ input_parsers::{ parse_url_or_moniker, @@ -255,7 +255,7 @@ async fn main() -> Result<(), Box> { .value_parser(parse_transfer_hook_account_arg) .value_name("TRANSFER_HOOK_ACCOUNTS") .takes_value(true) - .multiple(true) + .action(ArgAction::Append) .min_values(0) .index(3) .help(r#"Additional account(s) required for a transfer hook and their respective configurations, whether they are a fixed address or PDA. @@ -339,7 +339,7 @@ extraMetas: .value_parser(parse_transfer_hook_account_arg) .value_name("TRANSFER_HOOK_ACCOUNTS") .takes_value(true) - .multiple(true) + .action(ArgAction::Append) .min_values(0) .index(3) .help(r#"Additional account(s) required for a transfer hook and their respective configurations, whether they are a fixed address or PDA. From bb7f194a38cba6e0d102220bab7a47934bc51456 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 30 Jun 2024 12:33:34 +0900 Subject: [PATCH 3/6] replace `is_present` with `try_contains_id` --- token/transfer-hook/cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token/transfer-hook/cli/src/main.rs b/token/transfer-hook/cli/src/main.rs index d44e22ed4da..011ca8a06b7 100644 --- a/token/transfer-hook/cli/src/main.rs +++ b/token/transfer-hook/cli/src/main.rs @@ -431,7 +431,7 @@ extraMetas: exit(1); }), json_rpc_url, - verbose: matches.is_present("verbose"), + verbose: matches.try_contains_id("verbose")?, } }; solana_logger::setup_with_default("solana=info"); From 9020a176152f2154d6d3702aea60d6c0369f176f Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 30 Jun 2024 13:21:20 +0900 Subject: [PATCH 4/6] remove deprecated `value_of` --- token/transfer-hook/cli/src/main.rs | 80 ++++++++++++++--------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/token/transfer-hook/cli/src/main.rs b/token/transfer-hook/cli/src/main.rs index 011ca8a06b7..a24c01af98f 100644 --- a/token/transfer-hook/cli/src/main.rs +++ b/token/transfer-hook/cli/src/main.rs @@ -9,7 +9,7 @@ use { signer::{SignerSource, SignerSourceParserBuilder}, }, input_validators::normalize_to_url_if_moniker, - keypair::{pubkey_from_source, DefaultSigner}, + keypair::{pubkey_from_source, signer_from_path}, }, solana_client::nonblocking::rpc_client::RpcClient, solana_remote_wallet::remote_wallet::RemoteWalletManager, @@ -401,35 +401,35 @@ extraMetas: let (command, matches) = app_matches.subcommand().unwrap(); let mut wallet_manager: Option> = None; - let cli_config = if let Some(config_file) = matches.value_of("config_file") { + let cli_config = if let Some(config_file) = matches.get_one::("config_file") { solana_cli_config::Config::load(config_file).unwrap_or_default() } else { solana_cli_config::Config::default() }; let config = { - let default_signer = DefaultSigner::new( - "fee_payer", - matches - .value_of("fee_payer") - .map(|s| s.to_string()) - .unwrap_or_else(|| cli_config.keypair_path.clone()), - ); + let default_signer = if let Some((signer, _)) = + SignerSource::try_get_signer(matches, "fee_payer", &mut wallet_manager)? + { + signer + } else { + signer_from_path( + matches, + &cli_config.keypair_path, + "fee_payer", + &mut wallet_manager, + )? + }; let json_rpc_url = normalize_to_url_if_moniker( matches - .value_of("json_rpc_url") + .get_one::("json_rpc_url") .unwrap_or(&cli_config.json_rpc_url), ); Config { commitment_config: CommitmentConfig::confirmed(), - default_signer: default_signer - .signer_from_path(matches, &mut wallet_manager) - .unwrap_or_else(|err| { - eprintln!("error: {err}"); - exit(1); - }), + default_signer, json_rpc_url, verbose: matches.try_contains_id("verbose")?, } @@ -465,18 +465,18 @@ extraMetas: .flatten() .cloned() .collect(); - let mint_authority = DefaultSigner::new( - "mint_authority", - matches - .value_of("mint_authority") - .map(|s| s.to_string()) - .unwrap_or_else(|| cli_config.keypair_path.clone()), - ) - .signer_from_path(matches, &mut wallet_manager) - .unwrap_or_else(|err| { - eprintln!("error: {err}"); - exit(1); - }); + let mint_authority = if let Some((signer, _)) = + SignerSource::try_get_signer(matches, "mint_authority", &mut wallet_manager)? + { + signer + } else { + signer_from_path( + matches, + &cli_config.keypair_path, + "mint_authority", + &mut wallet_manager, + )? + }; let signature = process_create_extra_account_metas( &rpc_client, &program_id, @@ -514,18 +514,18 @@ extraMetas: .flatten() .cloned() .collect(); - let mint_authority = DefaultSigner::new( - "mint_authority", - matches - .value_of("mint_authority") - .map(|s| s.to_string()) - .unwrap_or_else(|| cli_config.keypair_path.clone()), - ) - .signer_from_path(matches, &mut wallet_manager) - .unwrap_or_else(|err| { - eprintln!("error: {err}"); - exit(1); - }); + let mint_authority = if let Some((signer, _)) = + SignerSource::try_get_signer(matches, "mint_authority", &mut wallet_manager)? + { + signer + } else { + signer_from_path( + matches, + &cli_config.keypair_path, + "mint_authority", + &mut wallet_manager, + )? + }; let signature = process_update_extra_account_metas( &rpc_client, &program_id, From 9903451e9e4cf63e993640093acaf8ff3cbf5303 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Sun, 30 Jun 2024 13:22:28 +0900 Subject: [PATCH 5/6] remove `deprecated` feature --- token/transfer-hook/cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token/transfer-hook/cli/Cargo.toml b/token/transfer-hook/cli/Cargo.toml index 292b37f51ed..60906352aa3 100644 --- a/token/transfer-hook/cli/Cargo.toml +++ b/token/transfer-hook/cli/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/solana-labs/solana-program-library" version = "0.2.0" [dependencies] -clap = { version = "3", features = ["cargo", "deprecated"] } +clap = { version = "3", features = ["cargo"] } futures-util = "0.3.30" solana-clap-v3-utils = "2.0.0" solana-cli-config = "2.0.0" From 281c0b2cae90e8be98fa294fb34255af397737b0 Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 2 Jul 2024 12:45:36 +0900 Subject: [PATCH 6/6] use `SignerSource::try_get_pubkey` to simplify pubkey parsing logic --- token/transfer-hook/cli/src/main.rs | 40 ++++++++--------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/token/transfer-hook/cli/src/main.rs b/token/transfer-hook/cli/src/main.rs index a24c01af98f..bf7273b1766 100644 --- a/token/transfer-hook/cli/src/main.rs +++ b/token/transfer-hook/cli/src/main.rs @@ -9,7 +9,7 @@ use { signer::{SignerSource, SignerSourceParserBuilder}, }, input_validators::normalize_to_url_if_moniker, - keypair::{pubkey_from_source, signer_from_path}, + keypair::signer_from_path, }, solana_client::nonblocking::rpc_client::RpcClient, solana_remote_wallet::remote_wallet::RemoteWalletManager, @@ -444,20 +444,11 @@ extraMetas: match (command, matches) { ("create-extra-metas", arg_matches) => { - let program_id_source = arg_matches - .try_get_one::("program_id")? - .unwrap(); - let program_id = pubkey_from_source( - arg_matches, - program_id_source, - "program_id", - &mut wallet_manager, - ) - .unwrap(); - - let token_source = arg_matches.try_get_one::("token")?.unwrap(); - let token = pubkey_from_source(arg_matches, token_source, "token", &mut wallet_manager) - .unwrap(); + let program_id = + SignerSource::try_get_pubkey(arg_matches, "program_id", &mut wallet_manager)? + .unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager)?.unwrap(); let transfer_hook_accounts = arg_matches .get_many::>("transfer_hook_accounts") @@ -493,20 +484,11 @@ extraMetas: println!("Signature: {signature}"); } ("update-extra-metas", arg_matches) => { - let program_id_source = arg_matches - .try_get_one::("program_id")? - .unwrap(); - let program_id = pubkey_from_source( - arg_matches, - program_id_source, - "program_id", - &mut wallet_manager, - ) - .unwrap(); - - let token_source = arg_matches.try_get_one::("token")?.unwrap(); - let token = pubkey_from_source(arg_matches, token_source, "token", &mut wallet_manager) - .unwrap(); + let program_id = + SignerSource::try_get_pubkey(arg_matches, "program_id", &mut wallet_manager)? + .unwrap(); + let token = + SignerSource::try_get_pubkey(arg_matches, "token", &mut wallet_manager)?.unwrap(); let transfer_hook_accounts = arg_matches .get_many::>("transfer_hook_accounts")