@@ -28,7 +28,7 @@ use spl_token::{
28
28
native_mint,
29
29
state:: { Account , Mint } ,
30
30
} ;
31
- use std:: process:: exit;
31
+ use std:: { process:: exit, str :: FromStr } ;
32
32
33
33
static WARNING : Emoji = Emoji ( "⚠️" , "!" ) ;
34
34
@@ -339,7 +339,14 @@ fn command_mint(
339
339
Ok ( Some ( transaction) )
340
340
}
341
341
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
+
343
350
println ! ( "Freezing account: {}\n Token: {}" , account, token) ;
344
351
345
352
let mut transaction = Transaction :: new_with_payer (
@@ -364,7 +371,14 @@ fn command_freeze(config: &Config, token: Pubkey, account: Pubkey) -> CommandRes
364
371
Ok ( Some ( transaction) )
365
372
}
366
373
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
+
368
382
println ! ( "Freezing account: {}\n Token: {}" , account, token) ;
369
383
370
384
let mut transaction = Transaction :: new_with_payer (
@@ -771,43 +785,25 @@ fn main() {
771
785
. subcommand (
772
786
SubCommand :: with_name ( "freeze" )
773
787
. 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
- )
783
788
. arg (
784
789
Arg :: with_name ( "account" )
785
790
. validator ( is_pubkey_or_keypair)
786
791
. value_name ( "TOKEN_ACCOUNT_ADDRESS" )
787
792
. takes_value ( true )
788
- . index ( 2 )
793
+ . index ( 1 )
789
794
. required ( true )
790
795
. help ( "The address of the token account to freeze" ) ,
791
796
) ,
792
797
)
793
798
. subcommand (
794
799
SubCommand :: with_name ( "thaw" )
795
800
. 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
- )
805
801
. arg (
806
802
Arg :: with_name ( "account" )
807
803
. validator ( is_pubkey_or_keypair)
808
804
. value_name ( "TOKEN_ACCOUNT_ADDRESS" )
809
805
. takes_value ( true )
810
- . index ( 2 )
806
+ . index ( 1 )
811
807
. required ( true )
812
808
. help ( "The address of the token account to thaw" ) ,
813
809
) ,
@@ -995,14 +991,12 @@ fn main() {
995
991
command_mint ( & config, token, amount, recipient)
996
992
}
997
993
( "freeze" , Some ( arg_matches) ) => {
998
- let token = pubkey_of ( arg_matches, "token" ) . unwrap ( ) ;
999
994
let account = pubkey_of ( arg_matches, "account" ) . unwrap ( ) ;
1000
- command_freeze ( & config, token , account)
995
+ command_freeze ( & config, account)
1001
996
}
1002
997
( "thaw" , Some ( arg_matches) ) => {
1003
- let token = pubkey_of ( arg_matches, "token" ) . unwrap ( ) ;
1004
998
let account = pubkey_of ( arg_matches, "account" ) . unwrap ( ) ;
1005
- command_thaw ( & config, token , account)
999
+ command_thaw ( & config, account)
1006
1000
}
1007
1001
( "wrap" , Some ( arg_matches) ) => {
1008
1002
let amount = value_t_or_exit ! ( arg_matches, "amount" , f64 ) ;
0 commit comments