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

Commit e0fb75d

Browse files
t-nelsonmergify[bot]
authored andcommitted
spl-token-cli: Use signer-based arg validators/parsers
1 parent c4cf9ff commit e0fb75d

File tree

1 file changed

+83
-46
lines changed

1 file changed

+83
-46
lines changed

token/cli/src/main.rs

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use solana_account_decoder::{
88
UiAccountData,
99
};
1010
use solana_clap_utils::{
11-
input_parsers::pubkey_of,
12-
input_validators::{is_amount, is_keypair, is_pubkey_or_keypair, is_url},
11+
input_parsers::pubkey_of_signer,
12+
input_validators::{is_amount, is_url, is_valid_pubkey, is_valid_signer},
1313
keypair::signer_from_path,
1414
};
1515
use solana_cli_output::display::println_name_value;
@@ -739,7 +739,7 @@ fn main() {
739739
Arg::with_name("owner")
740740
.long("owner")
741741
.value_name("KEYPAIR")
742-
.validator(is_keypair)
742+
.validator(is_valid_signer)
743743
.takes_value(true)
744744
.global(true)
745745
.help(
@@ -752,7 +752,7 @@ fn main() {
752752
Arg::with_name("fee_payer")
753753
.long("fee-payer")
754754
.value_name("KEYPAIR")
755-
.validator(is_keypair)
755+
.validator(is_valid_signer)
756756
.takes_value(true)
757757
.global(true)
758758
.help(
@@ -777,7 +777,7 @@ fn main() {
777777
.arg(
778778
Arg::with_name("token_keypair")
779779
.value_name("KEYPAIR")
780-
.validator(is_keypair)
780+
.validator(is_valid_signer)
781781
.takes_value(true)
782782
.index(1)
783783
.help(
@@ -800,7 +800,7 @@ fn main() {
800800
.about("Create a new token account")
801801
.arg(
802802
Arg::with_name("token")
803-
.validator(is_pubkey_or_keypair)
803+
.validator(is_valid_pubkey)
804804
.value_name("TOKEN_ADDRESS")
805805
.takes_value(true)
806806
.index(1)
@@ -810,7 +810,7 @@ fn main() {
810810
.arg(
811811
Arg::with_name("account_keypair")
812812
.value_name("KEYPAIR")
813-
.validator(is_keypair)
813+
.validator(is_valid_signer)
814814
.takes_value(true)
815815
.index(2)
816816
.help(
@@ -825,7 +825,7 @@ fn main() {
825825
.about("Authorize a new signing keypair to a token or token account")
826826
.arg(
827827
Arg::with_name("address")
828-
.validator(is_pubkey_or_keypair)
828+
.validator(is_valid_pubkey)
829829
.value_name("TOKEN_ADDRESS")
830830
.takes_value(true)
831831
.index(1)
@@ -845,7 +845,7 @@ fn main() {
845845
)
846846
.arg(
847847
Arg::with_name("new_authority")
848-
.validator(is_pubkey_or_keypair)
848+
.validator(is_valid_pubkey)
849849
.value_name("AUTHORITY_ADDRESS")
850850
.takes_value(true)
851851
.index(3)
@@ -865,7 +865,7 @@ fn main() {
865865
.about("Transfer tokens between accounts")
866866
.arg(
867867
Arg::with_name("sender")
868-
.validator(is_pubkey_or_keypair)
868+
.validator(is_valid_pubkey)
869869
.value_name("SENDER_TOKEN_ACCOUNT_ADDRESS")
870870
.takes_value(true)
871871
.index(1)
@@ -883,7 +883,7 @@ fn main() {
883883
)
884884
.arg(
885885
Arg::with_name("recipient")
886-
.validator(is_pubkey_or_keypair)
886+
.validator(is_valid_pubkey)
887887
.value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS")
888888
.takes_value(true)
889889
.index(3)
@@ -896,7 +896,7 @@ fn main() {
896896
.about("Burn tokens from an account")
897897
.arg(
898898
Arg::with_name("source")
899-
.validator(is_pubkey_or_keypair)
899+
.validator(is_valid_pubkey)
900900
.value_name("SOURCE_TOKEN_ACCOUNT_ADDRESS")
901901
.takes_value(true)
902902
.index(1)
@@ -918,7 +918,7 @@ fn main() {
918918
.about("Mint new tokens")
919919
.arg(
920920
Arg::with_name("token")
921-
.validator(is_pubkey_or_keypair)
921+
.validator(is_valid_pubkey)
922922
.value_name("TOKEN_ADDRESS")
923923
.takes_value(true)
924924
.index(1)
@@ -936,7 +936,7 @@ fn main() {
936936
)
937937
.arg(
938938
Arg::with_name("recipient")
939-
.validator(is_pubkey_or_keypair)
939+
.validator(is_valid_pubkey)
940940
.value_name("RECIPIENT_TOKEN_ACCOUNT_ADDRESS")
941941
.takes_value(true)
942942
.index(3)
@@ -949,7 +949,7 @@ fn main() {
949949
.about("Freeze a token account")
950950
.arg(
951951
Arg::with_name("account")
952-
.validator(is_pubkey_or_keypair)
952+
.validator(is_valid_pubkey)
953953
.value_name("TOKEN_ACCOUNT_ADDRESS")
954954
.takes_value(true)
955955
.index(1)
@@ -962,7 +962,7 @@ fn main() {
962962
.about("Thaw a token account")
963963
.arg(
964964
Arg::with_name("account")
965-
.validator(is_pubkey_or_keypair)
965+
.validator(is_valid_pubkey)
966966
.value_name("TOKEN_ACCOUNT_ADDRESS")
967967
.takes_value(true)
968968
.index(1)
@@ -975,7 +975,7 @@ fn main() {
975975
.about("Get token account balance")
976976
.arg(
977977
Arg::with_name("address")
978-
.validator(is_pubkey_or_keypair)
978+
.validator(is_valid_pubkey)
979979
.value_name("TOKEN_ACCOUNT_ADDRESS")
980980
.takes_value(true)
981981
.index(1)
@@ -988,7 +988,7 @@ fn main() {
988988
.about("Get token supply")
989989
.arg(
990990
Arg::with_name("address")
991-
.validator(is_pubkey_or_keypair)
991+
.validator(is_valid_pubkey)
992992
.value_name("TOKEN_ADDRESS")
993993
.takes_value(true)
994994
.index(1)
@@ -1001,7 +1001,7 @@ fn main() {
10011001
.about("List all token accounts by owner")
10021002
.arg(
10031003
Arg::with_name("token")
1004-
.validator(is_pubkey_or_keypair)
1004+
.validator(is_valid_pubkey)
10051005
.value_name("TOKEN_ADDRESS")
10061006
.takes_value(true)
10071007
.index(1)
@@ -1026,7 +1026,7 @@ fn main() {
10261026
.about("Unwrap a SOL token account")
10271027
.arg(
10281028
Arg::with_name("address")
1029-
.validator(is_pubkey_or_keypair)
1029+
.validator(is_valid_pubkey)
10301030
.value_name("TOKEN_ACCOUNT_ADDRESS")
10311031
.takes_value(true)
10321032
.index(1)
@@ -1039,7 +1039,7 @@ fn main() {
10391039
.about("Query details of an SPL Token account by address")
10401040
.arg(
10411041
Arg::with_name("address")
1042-
.validator(is_pubkey_or_keypair)
1042+
.validator(is_valid_pubkey)
10431043
.value_name("TOKEN_ACCOUNT_ADDRESS")
10441044
.takes_value(true)
10451045
.index(1)
@@ -1052,7 +1052,7 @@ fn main() {
10521052
.about("Approve a delegate for a token account")
10531053
.arg(
10541054
Arg::with_name("account")
1055-
.validator(is_pubkey_or_keypair)
1055+
.validator(is_valid_pubkey)
10561056
.value_name("TOKEN_ACCOUNT_ADDRESS")
10571057
.takes_value(true)
10581058
.index(1)
@@ -1070,7 +1070,7 @@ fn main() {
10701070
)
10711071
.arg(
10721072
Arg::with_name("delegate")
1073-
.validator(is_pubkey_or_keypair)
1073+
.validator(is_valid_pubkey)
10741074
.value_name("DELEGATE_TOKEN_ACCOUNT_ADDRESS")
10751075
.takes_value(true)
10761076
.index(3)
@@ -1083,7 +1083,7 @@ fn main() {
10831083
.about("Revoke a delegate's authority")
10841084
.arg(
10851085
Arg::with_name("account")
1086-
.validator(is_pubkey_or_keypair)
1086+
.validator(is_valid_pubkey)
10871087
.value_name("TOKEN_ACCOUNT_ADDRESS")
10881088
.takes_value(true)
10891089
.index(1)
@@ -1096,7 +1096,7 @@ fn main() {
10961096
.about("Close a token account")
10971097
.arg(
10981098
Arg::with_name("account")
1099-
.validator(is_pubkey_or_keypair)
1099+
.validator(is_valid_pubkey)
11001100
.value_name("TOKEN_ACCOUNT_ADDRESS")
11011101
.takes_value(true)
11021102
.index(1)
@@ -1105,7 +1105,7 @@ fn main() {
11051105
)
11061106
.arg(
11071107
Arg::with_name("destination")
1108-
.validator(is_pubkey_or_keypair)
1108+
.validator(is_valid_pubkey)
11091109
.value_name("TOKEN_ACCOUNT_ADDRESS")
11101110
.takes_value(true)
11111111
.index(2)
@@ -1191,7 +1191,9 @@ fn main() {
11911191
)
11921192
}
11931193
("create-account", Some(arg_matches)) => {
1194-
let token = pubkey_of(arg_matches, "token").unwrap();
1194+
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager)
1195+
.unwrap()
1196+
.unwrap();
11951197
let account = if arg_matches.is_present("account_keypair") {
11961198
signer_from_path(
11971199
&matches,
@@ -1210,7 +1212,9 @@ fn main() {
12101212
command_create_account(&config, token, account)
12111213
}
12121214
("authorize", Some(arg_matches)) => {
1213-
let address = pubkey_of(arg_matches, "address").unwrap();
1215+
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
1216+
.unwrap()
1217+
.unwrap();
12141218
let authority_type = arg_matches.value_of("authority_type").unwrap();
12151219
let authority_type = match authority_type {
12161220
"mint" => AuthorityType::MintTokens,
@@ -1219,71 +1223,104 @@ fn main() {
12191223
"close" => AuthorityType::CloseAccount,
12201224
_ => unreachable!(),
12211225
};
1222-
let new_authority = pubkey_of(arg_matches, "new_authority");
1226+
let new_authority =
1227+
pubkey_of_signer(arg_matches, "new_authority", &mut wallet_manager).unwrap();
12231228
command_authorize(&config, address, authority_type, new_authority)
12241229
}
12251230
("transfer", Some(arg_matches)) => {
1226-
let sender = pubkey_of(arg_matches, "sender").unwrap();
1231+
let sender = pubkey_of_signer(arg_matches, "sender", &mut wallet_manager)
1232+
.unwrap()
1233+
.unwrap();
12271234
let amount = value_t_or_exit!(arg_matches, "amount", f64);
1228-
let recipient = pubkey_of(arg_matches, "recipient").unwrap();
1235+
let recipient = pubkey_of_signer(arg_matches, "recipient", &mut wallet_manager)
1236+
.unwrap()
1237+
.unwrap();
12291238
command_transfer(&config, sender, amount, recipient)
12301239
}
12311240
("burn", Some(arg_matches)) => {
1232-
let source = pubkey_of(arg_matches, "source").unwrap();
1241+
let source = pubkey_of_signer(arg_matches, "source", &mut wallet_manager)
1242+
.unwrap()
1243+
.unwrap();
12331244
let amount = value_t_or_exit!(arg_matches, "amount", f64);
12341245
command_burn(&config, source, amount)
12351246
}
12361247
("mint", Some(arg_matches)) => {
1237-
let token = pubkey_of(arg_matches, "token").unwrap();
1248+
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager)
1249+
.unwrap()
1250+
.unwrap();
12381251
let amount = value_t_or_exit!(arg_matches, "amount", f64);
1239-
let recipient = pubkey_of(arg_matches, "recipient").unwrap();
1252+
let recipient = pubkey_of_signer(arg_matches, "recipient", &mut wallet_manager)
1253+
.unwrap()
1254+
.unwrap();
12401255
command_mint(&config, token, amount, recipient)
12411256
}
12421257
("freeze", Some(arg_matches)) => {
1243-
let account = pubkey_of(arg_matches, "account").unwrap();
1258+
let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager)
1259+
.unwrap()
1260+
.unwrap();
12441261
command_freeze(&config, account)
12451262
}
12461263
("thaw", Some(arg_matches)) => {
1247-
let account = pubkey_of(arg_matches, "account").unwrap();
1264+
let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager)
1265+
.unwrap()
1266+
.unwrap();
12481267
command_thaw(&config, account)
12491268
}
12501269
("wrap", Some(arg_matches)) => {
12511270
let amount = value_t_or_exit!(arg_matches, "amount", f64);
12521271
command_wrap(&config, amount)
12531272
}
12541273
("unwrap", Some(arg_matches)) => {
1255-
let address = pubkey_of(arg_matches, "address").unwrap();
1274+
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
1275+
.unwrap()
1276+
.unwrap();
12561277
command_unwrap(&config, address)
12571278
}
12581279
("approve", Some(arg_matches)) => {
1259-
let account = pubkey_of(arg_matches, "account").unwrap();
1280+
let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager)
1281+
.unwrap()
1282+
.unwrap();
12601283
let amount = value_t_or_exit!(arg_matches, "amount", f64);
1261-
let delegate = pubkey_of(arg_matches, "delegate").unwrap();
1284+
let delegate = pubkey_of_signer(arg_matches, "delegate", &mut wallet_manager)
1285+
.unwrap()
1286+
.unwrap();
12621287
command_approve(&config, account, amount, delegate)
12631288
}
12641289
("revoke", Some(arg_matches)) => {
1265-
let account = pubkey_of(arg_matches, "account").unwrap();
1290+
let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager)
1291+
.unwrap()
1292+
.unwrap();
12661293
command_revoke(&config, account)
12671294
}
12681295
("close", Some(arg_matches)) => {
1269-
let account = pubkey_of(arg_matches, "account").unwrap();
1270-
let destination = pubkey_of(arg_matches, "destination").unwrap();
1296+
let account = pubkey_of_signer(arg_matches, "account", &mut wallet_manager)
1297+
.unwrap()
1298+
.unwrap();
1299+
let destination = pubkey_of_signer(arg_matches, "destination", &mut wallet_manager)
1300+
.unwrap()
1301+
.unwrap();
12711302
command_close(&config, account, destination)
12721303
}
12731304
("balance", Some(arg_matches)) => {
1274-
let address = pubkey_of(arg_matches, "address").unwrap();
1305+
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
1306+
.unwrap()
1307+
.unwrap();
12751308
command_balance(&config, address)
12761309
}
12771310
("supply", Some(arg_matches)) => {
1278-
let address = pubkey_of(arg_matches, "address").unwrap();
1311+
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
1312+
.unwrap()
1313+
.unwrap();
12791314
command_supply(&config, address)
12801315
}
12811316
("accounts", Some(arg_matches)) => {
1282-
let token = pubkey_of(arg_matches, "token");
1317+
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap();
12831318
command_accounts(&config, token)
12841319
}
12851320
("account-info", Some(arg_matches)) => {
1286-
let address = pubkey_of(arg_matches, "address").unwrap();
1321+
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
1322+
.unwrap()
1323+
.unwrap();
12871324
command_account(&config, address)
12881325
}
12891326
_ => unreachable!(),

0 commit comments

Comments
 (0)