30
30
solana_remote_wallet:: remote_wallet:: RemoteWalletManager ,
31
31
solana_sdk:: {
32
32
commitment_config:: CommitmentConfig ,
33
+ hash:: Hash ,
33
34
native_token:: { self , Sol } ,
34
35
signature:: { Keypair , Signer } ,
35
36
signers:: Signers ,
@@ -135,6 +136,12 @@ fn get_signer(
135
136
} )
136
137
}
137
138
139
+ fn get_latest_blockhash ( client : & RpcClient ) -> Result < Hash , Error > {
140
+ Ok ( client
141
+ . get_latest_blockhash_with_commitment ( CommitmentConfig :: confirmed ( ) ) ?
142
+ . 0 )
143
+ }
144
+
138
145
fn send_transaction_no_wait (
139
146
config : & Config ,
140
147
transaction : Transaction ,
@@ -170,7 +177,7 @@ fn checked_transaction_with_signers<T: Signers>(
170
177
instructions : & [ Instruction ] ,
171
178
signers : & T ,
172
179
) -> Result < Transaction , Error > {
173
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
180
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
174
181
let transaction = Transaction :: new_signed_with_payer (
175
182
instructions,
176
183
Some ( & config. fee_payer . pubkey ( ) ) ,
@@ -365,27 +372,10 @@ fn command_create_pool(
365
372
Some ( & config. fee_payer . pubkey ( ) ) ,
366
373
) ;
367
374
368
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
369
- check_fee_payer_balance (
370
- config,
371
- total_rent_free_balances
372
- + config
373
- . rpc_client
374
- . get_fee_for_message ( setup_transaction. message ( ) ) ?
375
- + config
376
- . rpc_client
377
- . get_fee_for_message ( initialize_transaction. message ( ) ) ?,
378
- ) ?;
375
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
379
376
let mut setup_signers = vec ! [ config. fee_payer. as_ref( ) , & mint_keypair, & reserve_keypair] ;
380
377
unique_signers ! ( setup_signers) ;
381
378
setup_transaction. sign ( & setup_signers, recent_blockhash) ;
382
- send_transaction ( config, setup_transaction) ?;
383
-
384
- println ! (
385
- "Creating stake pool {} with validator list {}" ,
386
- stake_pool_keypair. pubkey( ) ,
387
- validator_list_keypair. pubkey( )
388
- ) ;
389
379
let mut initialize_signers = vec ! [
390
380
config. fee_payer. as_ref( ) ,
391
381
& stake_pool_keypair,
@@ -405,6 +395,23 @@ fn command_create_pool(
405
395
unique_signers ! ( initialize_signers) ;
406
396
initialize_transaction. sign ( & initialize_signers, recent_blockhash) ;
407
397
}
398
+ check_fee_payer_balance (
399
+ config,
400
+ total_rent_free_balances
401
+ + config
402
+ . rpc_client
403
+ . get_fee_for_message ( setup_transaction. message ( ) ) ?
404
+ + config
405
+ . rpc_client
406
+ . get_fee_for_message ( initialize_transaction. message ( ) ) ?,
407
+ ) ?;
408
+ send_transaction ( config, setup_transaction) ?;
409
+
410
+ println ! (
411
+ "Creating stake pool {} with validator list {}" ,
412
+ stake_pool_keypair. pubkey( ) ,
413
+ validator_list_keypair. pubkey( )
414
+ ) ;
408
415
send_transaction ( config, initialize_transaction) ?;
409
416
Ok ( ( ) )
410
417
}
@@ -761,16 +768,16 @@ fn command_deposit_stake(
761
768
let mut transaction =
762
769
Transaction :: new_with_payer ( & instructions, Some ( & config. fee_payer . pubkey ( ) ) ) ;
763
770
764
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
771
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
772
+ unique_signers ! ( signers) ;
773
+ transaction. sign ( & signers, recent_blockhash) ;
765
774
check_fee_payer_balance (
766
775
config,
767
776
total_rent_free_balances
768
777
+ config
769
778
. rpc_client
770
779
. get_fee_for_message ( transaction. message ( ) ) ?,
771
780
) ?;
772
- unique_signers ! ( signers) ;
773
- transaction. sign ( & signers, recent_blockhash) ;
774
781
send_transaction ( config, transaction) ?;
775
782
Ok ( ( ) )
776
783
}
@@ -802,7 +809,7 @@ fn command_deposit_all_stake(
802
809
& mut total_rent_free_balances,
803
810
) ) ;
804
811
if !create_token_account_instructions. is_empty ( ) {
805
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
812
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
806
813
let transaction = Transaction :: new_signed_with_payer (
807
814
& create_token_account_instructions,
808
815
Some ( & config. fee_payer . pubkey ( ) ) ,
@@ -903,7 +910,7 @@ fn command_deposit_all_stake(
903
910
)
904
911
} ;
905
912
906
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
913
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
907
914
let transaction = Transaction :: new_signed_with_payer (
908
915
& instructions,
909
916
Some ( & config. fee_payer . pubkey ( ) ) ,
@@ -1034,16 +1041,16 @@ fn command_deposit_sol(
1034
1041
let mut transaction =
1035
1042
Transaction :: new_with_payer ( & instructions, Some ( & config. fee_payer . pubkey ( ) ) ) ;
1036
1043
1037
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
1044
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
1045
+ unique_signers ! ( signers) ;
1046
+ transaction. sign ( & signers, recent_blockhash) ;
1038
1047
check_fee_payer_balance (
1039
1048
config,
1040
1049
total_rent_free_balances
1041
1050
+ config
1042
1051
. rpc_client
1043
1052
. get_fee_for_message ( transaction. message ( ) ) ?,
1044
1053
) ?;
1045
- unique_signers ! ( signers) ;
1046
- transaction. sign ( & signers, recent_blockhash) ;
1047
1054
send_transaction ( config, transaction) ?;
1048
1055
Ok ( ( ) )
1049
1056
}
@@ -1495,19 +1502,19 @@ fn command_withdraw_stake(
1495
1502
let mut transaction =
1496
1503
Transaction :: new_with_payer ( & instructions, Some ( & config. fee_payer . pubkey ( ) ) ) ;
1497
1504
1498
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
1505
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
1506
+ for new_stake_keypair in & new_stake_keypairs {
1507
+ signers. push ( new_stake_keypair) ;
1508
+ }
1509
+ unique_signers ! ( signers) ;
1510
+ transaction. sign ( & signers, recent_blockhash) ;
1499
1511
check_fee_payer_balance (
1500
1512
config,
1501
1513
total_rent_free_balances
1502
1514
+ config
1503
1515
. rpc_client
1504
1516
. get_fee_for_message ( transaction. message ( ) ) ?,
1505
1517
) ?;
1506
- for new_stake_keypair in & new_stake_keypairs {
1507
- signers. push ( new_stake_keypair) ;
1508
- }
1509
- unique_signers ! ( signers) ;
1510
- transaction. sign ( & signers, recent_blockhash) ;
1511
1518
send_transaction ( config, transaction) ?;
1512
1519
Ok ( ( ) )
1513
1520
}
@@ -1620,15 +1627,15 @@ fn command_withdraw_sol(
1620
1627
let mut transaction =
1621
1628
Transaction :: new_with_payer ( & instructions, Some ( & config. fee_payer . pubkey ( ) ) ) ;
1622
1629
1623
- let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
1630
+ let recent_blockhash = get_latest_blockhash ( & config. rpc_client ) ?;
1631
+ unique_signers ! ( signers) ;
1632
+ transaction. sign ( & signers, recent_blockhash) ;
1624
1633
check_fee_payer_balance (
1625
1634
config,
1626
1635
config
1627
1636
. rpc_client
1628
1637
. get_fee_for_message ( transaction. message ( ) ) ?,
1629
1638
) ?;
1630
- unique_signers ! ( signers) ;
1631
- transaction. sign ( & signers, recent_blockhash) ;
1632
1639
send_transaction ( config, transaction) ?;
1633
1640
Ok ( ( ) )
1634
1641
}
0 commit comments