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

Commit e988b16

Browse files
committed
token-cli: constrain program id input
1 parent 2ae2a6b commit e988b16

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

token/cli/src/main.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use solana_clap_utils::{
1212
fee_payer::fee_payer_arg,
1313
input_parsers::{pubkey_of_signer, pubkeys_of_multiple_signers, value_of},
1414
input_validators::{
15-
is_amount, is_amount_or_all, is_parsable, is_url_or_moniker, is_valid_pubkey,
15+
is_amount, is_amount_or_all, is_parsable, is_pubkey, is_url_or_moniker, is_valid_pubkey,
1616
is_valid_signer,
1717
},
1818
keypair::signer_from_path,
@@ -1987,6 +1987,23 @@ fn multisig_member_help_string() -> String {
19871987
)
19881988
}
19891989

1990+
fn is_valid_token_program_id<T>(string: T) -> Result<(), String>
1991+
where
1992+
T: AsRef<str> + Display,
1993+
{
1994+
match is_pubkey(string.as_ref()) {
1995+
Ok(()) => {
1996+
let program_id = string.as_ref().parse::<Pubkey>().unwrap();
1997+
if program_id == spl_token_2022::id() || program_id == spl_token::id() {
1998+
Ok(())
1999+
} else {
2000+
Err(format!("Unrecognized token program id: {}", program_id))
2001+
}
2002+
}
2003+
Err(e) => Err(e),
2004+
}
2005+
}
2006+
19902007
fn app<'a, 'b>(
19912008
default_decimals: &'a str,
19922009
minimum_signers_help: &'b str,
@@ -2029,7 +2046,7 @@ fn app<'a, 'b>(
20292046
.value_name("ADDRESS")
20302047
.takes_value(true)
20312048
.global(true)
2032-
.validator(is_valid_pubkey)
2049+
.validator(is_valid_token_program_id)
20332050
.help("SPL Token program id"),
20342051
)
20352052
.arg(

0 commit comments

Comments
 (0)