@@ -53,6 +53,7 @@ struct Config {
53
53
verbose : bool ,
54
54
owner : Box < dyn Signer > ,
55
55
fee_payer : Box < dyn Signer > ,
56
+ dry_run : bool ,
56
57
}
57
58
58
59
type Error = Box < dyn std:: error:: Error > ;
@@ -511,6 +512,9 @@ fn command_deposit(
511
512
let stake_data = config. rpc_client . get_account_data ( & stake) ?;
512
513
let stake_data: StakeState =
513
514
deserialize ( stake_data. as_slice ( ) ) . or ( Err ( "Invalid stake account data" ) ) ?;
515
+ if config. verbose {
516
+ println ! ( "Depositing stake account {:?}" , stake_data) ;
517
+ }
514
518
let validator: Pubkey = match stake_data {
515
519
StakeState :: Stake ( _, stake) => Ok ( stake. delegation . voter_pubkey ) ,
516
520
_ => Err ( "Wrong stake account state, must be delegated to validator" ) ,
@@ -529,7 +533,16 @@ fn command_deposit(
529
533
// Calculate validator stake account address linked to the pool
530
534
let ( validator_stake_account, _) =
531
535
PoolProcessor :: find_stake_address_for_validator ( & spl_stake_pool:: id ( ) , & validator, pool) ;
532
- println ! ( "Depositing into stake account {}" , validator_stake_account) ;
536
+ let validator_stake_data = config
537
+ . rpc_client
538
+ . get_account_data ( & validator_stake_account) ?;
539
+ let validator_stake_data: StakeState =
540
+ deserialize ( validator_stake_data. as_slice ( ) ) . or ( Err ( "Invalid stake account data" ) ) ?;
541
+ if config. verbose {
542
+ println ! ( "Depositing into stake account {:?}" , validator_stake_data) ;
543
+ } else {
544
+ println ! ( "Depositing into stake account {}" , validator_stake_account) ;
545
+ }
533
546
534
547
let mut instructions: Vec < Instruction > = vec ! [ ] ;
535
548
let mut signers = vec ! [ config. fee_payer. as_ref( ) , config. owner. as_ref( ) ] ;
@@ -617,6 +630,21 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
617
630
let pool_data = config. rpc_client . get_account_data ( & pool) ?;
618
631
let pool_data = StakePool :: deserialize ( pool_data. as_slice ( ) ) . unwrap ( ) ;
619
632
633
+ if config. verbose {
634
+ let validator_list = config
635
+ . rpc_client
636
+ . get_account_data ( & pool_data. validator_stake_list ) ?;
637
+ let validator_stake_list_data =
638
+ ValidatorStakeList :: deserialize ( & validator_list. as_slice ( ) ) ?;
639
+ println ! ( "Current validator list" ) ;
640
+ for validator in validator_stake_list_data. validators {
641
+ println ! (
642
+ "Vote: {}\t Balance: {}\t Epoch: {}" ,
643
+ validator. validator_account, validator. balance, validator. last_update_epoch
644
+ ) ;
645
+ }
646
+ }
647
+
620
648
let pool_withdraw_authority: Pubkey = PoolProcessor :: authority_id (
621
649
& spl_stake_pool:: id ( ) ,
622
650
pool,
@@ -633,9 +661,16 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
633
661
634
662
let mut total_balance: u64 = 0 ;
635
663
for ( pubkey, account) in accounts {
664
+ let stake_data: StakeState =
665
+ deserialize ( account. data . as_slice ( ) ) . or ( Err ( "Invalid stake account data" ) ) ?;
636
666
let balance = account. lamports ;
637
667
total_balance += balance;
638
- println ! ( "{}\t {} SOL" , pubkey, lamports_to_sol( balance) ) ;
668
+ println ! (
669
+ "Pubkey: {}\t Vote: {}\t {} SOL" ,
670
+ pubkey,
671
+ stake_data. delegation( ) . unwrap( ) . voter_pubkey,
672
+ lamports_to_sol( balance)
673
+ ) ;
639
674
}
640
675
println ! ( "Total: {} SOL" , lamports_to_sol( total_balance) ) ;
641
676
@@ -654,14 +689,19 @@ fn command_update(config: &Config, pool: &Pubkey) -> CommandResult {
654
689
655
690
let epoch_info = config. rpc_client . get_epoch_info ( ) ?;
656
691
657
- let accounts_to_update: Vec < & Pubkey > = validator_stake_list_data
692
+ let accounts_to_update: Vec < Pubkey > = validator_stake_list_data
658
693
. validators
659
694
. iter ( )
660
695
. filter_map ( |item| {
661
696
if item. last_update_epoch >= epoch_info. epoch {
662
697
None
663
698
} else {
664
- Some ( & item. validator_account )
699
+ let ( stake_account, _) = PoolProcessor :: find_stake_address_for_validator (
700
+ & spl_stake_pool:: id ( ) ,
701
+ & item. validator_account ,
702
+ & pool,
703
+ ) ;
704
+ Some ( stake_account)
665
705
}
666
706
} )
667
707
. collect ( ) ;
@@ -1033,6 +1073,13 @@ fn main() {
1033
1073
. global ( true )
1034
1074
. help ( "Show additional information" ) ,
1035
1075
)
1076
+ . arg (
1077
+ Arg :: with_name ( "dry_run" )
1078
+ . long ( "dry-run" )
1079
+ . takes_value ( false )
1080
+ . global ( true )
1081
+ . help ( "Simluate transaction instead of executing" ) ,
1082
+ )
1036
1083
. arg (
1037
1084
Arg :: with_name ( "json_rpc_url" )
1038
1085
. long ( "url" )
@@ -1354,12 +1401,14 @@ fn main() {
1354
1401
exit ( 1 ) ;
1355
1402
} ) ;
1356
1403
let verbose = matches. is_present ( "verbose" ) ;
1404
+ let dry_run = matches. is_present ( "dry_run" ) ;
1357
1405
1358
1406
Config {
1359
1407
rpc_client : RpcClient :: new_with_commitment ( json_rpc_url, CommitmentConfig :: confirmed ( ) ) ,
1360
1408
verbose,
1361
1409
owner,
1362
1410
fee_payer,
1411
+ dry_run,
1363
1412
}
1364
1413
} ;
1365
1414
@@ -1439,10 +1488,15 @@ fn main() {
1439
1488
}
1440
1489
. and_then ( |transaction| {
1441
1490
if let Some ( transaction) = transaction {
1442
- let signature = config
1443
- . rpc_client
1444
- . send_and_confirm_transaction_with_spinner ( & transaction) ?;
1445
- println ! ( "Signature: {}" , signature) ;
1491
+ if config. dry_run {
1492
+ let result = config. rpc_client . simulate_transaction ( & transaction) ?;
1493
+ println ! ( "Simulate result: {:?}" , result) ;
1494
+ } else {
1495
+ let signature = config
1496
+ . rpc_client
1497
+ . send_and_confirm_transaction_with_spinner ( & transaction) ?;
1498
+ println ! ( "Signature: {}" , signature) ;
1499
+ }
1446
1500
}
1447
1501
Ok ( ( ) )
1448
1502
} )
0 commit comments