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

Commit 06b0c1f

Browse files
committed
replace is_amount with parser
1 parent eff3494 commit 06b0c1f

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
@@ -8,7 +8,7 @@ use {
88
fee_payer::fee_payer_arg,
99
input_parsers::Amount,
1010
input_validators::{
11-
is_amount, is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey, is_valid_signer,
11+
is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey, is_valid_signer,
1212
},
1313
memo::memo_arg,
1414
nonce::*,
@@ -340,7 +340,7 @@ pub fn transfer_lamports_arg<'a>() -> Arg<'a> {
340340
.long(TRANSFER_LAMPORTS_ARG.long)
341341
.takes_value(true)
342342
.value_name("LAMPORTS")
343-
.validator(|s| is_amount(s))
343+
.value_parser(clap::value_parser!(u64))
344344
.help(TRANSFER_LAMPORTS_ARG.help)
345345
}
346346

@@ -528,7 +528,7 @@ impl BenchSubCommand for App<'_> {
528528
)
529529
.arg(
530530
Arg::with_name("amount")
531-
.validator(|s| is_amount(s))
531+
.value_parser(Amount::parse)
532532
.value_name("TOKEN_AMOUNT")
533533
.takes_value(true)
534534
.index(3)
@@ -568,7 +568,7 @@ impl BenchSubCommand for App<'_> {
568568
)
569569
.arg(
570570
Arg::with_name("amount")
571-
.validator(|s| is_amount(s))
571+
.value_parser(Amount::parse)
572572
.value_name("TOKEN_AMOUNT")
573573
.takes_value(true)
574574
.index(3)
@@ -835,7 +835,7 @@ pub fn app<'a>(
835835
.number_of_values(1)
836836
.conflicts_with("transfer_fee")
837837
.requires("transfer_fee_basis_points")
838-
.validator(|s| is_amount(s))
838+
.value_parser(Amount::parse)
839839
.help(
840840
"Add a UI amount maximum transfer fee to the mint. \
841841
The mint authority can set and collect fees"
@@ -1086,7 +1086,7 @@ pub fn app<'a>(
10861086
)
10871087
.arg(
10881088
Arg::with_name("max_size")
1089-
.validator(|s| is_amount(s))
1089+
.value_parser(clap::value_parser!(u64))
10901090
.value_name("MAX_SIZE")
10911091
.takes_value(true)
10921092
.required(true)
@@ -1132,7 +1132,7 @@ pub fn app<'a>(
11321132
)
11331133
.arg(
11341134
Arg::with_name("new_max_size")
1135-
.validator(|s| is_amount(s))
1135+
.value_parser(clap::value_parser!(u64))
11361136
.value_name("NEW_MAX_SIZE")
11371137
.takes_value(true)
11381138
.required(true)
@@ -1430,8 +1430,8 @@ pub fn app<'a>(
14301430
.arg(
14311431
Arg::with_name("expected_fee")
14321432
.long("expected-fee")
1433-
.validator(|s| is_amount(s))
1434-
.value_name("TOKEN_AMOUNT")
1433+
.value_parser(Amount::parse)
1434+
.value_name("EXPECTED_FEE")
14351435
.takes_value(true)
14361436
.help("Expected fee amount collected during the transfer"),
14371437
)
@@ -1510,7 +1510,7 @@ pub fn app<'a>(
15101510
)
15111511
.arg(
15121512
Arg::with_name("amount")
1513-
.validator(|s| is_amount(s))
1513+
.value_parser(Amount::parse)
15141514
.value_name("TOKEN_AMOUNT")
15151515
.takes_value(true)
15161516
.index(2)
@@ -1620,7 +1620,7 @@ pub fn app<'a>(
16201620
.about("Wrap native SOL in a SOL token account")
16211621
.arg(
16221622
Arg::with_name("amount")
1623-
.validator(|s| is_amount(s))
1623+
.value_parser(Amount::parse)
16241624
.value_name("AMOUNT")
16251625
.takes_value(true)
16261626
.index(1)
@@ -1702,7 +1702,7 @@ pub fn app<'a>(
17021702
)
17031703
.arg(
17041704
Arg::with_name("amount")
1705-
.validator(|s| is_amount(s))
1705+
.value_parser(Amount::parse)
17061706
.value_name("TOKEN_AMOUNT")
17071707
.takes_value(true)
17081708
.index(2)
@@ -2333,8 +2333,8 @@ pub fn app<'a>(
23332333
)
23342334
.arg(
23352335
Arg::with_name("maximum_fee")
2336-
.value_name("TOKEN_AMOUNT")
2337-
.validator(|s| is_amount(s))
2336+
.value_name("MAXIMUM_FEE")
2337+
.value_parser(Amount::parse)
23382338
.takes_value(true)
23392339
.required(true)
23402340
.help("The new maximum transfer fee in UI amount"),

0 commit comments

Comments
 (0)