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

Commit 6e7265d

Browse files
committed
revert direct parser for is_amount validation
1 parent f420049 commit 6e7265d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

token/cli/src/clap_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ pub fn app<'a>(
839839
.number_of_values(1)
840840
.conflicts_with("transfer_fee")
841841
.requires("transfer_fee_basis_points")
842-
.value_parser(clap::value_parser!(f64))
842+
.validator(|s| is_amount(s))
843843
.help(
844844
"Add a UI amount maximum transfer fee to the mint. \
845845
The mint authority can set and collect fees"
@@ -1434,7 +1434,7 @@ pub fn app<'a>(
14341434
.arg(
14351435
Arg::with_name("expected_fee")
14361436
.long("expected-fee")
1437-
.value_parser(clap::value_parser!(f64))
1437+
.validator(|s| is_amount(s))
14381438
.value_name("TOKEN_AMOUNT")
14391439
.takes_value(true)
14401440
.help("Expected fee amount collected during the transfer"),

token/cli/src/command.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,8 +3535,11 @@ pub async fn process_command<'a>(
35353535

35363536
let transfer_fee_basis_point = arg_matches.get_one::<u16>("transfer_fee_basis_points");
35373537
let transfer_fee_maximum_fee = arg_matches
3538-
.get_one::<f64>("transfer_fee_maximum_fee")
3539-
.map(|v| spl_token::ui_amount_to_amount(*v, decimals));
3538+
.get_one::<String>("transfer_fee_maximum_fee")
3539+
.map(|str| {
3540+
let v = str.parse::<f64>().unwrap(); // inputs are validated so this is safe
3541+
spl_token::ui_amount_to_amount(v, decimals)
3542+
});
35403543
let transfer_fee = transfer_fee_basis_point
35413544
.map(|v| (*v, transfer_fee_maximum_fee.unwrap()))
35423545
.or(transfer_fee);
@@ -3870,7 +3873,9 @@ pub async fn process_command<'a>(
38703873
println_display(config, "recipient-is-ata-owner is now the default behavior. The option has been deprecated and will be removed in a future release.".to_string());
38713874
}
38723875
let use_unchecked_instruction = arg_matches.is_present("use_unchecked_instruction");
3873-
let expected_fee = arg_matches.get_one::<f64>("expected_fee").copied();
3876+
let expected_fee = arg_matches
3877+
.get_one::<String>("expected_fee")
3878+
.map(|str| str.parse::<f64>().unwrap()); // unwrap safe since inputs are validated
38743879
let memo = value_t!(arg_matches, "memo", String).ok();
38753880
let transfer_hook_accounts = arg_matches.values_of("transfer_hook_account").map(|v| {
38763881
v.into_iter()

0 commit comments

Comments
 (0)