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

Commit 75e1220

Browse files
Accounts: check mint if provided, use helper (#1503)
1 parent a3e8af2 commit 75e1220

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

token/cli/src/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ fn resolve_mint_info(
474474
}
475475
}
476476

477+
fn validate_mint(config: &Config, token: Pubkey) -> Result<(), Error> {
478+
let mint = config.rpc_client.get_account(&token);
479+
if mint.is_err() || Mint::unpack(&mint.unwrap().data).is_err() {
480+
return Err(format!("Invalid mint account {:?}", token).into());
481+
}
482+
Ok(())
483+
}
484+
477485
#[allow(clippy::too_many_arguments)]
478486
fn command_transfer(
479487
config: &Config,
@@ -884,6 +892,9 @@ fn command_supply(config: &Config, address: Pubkey) -> CommandResult {
884892
}
885893

886894
fn command_accounts(config: &Config, token: Option<Pubkey>) -> CommandResult {
895+
if let Some(token) = token {
896+
validate_mint(config, token)?;
897+
}
887898
let accounts = config.rpc_client.get_token_accounts_by_owner(
888899
&config.owner,
889900
match token {
@@ -1006,10 +1017,7 @@ fn command_accounts(config: &Config, token: Option<Pubkey>) -> CommandResult {
10061017

10071018
fn command_address(config: &Config, token: Option<Pubkey>) -> CommandResult {
10081019
if let Some(token) = token {
1009-
let mint = config.rpc_client.get_account(&token);
1010-
if mint.is_err() || Mint::unpack(&mint.unwrap().data).is_err() {
1011-
return Err(format!("Invalid mint account {:?}", token).into());
1012-
}
1020+
validate_mint(config, token)?;
10131021
let associated_token_address = get_associated_token_address(&config.owner, &token);
10141022
println!("Wallet address: {:?}", config.owner);
10151023
println!("Associated token address: {:?}", associated_token_address);

0 commit comments

Comments
 (0)