Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 7d24772

Browse files
[token-upgrade] Remove clap deprecated functions (#6951)
* replace `multiple` with `ArgAction::Append` * replace `is_present` with `try_contains_id` * replace `value_of` function * remove `deprecated` feature * replace `try_pubkey_of` with `SignerSource::try_get_pubkey`
1 parent 8593a5b commit 7d24772

File tree

1 file changed

+62
-64
lines changed

1 file changed

+62
-64
lines changed

token-upgrade/cli/src/main.rs

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use {
2-
clap::{crate_description, crate_name, crate_version, Arg, Command},
2+
clap::{crate_description, crate_name, crate_version, Arg, ArgAction, Command},
33
solana_clap_v3_utils::{
44
input_parsers::{
55
parse_url_or_moniker,
6-
signer::{try_pubkey_of, SignerSourceParserBuilder},
6+
signer::{SignerSource, SignerSourceParserBuilder},
77
},
88
input_validators::normalize_to_url_if_moniker,
9-
keypair::{
10-
signer_from_path, signer_from_path_with_config, DefaultSigner, SignerFromPathConfig,
11-
},
9+
keypair::{signer_from_path, signer_from_source, SignerFromPathConfig},
1210
},
1311
solana_client::nonblocking::rpc_client::RpcClient,
1412
solana_remote_wallet::remote_wallet::RemoteWalletManager,
@@ -336,7 +334,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
336334
.value_parser(SignerSourceParserBuilder::default().allow_all().build())
337335
.value_name("MULTISIG_SIGNER")
338336
.takes_value(true)
339-
.multiple(true)
337+
.action(ArgAction::Append)
340338
.min_values(0)
341339
.max_values(spl_token_2022::instruction::MAX_SIGNERS)
342340
.help("Member signer of a multisig account")
@@ -348,19 +346,24 @@ async fn main() -> Result<(), Box<dyn Error>> {
348346
let mut wallet_manager: Option<Rc<RemoteWalletManager>> = None;
349347

350348
let config = {
351-
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
349+
let cli_config = if let Some(config_file) = matches.try_get_one::<String>("config_file")? {
352350
solana_cli_config::Config::load(config_file).unwrap_or_default()
353351
} else {
354352
solana_cli_config::Config::default()
355353
};
356354

357-
let payer = DefaultSigner::new(
358-
"payer",
359-
matches
360-
.value_of("payer")
361-
.map(|s| s.to_string())
362-
.unwrap_or_else(|| cli_config.keypair_path.clone()),
363-
);
355+
let payer = if let Ok(Some((signer, _))) =
356+
SignerSource::try_get_signer(matches, "payer", &mut wallet_manager)
357+
{
358+
Box::new(signer)
359+
} else {
360+
signer_from_path(
361+
matches,
362+
&cli_config.keypair_path,
363+
"payer",
364+
&mut wallet_manager,
365+
)?
366+
};
364367

365368
let json_rpc_url = normalize_to_url_if_moniker(
366369
matches
@@ -370,16 +373,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
370373

371374
Config {
372375
commitment_config: CommitmentConfig::confirmed(),
373-
payer: Arc::from(
374-
payer
375-
.signer_from_path(matches, &mut wallet_manager)
376-
.unwrap_or_else(|err| {
377-
eprintln!("error: {}", err);
378-
exit(1);
379-
}),
380-
),
376+
payer: Arc::from(payer),
381377
json_rpc_url,
382-
verbose: matches.is_present("verbose"),
378+
verbose: matches.try_contains_id("verbose")?,
383379
}
384380
};
385381
solana_logger::setup_with_default("solana=info");
@@ -394,17 +390,17 @@ async fn main() -> Result<(), Box<dyn Error>> {
394390

395391
match (command, matches) {
396392
("create-escrow", arg_matches) => {
397-
let original_mint = try_pubkey_of(arg_matches, "original_mint")
398-
.unwrap()
399-
.unwrap();
400-
let new_mint = try_pubkey_of(arg_matches, "new_mint").unwrap().unwrap();
401-
let account_keypair = matches.value_of("account_keypair").map(|path| {
402-
signer_from_path(arg_matches, path, "account_keypair", &mut wallet_manager)
403-
.unwrap_or_else(|err| {
404-
eprintln!("error: account keypair: {}", err);
405-
exit(1);
406-
})
407-
});
393+
let original_mint =
394+
SignerSource::try_get_pubkey(arg_matches, "original_mint", &mut wallet_manager)
395+
.unwrap()
396+
.unwrap();
397+
let new_mint =
398+
SignerSource::try_get_pubkey(arg_matches, "new_mint", &mut wallet_manager)
399+
.unwrap()
400+
.unwrap();
401+
let account_keypair =
402+
SignerSource::try_get_signer(matches, "account_keypair", &mut wallet_manager)?
403+
.map(|(signer, _)| signer);
408404
let response = process_create_escrow_account(
409405
&rpc_client,
410406
&config.payer,
@@ -422,14 +418,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
422418
("exchange", arg_matches) => {
423419
let mut bulk_signers = vec![config.payer.clone()];
424420
let mut multisig_pubkeys = vec![];
425-
if let Some(values) = arg_matches.values_of("multisig_signer") {
426-
for (i, value) in values.enumerate() {
421+
422+
if let Some(sources) = arg_matches.try_get_many::<SignerSource>("multisig_signer")? {
423+
for (i, source) in sources.enumerate() {
427424
let name = format!("{}-{}", "multisig_signer", i.saturating_add(1));
428-
let signer = signer_from_path(arg_matches, value, &name, &mut wallet_manager)
429-
.unwrap_or_else(|e| {
430-
eprintln!("error parsing multisig signer: {}", e);
431-
exit(1);
432-
});
425+
let signer =
426+
signer_from_source(arg_matches, source, &name, &mut wallet_manager)
427+
.unwrap_or_else(|e| {
428+
eprint!("error parsing multisig signer: {}", e);
429+
exit(1);
430+
});
433431
let signer_pubkey = signer.pubkey();
434432
let signer = Arc::from(signer);
435433
if !bulk_signers.contains(&signer) {
@@ -441,35 +439,35 @@ async fn main() -> Result<(), Box<dyn Error>> {
441439
}
442440
}
443441

444-
let original_mint = try_pubkey_of(arg_matches, "original_mint")
445-
.unwrap()
446-
.unwrap();
447-
let new_mint = try_pubkey_of(arg_matches, "new_mint").unwrap().unwrap();
442+
let original_mint =
443+
SignerSource::try_get_pubkey(arg_matches, "original_mint", &mut wallet_manager)
444+
.unwrap()
445+
.unwrap();
446+
let new_mint =
447+
SignerSource::try_get_pubkey(arg_matches, "new_mint", &mut wallet_manager)
448+
.unwrap()
449+
.unwrap();
448450
let signer_config = SignerFromPathConfig {
449451
allow_null_signer: !multisig_pubkeys.is_empty(),
450452
};
451-
let owner = matches
452-
.value_of("owner")
453-
.map_or(Ok(config.payer.clone()), |path| {
454-
signer_from_path_with_config(
455-
arg_matches,
456-
path,
457-
"owner",
458-
&mut wallet_manager,
459-
&signer_config,
460-
)
461-
.map(Arc::from)
462-
})
463-
.unwrap_or_else(|err| {
464-
eprintln!("error: owner signer: {}", err);
465-
exit(1);
466-
});
453+
let owner = if let Ok(Some((signer, _))) =
454+
SignerSource::try_get_signer(matches, "owner", &mut wallet_manager)
455+
{
456+
Arc::from(signer)
457+
} else {
458+
config.payer.clone()
459+
};
467460
if !signer_config.allow_null_signer && !bulk_signers.contains(&owner) {
468461
bulk_signers.push(owner.clone());
469462
}
470-
let burn_from = try_pubkey_of(arg_matches, "burn_from").unwrap();
471-
let escrow = try_pubkey_of(arg_matches, "escrow").unwrap();
472-
let destination = try_pubkey_of(arg_matches, "destination").unwrap();
463+
let burn_from =
464+
SignerSource::try_get_pubkey(arg_matches, "burn_from", &mut wallet_manager)
465+
.unwrap();
466+
let escrow =
467+
SignerSource::try_get_pubkey(arg_matches, "escrow", &mut wallet_manager).unwrap();
468+
let destination =
469+
SignerSource::try_get_pubkey(arg_matches, "destination", &mut wallet_manager)
470+
.unwrap();
473471

474472
let signature = process_exchange(
475473
&rpc_client,

0 commit comments

Comments
 (0)