@@ -60,10 +60,11 @@ struct Config {
60
60
owner : Box < dyn Signer > ,
61
61
fee_payer : Box < dyn Signer > ,
62
62
dry_run : bool ,
63
+ no_update : bool ,
63
64
}
64
65
65
66
type Error = Box < dyn std:: error:: Error > ;
66
- type CommandResult = Result < Option < Transaction > , Error > ;
67
+ type CommandResult = Result < ( ) , Error > ;
67
68
68
69
const STAKE_STATE_LEN : usize = 200 ;
69
70
const MAX_ACCOUNTS_TO_UPDATE : usize = 10 ;
@@ -115,6 +116,22 @@ fn get_authority_accounts(config: &Config, authority: &Pubkey) -> Vec<(Pubkey, A
115
116
. unwrap ( )
116
117
}
117
118
119
+ fn send_transaction (
120
+ config : & Config ,
121
+ transaction : Transaction ,
122
+ ) -> solana_client:: client_error:: Result < ( ) > {
123
+ if config. dry_run {
124
+ let result = config. rpc_client . simulate_transaction ( & transaction) ?;
125
+ println ! ( "Simulate result: {:?}" , result) ;
126
+ } else {
127
+ let signature = config
128
+ . rpc_client
129
+ . send_and_confirm_transaction_with_spinner ( & transaction) ?;
130
+ println ! ( "Signature: {}" , signature) ;
131
+ }
132
+ Ok ( ( ) )
133
+ }
134
+
118
135
fn command_create_pool ( config : & Config , fee : PoolFee , max_validators : u32 ) -> CommandResult {
119
136
let mint_account = Keypair :: new ( ) ;
120
137
println ! ( "Creating mint {}" , mint_account. pubkey( ) ) ;
@@ -242,7 +259,8 @@ fn command_create_pool(config: &Config, fee: PoolFee, max_validators: u32) -> Co
242
259
] ;
243
260
unique_signers ! ( signers) ;
244
261
transaction. sign ( & signers, recent_blockhash) ;
245
- Ok ( Some ( transaction) )
262
+ send_transaction ( & config, transaction) ?;
263
+ Ok ( ( ) )
246
264
}
247
265
248
266
fn command_vsa_create ( config : & Config , pool : & Pubkey , vote_account : & Pubkey ) -> CommandResult {
@@ -275,7 +293,8 @@ fn command_vsa_create(config: &Config, pool: &Pubkey, vote_account: &Pubkey) ->
275
293
let ( recent_blockhash, fee_calculator) = config. rpc_client . get_recent_blockhash ( ) ?;
276
294
check_fee_payer_balance ( config, fee_calculator. calculate_fee ( & transaction. message ( ) ) ) ?;
277
295
transaction. sign ( & [ config. fee_payer . as_ref ( ) ] , recent_blockhash) ;
278
- Ok ( Some ( transaction) )
296
+ send_transaction ( & config, transaction) ?;
297
+ Ok ( ( ) )
279
298
}
280
299
281
300
fn command_vsa_add (
@@ -288,6 +307,10 @@ fn command_vsa_add(
288
307
return Err ( "Stake account is not active." . into ( ) ) ;
289
308
}
290
309
310
+ if !config. no_update {
311
+ command_update ( config, pool) ?;
312
+ }
313
+
291
314
// Get stake pool state
292
315
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
293
316
let pool_data = StakePool :: try_from_slice ( pool_data. as_slice ( ) ) . unwrap ( ) ;
@@ -369,7 +392,8 @@ fn command_vsa_add(
369
392
) ?;
370
393
unique_signers ! ( signers) ;
371
394
transaction. sign ( & signers, recent_blockhash) ;
372
- Ok ( Some ( transaction) )
395
+ send_transaction ( & config, transaction) ?;
396
+ Ok ( ( ) )
373
397
}
374
398
375
399
fn command_vsa_remove (
@@ -379,6 +403,10 @@ fn command_vsa_remove(
379
403
withdraw_from : & Pubkey ,
380
404
new_authority : & Option < Pubkey > ,
381
405
) -> CommandResult {
406
+ if !config. no_update {
407
+ command_update ( config, pool) ?;
408
+ }
409
+
382
410
// Get stake pool state
383
411
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
384
412
let pool_data: StakePool = StakePool :: try_from_slice ( pool_data. as_slice ( ) ) . unwrap ( ) ;
@@ -453,7 +481,8 @@ fn command_vsa_remove(
453
481
& [ config. fee_payer . as_ref ( ) , config. owner . as_ref ( ) ] ,
454
482
recent_blockhash,
455
483
) ;
456
- Ok ( Some ( transaction) )
484
+ send_transaction ( & config, transaction) ?;
485
+ Ok ( ( ) )
457
486
}
458
487
459
488
fn unwrap_create_token_account < F > (
@@ -509,6 +538,10 @@ fn command_deposit(
509
538
stake : & Pubkey ,
510
539
token_receiver : & Option < Pubkey > ,
511
540
) -> CommandResult {
541
+ if !config. no_update {
542
+ command_update ( config, pool) ?;
543
+ }
544
+
512
545
// Get stake pool state
513
546
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
514
547
let pool_data: StakePool = StakePool :: try_from_slice ( pool_data. as_slice ( ) ) . unwrap ( ) ;
@@ -627,7 +660,8 @@ fn command_deposit(
627
660
) ?;
628
661
unique_signers ! ( signers) ;
629
662
transaction. sign ( & signers, recent_blockhash) ;
630
- Ok ( Some ( transaction) )
663
+ send_transaction ( & config, transaction) ?;
664
+ Ok ( ( ) )
631
665
}
632
666
633
667
fn command_list ( config : & Config , pool : & Pubkey ) -> CommandResult {
@@ -679,7 +713,7 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
679
713
}
680
714
println ! ( "Total: {}" , Sol ( total_balance) ) ;
681
715
682
- Ok ( None )
716
+ Ok ( ( ) )
683
717
}
684
718
685
719
fn command_update ( config : & Config , pool : & Pubkey ) -> CommandResult {
@@ -723,8 +757,9 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
723
757
724
758
if instructions. is_empty ( ) && pool_data. last_update_epoch == epoch_info. epoch {
725
759
println ! ( "Stake pool balances are up to date, no update required." ) ;
726
- Ok ( None )
760
+ Ok ( ( ) )
727
761
} else {
762
+ println ! ( "Updating stake pool..." ) ;
728
763
instructions. push ( update_pool_balance (
729
764
& spl_stake_pool:: id ( ) ,
730
765
pool,
@@ -737,7 +772,8 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
737
772
let ( recent_blockhash, fee_calculator) = config. rpc_client . get_recent_blockhash ( ) ?;
738
773
check_fee_payer_balance ( config, fee_calculator. calculate_fee ( & transaction. message ( ) ) ) ?;
739
774
transaction. sign ( & [ config. fee_payer . as_ref ( ) ] , recent_blockhash) ;
740
- Ok ( Some ( transaction) )
775
+ send_transaction ( & config, transaction) ?;
776
+ Ok ( ( ) )
741
777
}
742
778
}
743
779
@@ -829,6 +865,10 @@ fn command_withdraw(
829
865
withdraw_from : & Pubkey ,
830
866
stake_receiver_param : & Option < Pubkey > ,
831
867
) -> CommandResult {
868
+ if !config. no_update {
869
+ command_update ( config, pool) ?;
870
+ }
871
+
832
872
// Get stake pool state
833
873
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
834
874
let pool_data = StakePool :: try_from_slice ( pool_data. as_slice ( ) ) . unwrap ( ) ;
@@ -959,8 +999,8 @@ fn command_withdraw(
959
999
) ?;
960
1000
unique_signers ! ( signers) ;
961
1001
transaction. sign ( & signers, recent_blockhash) ;
962
-
963
- Ok ( Some ( transaction ) )
1002
+ send_transaction ( & config , transaction ) ? ;
1003
+ Ok ( ( ) )
964
1004
}
965
1005
966
1006
fn command_set_owner (
@@ -1014,7 +1054,8 @@ fn command_set_owner(
1014
1054
let mut signers = vec ! [ config. fee_payer. as_ref( ) , config. owner. as_ref( ) ] ;
1015
1055
unique_signers ! ( signers) ;
1016
1056
transaction. sign ( & signers, recent_blockhash) ;
1017
- Ok ( Some ( transaction) )
1057
+ send_transaction ( & config, transaction) ?;
1058
+ Ok ( ( ) )
1018
1059
}
1019
1060
1020
1061
fn main ( ) {
@@ -1051,6 +1092,13 @@ fn main() {
1051
1092
. global ( true )
1052
1093
. help ( "Simluate transaction instead of executing" ) ,
1053
1094
)
1095
+ . arg (
1096
+ Arg :: with_name ( "no_update" )
1097
+ . long ( "no-update" )
1098
+ . takes_value ( false )
1099
+ . global ( true )
1100
+ . help ( "Do not automatically update the stake pool if needed" ) ,
1101
+ )
1054
1102
. arg (
1055
1103
Arg :: with_name ( "json_rpc_url" )
1056
1104
. long ( "url" )
@@ -1354,13 +1402,15 @@ fn main() {
1354
1402
} ) ;
1355
1403
let verbose = matches. is_present ( "verbose" ) ;
1356
1404
let dry_run = matches. is_present ( "dry_run" ) ;
1405
+ let no_update = matches. is_present ( "no_update" ) ;
1357
1406
1358
1407
Config {
1359
1408
rpc_client : RpcClient :: new_with_commitment ( json_rpc_url, CommitmentConfig :: confirmed ( ) ) ,
1360
1409
verbose,
1361
1410
owner,
1362
1411
fee_payer,
1363
1412
dry_run,
1413
+ no_update,
1364
1414
}
1365
1415
} ;
1366
1416
@@ -1439,20 +1489,6 @@ fn main() {
1439
1489
}
1440
1490
_ => unreachable ! ( ) ,
1441
1491
}
1442
- . and_then ( |transaction| {
1443
- if let Some ( transaction) = transaction {
1444
- if config. dry_run {
1445
- let result = config. rpc_client . simulate_transaction ( & transaction) ?;
1446
- println ! ( "Simulate result: {:?}" , result) ;
1447
- } else {
1448
- let signature = config
1449
- . rpc_client
1450
- . send_and_confirm_transaction_with_spinner ( & transaction) ?;
1451
- println ! ( "Signature: {}" , signature) ;
1452
- }
1453
- }
1454
- Ok ( ( ) )
1455
- } )
1456
1492
. map_err ( |err| {
1457
1493
eprintln ! ( "{}" , err) ;
1458
1494
exit ( 1 ) ;
0 commit comments