@@ -20,8 +20,7 @@ use solana_clap_utils::{
20
20
} ;
21
21
use solana_cli_output:: { display:: println_name_value, return_signers, OutputFormat } ;
22
22
use solana_client:: {
23
- blockhash_query:: BlockhashQuery , rpc_client:: RpcClient , rpc_config:: RpcSendTransactionConfig ,
24
- rpc_request:: TokenAccountsFilter ,
23
+ blockhash_query:: BlockhashQuery , rpc_client:: RpcClient , rpc_request:: TokenAccountsFilter ,
25
24
} ;
26
25
use solana_remote_wallet:: remote_wallet:: RemoteWalletManager ;
27
26
use solana_sdk:: {
@@ -146,7 +145,6 @@ struct Config<'a> {
146
145
verbose : bool ,
147
146
owner : Pubkey ,
148
147
fee_payer : Pubkey ,
149
- commitment_config : CommitmentConfig ,
150
148
default_signer : DefaultSigner ,
151
149
nonce_account : Option < Pubkey > ,
152
150
nonce_authority : Option < Pubkey > ,
@@ -165,10 +163,7 @@ fn new_throwaway_signer() -> (Option<Box<dyn Signer>>, Option<Pubkey>) {
165
163
}
166
164
167
165
fn check_fee_payer_balance ( config : & Config , required_balance : u64 ) -> Result < ( ) , Error > {
168
- let balance = config
169
- . rpc_client
170
- . get_balance_with_commitment ( & config. fee_payer , config. commitment_config ) ?
171
- . value ;
166
+ let balance = config. rpc_client . get_balance ( & config. fee_payer ) ?;
172
167
if balance < required_balance {
173
168
Err ( format ! (
174
169
"Fee payer, {}, has insufficient balance: {} required, {} available" ,
@@ -183,10 +178,7 @@ fn check_fee_payer_balance(config: &Config, required_balance: u64) -> Result<(),
183
178
}
184
179
185
180
fn check_owner_balance ( config : & Config , required_balance : u64 ) -> Result < ( ) , Error > {
186
- let balance = config
187
- . rpc_client
188
- . get_balance_with_commitment ( & config. owner , config. commitment_config ) ?
189
- . value ;
181
+ let balance = config. rpc_client . get_balance ( & config. owner ) ?;
190
182
if balance < required_balance {
191
183
Err ( format ! (
192
184
"Owner, {}, has insufficient balance: {} required, {} available" ,
@@ -306,14 +298,9 @@ fn command_create_account(
306
298
)
307
299
} ;
308
300
309
- if let Some ( account_data) = config
310
- . rpc_client
311
- . get_account_with_commitment ( & account, config. commitment_config ) ?
312
- . value
313
- {
314
- if !( account_data. owner == system_program:: id ( ) && system_account_ok) {
315
- return Err ( format ! ( "Error: Account already exists: {}" , account) . into ( ) ) ;
316
- }
301
+ let account_data = config. rpc_client . get_account ( & account) ?;
302
+ if !( account_data. owner == system_program:: id ( ) && system_account_ok) {
303
+ return Err ( format ! ( "Error: Account already exists: {}" , account) . into ( ) ) ;
317
304
}
318
305
319
306
Ok ( Some ( (
@@ -407,8 +394,7 @@ fn resolve_mint_info(
407
394
if !config. sign_only {
408
395
let source_account = config
409
396
. rpc_client
410
- . get_token_account_with_commitment ( & token_account, config. commitment_config ) ?
411
- . value
397
+ . get_token_account ( & token_account) ?
412
398
. ok_or_else ( || format ! ( "Could not find token account {}" , token_account) ) ?;
413
399
Ok ( (
414
400
Pubkey :: from_str ( & source_account. mint ) ?,
@@ -462,64 +448,55 @@ fn command_transfer(
462
448
let mut recipient_token_account = recipient;
463
449
let mut minimum_balance_for_rent_exemption = 0 ;
464
450
465
- if let Some ( account_data) = config
466
- . rpc_client
467
- . get_account_with_commitment ( & recipient, config. commitment_config ) ?
468
- . value
469
- {
470
- if account_data. owner == system_program:: id ( ) {
471
- recipient_token_account = get_associated_token_address ( & recipient, & mint_pubkey) ;
472
- println ! (
473
- " Recipient associated token account: {}" ,
474
- recipient_token_account
475
- ) ;
451
+ let account_data = config. rpc_client . get_account ( & recipient) ?;
452
+ if account_data. owner == system_program:: id ( ) {
453
+ recipient_token_account = get_associated_token_address ( & recipient, & mint_pubkey) ;
454
+ println ! (
455
+ " Recipient associated token account: {}" ,
456
+ recipient_token_account
457
+ ) ;
476
458
477
- let needs_funding = if let Some ( recipient_token_account_data) = config
478
- . rpc_client
479
- . get_account_with_commitment ( & recipient_token_account, config. commitment_config ) ?
480
- . value
481
- {
482
- if recipient_token_account_data. owner == system_program:: id ( ) {
483
- true
484
- } else if recipient_token_account_data. owner == spl_token:: id ( ) {
485
- false
486
- } else {
487
- return Err (
488
- format ! ( "Error: Unsupported recipient address: {}" , recipient) . into ( ) ,
489
- ) ;
490
- }
491
- } else {
459
+ let needs_funding = if let Some ( recipient_token_account_data) = config
460
+ . rpc_client
461
+ . get_account_with_commitment ( & recipient_token_account, config. rpc_client . commitment ( ) ) ?
462
+ . value
463
+ {
464
+ if recipient_token_account_data. owner == system_program:: id ( ) {
492
465
true
493
- } ;
466
+ } else if recipient_token_account_data. owner == spl_token:: id ( ) {
467
+ false
468
+ } else {
469
+ return Err ( format ! ( "Error: Unsupported recipient address: {}" , recipient) . into ( ) ) ;
470
+ }
471
+ } else {
472
+ true
473
+ } ;
494
474
495
- if needs_funding {
496
- if fund_recipient {
497
- minimum_balance_for_rent_exemption += config
498
- . rpc_client
499
- . get_minimum_balance_for_rent_exemption ( Account :: LEN ) ?;
500
- println ! (
501
- " Funding recipient: {} ({} SOL)" ,
502
- recipient_token_account,
503
- lamports_to_sol( minimum_balance_for_rent_exemption)
504
- ) ;
505
- instructions. push ( create_associated_token_account (
506
- & config. fee_payer ,
507
- & recipient,
508
- & mint_pubkey,
509
- ) ) ;
510
- } else {
511
- return Err (
512
- "Error: Recipient's associated token account does not exist. \
475
+ if needs_funding {
476
+ if fund_recipient {
477
+ minimum_balance_for_rent_exemption += config
478
+ . rpc_client
479
+ . get_minimum_balance_for_rent_exemption ( Account :: LEN ) ?;
480
+ println ! (
481
+ " Funding recipient: {} ({} SOL)" ,
482
+ recipient_token_account,
483
+ lamports_to_sol( minimum_balance_for_rent_exemption)
484
+ ) ;
485
+ instructions. push ( create_associated_token_account (
486
+ & config. fee_payer ,
487
+ & recipient,
488
+ & mint_pubkey,
489
+ ) ) ;
490
+ } else {
491
+ return Err (
492
+ "Error: Recipient's associated token account does not exist. \
513
493
Add `--fund-recipient` to fund their account"
514
- . into ( ) ,
515
- ) ;
516
- }
494
+ . into ( ) ,
495
+ ) ;
517
496
}
518
- } else if account_data. owner != spl_token:: id ( ) {
519
- return Err ( format ! ( "Error: Unsupported recipient address: {}" , recipient) . into ( ) ) ;
520
497
}
521
- } else {
522
- return Err ( format ! ( "Error: Recipient does not exist : {}" , recipient) . into ( ) ) ;
498
+ } else if account_data . owner != spl_token :: id ( ) {
499
+ return Err ( format ! ( "Error: Unsupported recipient address : {}" , recipient) . into ( ) ) ;
523
500
}
524
501
525
502
instructions. push ( transfer_checked (
@@ -649,12 +626,7 @@ fn command_unwrap(config: &Config, address: Pubkey) -> CommandResult {
649
626
if !config. sign_only {
650
627
println ! (
651
628
" Amount: {} SOL" ,
652
- lamports_to_sol(
653
- config
654
- . rpc_client
655
- . get_balance_with_commitment( & address, config. commitment_config) ?
656
- . value
657
- ) ,
629
+ lamports_to_sol( config. rpc_client. get_balance( & address) ?) ,
658
630
) ;
659
631
}
660
632
println ! ( " Recipient: {}" , & config. owner) ;
@@ -702,8 +674,7 @@ fn command_revoke(config: &Config, account: Pubkey, delegate: Option<Pubkey>) ->
702
674
let delegate = if !config. sign_only {
703
675
let source_account = config
704
676
. rpc_client
705
- . get_token_account_with_commitment ( & account, config. commitment_config ) ?
706
- . value
677
+ . get_token_account ( & account) ?
707
678
. ok_or_else ( || format ! ( "Could not find token account {}" , account) ) ?;
708
679
if let Some ( string) = source_account. delegate {
709
680
Some ( Pubkey :: from_str ( & string) ?)
@@ -736,8 +707,7 @@ fn command_close(config: &Config, account: Pubkey, destination: Pubkey) -> Comma
736
707
if !config. sign_only {
737
708
let source_account = config
738
709
. rpc_client
739
- . get_token_account_with_commitment ( & account, config. commitment_config ) ?
740
- . value
710
+ . get_token_account ( & account) ?
741
711
. ok_or_else ( || format ! ( "Could not find token account {}" , account) ) ?;
742
712
743
713
if !source_account. is_native && source_account. token_amount . ui_amount > 0.0 {
@@ -760,10 +730,7 @@ fn command_close(config: &Config, account: Pubkey, destination: Pubkey) -> Comma
760
730
}
761
731
762
732
fn command_balance ( config : & Config , address : Pubkey ) -> CommandResult {
763
- let balance = config
764
- . rpc_client
765
- . get_token_account_balance_with_commitment ( & address, config. commitment_config ) ?
766
- . value ;
733
+ let balance = config. rpc_client . get_token_account_balance ( & address) ?;
767
734
768
735
if config. verbose {
769
736
println ! ( "ui amount: {}" , balance. ui_amount) ;
@@ -776,27 +743,20 @@ fn command_balance(config: &Config, address: Pubkey) -> CommandResult {
776
743
}
777
744
778
745
fn command_supply ( config : & Config , address : Pubkey ) -> CommandResult {
779
- let supply = config
780
- . rpc_client
781
- . get_token_supply_with_commitment ( & address, config. commitment_config ) ?
782
- . value ;
746
+ let supply = config. rpc_client . get_token_supply ( & address) ?;
783
747
784
748
println ! ( "{}" , supply. ui_amount) ;
785
749
Ok ( None )
786
750
}
787
751
788
752
fn command_accounts ( config : & Config , token : Option < Pubkey > ) -> CommandResult {
789
- let accounts = config
790
- . rpc_client
791
- . get_token_accounts_by_owner_with_commitment (
792
- & config. owner ,
793
- match token {
794
- Some ( token) => TokenAccountsFilter :: Mint ( token) ,
795
- None => TokenAccountsFilter :: ProgramId ( spl_token:: id ( ) ) ,
796
- } ,
797
- config. commitment_config ,
798
- ) ?
799
- . value ;
753
+ let accounts = config. rpc_client . get_token_accounts_by_owner (
754
+ & config. owner ,
755
+ match token {
756
+ Some ( token) => TokenAccountsFilter :: Mint ( token) ,
757
+ None => TokenAccountsFilter :: ProgramId ( spl_token:: id ( ) ) ,
758
+ } ,
759
+ ) ?;
800
760
if accounts. is_empty ( ) {
801
761
println ! ( "None" ) ;
802
762
}
@@ -853,14 +813,10 @@ fn command_accounts(config: &Config, token: Option<Pubkey>) -> CommandResult {
853
813
854
814
fn command_gc ( config : & Config ) -> CommandResult {
855
815
println ! ( "Fetching token accounts" ) ;
856
- let accounts = config
857
- . rpc_client
858
- . get_token_accounts_by_owner_with_commitment (
859
- & config. owner ,
860
- TokenAccountsFilter :: ProgramId ( spl_token:: id ( ) ) ,
861
- config. commitment_config ,
862
- ) ?
863
- . value ;
816
+ let accounts = config. rpc_client . get_token_accounts_by_owner (
817
+ & config. owner ,
818
+ TokenAccountsFilter :: ProgramId ( spl_token:: id ( ) ) ,
819
+ ) ?;
864
820
if accounts. is_empty ( ) {
865
821
println ! ( "Nothing to do" ) ;
866
822
return Ok ( None ) ;
@@ -1005,11 +961,7 @@ fn stringify_ui_token_amount_trimmed(amount: &UiTokenAmount) -> String {
1005
961
}
1006
962
1007
963
fn command_account_info ( config : & Config , address : Pubkey ) -> CommandResult {
1008
- let account = config
1009
- . rpc_client
1010
- . get_token_account_with_commitment ( & address, config. commitment_config ) ?
1011
- . value
1012
- . unwrap ( ) ;
964
+ let account = config. rpc_client . get_token_account ( & address) ?. unwrap ( ) ;
1013
965
println ! ( ) ;
1014
966
println_name_value ( "Address:" , & address. to_string ( ) ) ;
1015
967
println_name_value (
@@ -1043,11 +995,7 @@ fn command_account_info(config: &Config, address: Pubkey) -> CommandResult {
1043
995
}
1044
996
1045
997
fn get_multisig ( config : & Config , address : & Pubkey ) -> Result < Multisig , Error > {
1046
- let account = config
1047
- . rpc_client
1048
- . get_account_with_commitment ( & address, config. commitment_config ) ?
1049
- . value
1050
- . ok_or ( format ! ( "account does not exist: {}" , address) ) ?;
998
+ let account = config. rpc_client . get_account ( & address) ?;
1051
999
Multisig :: unpack ( & account. data ) . map_err ( |e| e. into ( ) )
1052
1000
}
1053
1001
@@ -1709,11 +1657,13 @@ fn main() {
1709
1657
let multisigner_pubkeys = multisigner_ids. iter ( ) . collect :: < Vec < _ > > ( ) ;
1710
1658
1711
1659
Config {
1712
- rpc_client : RpcClient :: new ( json_rpc_url) ,
1660
+ rpc_client : RpcClient :: new_with_commitment (
1661
+ json_rpc_url,
1662
+ CommitmentConfig :: single_gossip ( ) ,
1663
+ ) ,
1713
1664
verbose,
1714
1665
owner,
1715
1666
fee_payer,
1716
- commitment_config : CommitmentConfig :: single_gossip ( ) ,
1717
1667
default_signer,
1718
1668
nonce_account,
1719
1669
nonce_authority,
@@ -1990,7 +1940,10 @@ fn main() {
1990
1940
} ;
1991
1941
let ( recent_blockhash, fee_calculator) = config
1992
1942
. blockhash_query
1993
- . get_blockhash_and_fee_calculator ( & config. rpc_client , config. commitment_config )
1943
+ . get_blockhash_and_fee_calculator (
1944
+ & config. rpc_client ,
1945
+ config. rpc_client . commitment ( ) ,
1946
+ )
1994
1947
. unwrap_or_else ( |e| {
1995
1948
eprintln ! ( "error: {}" , e) ;
1996
1949
exit ( 1 ) ;
@@ -2012,14 +1965,7 @@ fn main() {
2012
1965
transaction. try_sign ( & signer_info. signers , recent_blockhash) ?;
2013
1966
let signature = config
2014
1967
. rpc_client
2015
- . send_and_confirm_transaction_with_spinner_and_config (
2016
- & transaction,
2017
- config. commitment_config ,
2018
- RpcSendTransactionConfig {
2019
- preflight_commitment : Some ( config. commitment_config . commitment ) ,
2020
- ..RpcSendTransactionConfig :: default ( )
2021
- } ,
2022
- ) ?;
1968
+ . send_and_confirm_transaction_with_spinner ( & transaction) ?;
2023
1969
println ! ( "Signature: {}" , signature) ;
2024
1970
}
2025
1971
}
0 commit comments