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

Commit 5bf19b6

Browse files
Clean up freeze/thaw querying for mint (#529)
1 parent 3f25180 commit 5bf19b6

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

token/cli/src/main.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use spl_token::{
2828
native_mint,
2929
state::{Account, Mint},
3030
};
31-
use std::process::exit;
31+
use std::{process::exit, str::FromStr};
3232

3333
static WARNING: Emoji = Emoji("⚠️", "!");
3434

@@ -339,7 +339,14 @@ fn command_mint(
339339
Ok(Some(transaction))
340340
}
341341

342-
fn command_freeze(config: &Config, token: Pubkey, account: Pubkey) -> CommandResult {
342+
fn command_freeze(config: &Config, account: Pubkey) -> CommandResult {
343+
let token_account = config
344+
.rpc_client
345+
.get_token_account_with_commitment(&account, config.commitment_config)?
346+
.value
347+
.ok_or_else(|| format!("Could not find token account {}", account))?;
348+
let token = Pubkey::from_str(&token_account.mint)?;
349+
343350
println!("Freezing account: {}\n Token: {}", account, token);
344351

345352
let mut transaction = Transaction::new_with_payer(
@@ -364,7 +371,14 @@ fn command_freeze(config: &Config, token: Pubkey, account: Pubkey) -> CommandRes
364371
Ok(Some(transaction))
365372
}
366373

367-
fn command_thaw(config: &Config, token: Pubkey, account: Pubkey) -> CommandResult {
374+
fn command_thaw(config: &Config, account: Pubkey) -> CommandResult {
375+
let token_account = config
376+
.rpc_client
377+
.get_token_account_with_commitment(&account, config.commitment_config)?
378+
.value
379+
.ok_or_else(|| format!("Could not find token account {}", account))?;
380+
let token = Pubkey::from_str(&token_account.mint)?;
381+
368382
println!("Freezing account: {}\n Token: {}", account, token);
369383

370384
let mut transaction = Transaction::new_with_payer(
@@ -771,43 +785,25 @@ fn main() {
771785
.subcommand(
772786
SubCommand::with_name("freeze")
773787
.about("Freeze a token account")
774-
.arg(
775-
Arg::with_name("token") // TODO: remove this arg when solana-client v1.3.12+ is published; grab mint from token account state
776-
.validator(is_pubkey_or_keypair)
777-
.value_name("TOKEN_ADDRESS")
778-
.takes_value(true)
779-
.index(1)
780-
.required(true)
781-
.help("The token mint"),
782-
)
783788
.arg(
784789
Arg::with_name("account")
785790
.validator(is_pubkey_or_keypair)
786791
.value_name("TOKEN_ACCOUNT_ADDRESS")
787792
.takes_value(true)
788-
.index(2)
793+
.index(1)
789794
.required(true)
790795
.help("The address of the token account to freeze"),
791796
),
792797
)
793798
.subcommand(
794799
SubCommand::with_name("thaw")
795800
.about("Thaw a token account")
796-
.arg(
797-
Arg::with_name("token") // TODO: remove this arg when solana-client v1.3.12+ is published; grab mint from token account state
798-
.validator(is_pubkey_or_keypair)
799-
.value_name("TOKEN_ADDRESS")
800-
.takes_value(true)
801-
.index(1)
802-
.required(true)
803-
.help("The token mint"),
804-
)
805801
.arg(
806802
Arg::with_name("account")
807803
.validator(is_pubkey_or_keypair)
808804
.value_name("TOKEN_ACCOUNT_ADDRESS")
809805
.takes_value(true)
810-
.index(2)
806+
.index(1)
811807
.required(true)
812808
.help("The address of the token account to thaw"),
813809
),
@@ -995,14 +991,12 @@ fn main() {
995991
command_mint(&config, token, amount, recipient)
996992
}
997993
("freeze", Some(arg_matches)) => {
998-
let token = pubkey_of(arg_matches, "token").unwrap();
999994
let account = pubkey_of(arg_matches, "account").unwrap();
1000-
command_freeze(&config, token, account)
995+
command_freeze(&config, account)
1001996
}
1002997
("thaw", Some(arg_matches)) => {
1003-
let token = pubkey_of(arg_matches, "token").unwrap();
1004998
let account = pubkey_of(arg_matches, "account").unwrap();
1005-
command_thaw(&config, token, account)
999+
command_thaw(&config, account)
10061000
}
10071001
("wrap", Some(arg_matches)) => {
10081002
let amount = value_t_or_exit!(arg_matches, "amount", f64);

0 commit comments

Comments
 (0)