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

Commit 288ded3

Browse files
committed
replace is_amount with parser
1 parent acf64e2 commit 288ded3

File tree

3 files changed

+98
-57
lines changed

3 files changed

+98
-57
lines changed

token/cli/src/bench.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use {
33
crate::{clap_app::Error, command::CommandResult, config::Config},
44
clap::{value_t_or_exit, ArgMatches},
5-
solana_clap_v3_utils::input_parsers::pubkey_of_signer,
5+
solana_clap_v3_utils::input_parsers::{pubkey_of_signer, Amount},
66
solana_client::{
77
nonblocking::rpc_client::RpcClient, rpc_client::RpcClient as BlockingRpcClient,
88
tpu_client::TpuClient, tpu_client::TpuClientConfig,
@@ -58,7 +58,7 @@ pub(crate) async fn bench_process_command(
5858
.unwrap()
5959
.unwrap();
6060
let n = value_t_or_exit!(arg_matches, "n", usize);
61-
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
61+
let ui_amount = *arg_matches.get_one::<Amount>("amount").unwrap();
6262
let (owner_signer, owner) =
6363
config.signer_or_default(arg_matches, "owner", wallet_manager);
6464
signers.push(owner_signer);
@@ -73,7 +73,7 @@ pub(crate) async fn bench_process_command(
7373
.unwrap()
7474
.unwrap();
7575
let n = value_t_or_exit!(arg_matches, "n", usize);
76-
let ui_amount = value_t_or_exit!(arg_matches, "amount", f64);
76+
let ui_amount = *arg_matches.get_one::<Amount>("amount").unwrap();
7777
let (owner_signer, owner) =
7878
config.signer_or_default(arg_matches, "owner", wallet_manager);
7979
signers.push(owner_signer);
@@ -237,7 +237,7 @@ async fn command_deposit_into_or_withdraw_from(
237237
token: &Pubkey,
238238
n: usize,
239239
owner: &Pubkey,
240-
ui_amount: f64,
240+
ui_amount: Amount,
241241
from_or_to: Option<Pubkey>,
242242
deposit_into: bool,
243243
) -> Result<(), Error> {
@@ -250,7 +250,17 @@ async fn command_deposit_into_or_withdraw_from(
250250
let from_or_to = from_or_to
251251
.unwrap_or_else(|| get_associated_token_address_with_program_id(owner, token, &program_id));
252252
config.check_account(&from_or_to, Some(*token)).await?;
253-
let amount = spl_token::ui_amount_to_amount(ui_amount, mint_info.decimals);
253+
let amount = match ui_amount {
254+
Amount::Raw(ui_amount) => ui_amount,
255+
Amount::Decimal(ui_amount) => spl_token::ui_amount_to_amount(ui_amount, mint_info.decimals),
256+
Amount::All => {
257+
return Err(
258+
"Use of ALL keyword currently not supported for the bench command"
259+
.to_string()
260+
.into(),
261+
);
262+
}
263+
};
254264

255265
let token_addresses_with_seed = get_token_addresses_with_seed(&program_id, token, owner, n);
256266
let mut messages = vec![];

token/cli/src/clap_app.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
fee_payer::fee_payer_arg,
77
input_parsers::Amount,
88
input_validators::{
9-
is_amount, is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey, is_valid_signer,
9+
is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey, is_valid_signer,
1010
},
1111
memo::memo_arg,
1212
nonce::*,
@@ -338,7 +338,7 @@ pub fn transfer_lamports_arg<'a>() -> Arg<'a> {
338338
.long(TRANSFER_LAMPORTS_ARG.long)
339339
.takes_value(true)
340340
.value_name("LAMPORTS")
341-
.validator(|s| is_amount(s))
341+
.value_parser(clap::value_parser!(u64))
342342
.help(TRANSFER_LAMPORTS_ARG.help)
343343
}
344344

@@ -526,7 +526,7 @@ impl BenchSubCommand for App<'_> {
526526
)
527527
.arg(
528528
Arg::with_name("amount")
529-
.validator(|s| is_amount(s))
529+
.value_parser(Amount::parse)
530530
.value_name("TOKEN_AMOUNT")
531531
.takes_value(true)
532532
.index(3)
@@ -566,7 +566,7 @@ impl BenchSubCommand for App<'_> {
566566
)
567567
.arg(
568568
Arg::with_name("amount")
569-
.validator(|s| is_amount(s))
569+
.value_parser(Amount::parse)
570570
.value_name("TOKEN_AMOUNT")
571571
.takes_value(true)
572572
.index(3)
@@ -833,7 +833,7 @@ pub fn app<'a>(
833833
.number_of_values(1)
834834
.conflicts_with("transfer_fee")
835835
.requires("transfer_fee_basis_points")
836-
.validator(|s| is_amount(s))
836+
.value_parser(Amount::parse)
837837
.help(
838838
"Add a UI amount maximum transfer fee to the mint. \
839839
The mint authority can set and collect fees"
@@ -1084,7 +1084,7 @@ pub fn app<'a>(
10841084
)
10851085
.arg(
10861086
Arg::with_name("max_size")
1087-
.validator(|s| is_amount(s))
1087+
.value_parser(clap::value_parser!(u64))
10881088
.value_name("MAX_SIZE")
10891089
.takes_value(true)
10901090
.required(true)
@@ -1130,7 +1130,7 @@ pub fn app<'a>(
11301130
)
11311131
.arg(
11321132
Arg::with_name("new_max_size")
1133-
.validator(|s| is_amount(s))
1133+
.value_parser(clap::value_parser!(u64))
11341134
.value_name("NEW_MAX_SIZE")
11351135
.takes_value(true)
11361136
.required(true)
@@ -1428,8 +1428,8 @@ pub fn app<'a>(
14281428
.arg(
14291429
Arg::with_name("expected_fee")
14301430
.long("expected-fee")
1431-
.validator(|s| is_amount(s))
1432-
.value_name("TOKEN_AMOUNT")
1431+
.value_parser(Amount::parse)
1432+
.value_name("EXPECTED_FEE")
14331433
.takes_value(true)
14341434
.help("Expected fee amount collected during the transfer"),
14351435
)
@@ -1508,7 +1508,7 @@ pub fn app<'a>(
15081508
)
15091509
.arg(
15101510
Arg::with_name("amount")
1511-
.validator(|s| is_amount(s))
1511+
.value_parser(Amount::parse)
15121512
.value_name("TOKEN_AMOUNT")
15131513
.takes_value(true)
15141514
.index(2)
@@ -1618,7 +1618,7 @@ pub fn app<'a>(
16181618
.about("Wrap native SOL in a SOL token account")
16191619
.arg(
16201620
Arg::with_name("amount")
1621-
.validator(|s| is_amount(s))
1621+
.value_parser(Amount::parse)
16221622
.value_name("AMOUNT")
16231623
.takes_value(true)
16241624
.index(1)
@@ -1700,7 +1700,7 @@ pub fn app<'a>(
17001700
)
17011701
.arg(
17021702
Arg::with_name("amount")
1703-
.validator(|s| is_amount(s))
1703+
.value_parser(Amount::parse)
17041704
.value_name("TOKEN_AMOUNT")
17051705
.takes_value(true)
17061706
.index(2)
@@ -2331,8 +2331,8 @@ pub fn app<'a>(
23312331
)
23322332
.arg(
23332333
Arg::with_name("maximum_fee")
2334-
.value_name("TOKEN_AMOUNT")
2335-
.validator(|s| is_amount(s))
2334+
.value_name("MAXIMUM_FEE")
2335+
.value_parser(Amount::parse)
23362336
.takes_value(true)
23372337
.required(true)
23382338
.help("The new maximum transfer fee in UI amount"),

0 commit comments

Comments
 (0)