Minor config -> rpc_client refactor

This commit is contained in:
Michael Vines 2021-03-30 13:47:09 -07:00
parent 9e4f190633
commit 19e1161be2
1 changed files with 14 additions and 14 deletions

View File

@ -94,14 +94,13 @@ fn check_fee_payer_balance(config: &Config, required_balance: u64) -> Result<(),
} }
} }
fn get_authority_accounts(config: &Config, authority: &Pubkey) -> Vec<(Pubkey, Account)> { fn get_authority_accounts(rpc_client: &RpcClient, authority: &Pubkey) -> Vec<(Pubkey, Account)> {
config rpc_client
.rpc_client
.get_program_accounts_with_config( .get_program_accounts_with_config(
&stake_program_id(), &stake_program_id(),
RpcProgramAccountsConfig { RpcProgramAccountsConfig {
filters: Some(vec![RpcFilterType::Memcmp(Memcmp { filters: Some(vec![RpcFilterType::Memcmp(Memcmp {
offset: 44, // 44 is Withdrawer authority offset in stake accoun stake offset: 44, // 44 is Withdrawer authority offset in stake account stake
bytes: MemcmpEncodedBytes::Binary( bytes: MemcmpEncodedBytes::Binary(
bs58::encode(authority.to_bytes()).into_string(), bs58::encode(authority.to_bytes()).into_string(),
), ),
@ -692,7 +691,7 @@ fn command_list(config: &Config, pool: &Pubkey) -> CommandResult {
) )
.unwrap(); .unwrap();
let accounts = get_authority_accounts(config, &pool_withdraw_authority); let accounts = get_authority_accounts(&config.rpc_client, &pool_withdraw_authority);
if accounts.is_empty() { if accounts.is_empty() {
return Err("No accounts found.".to_string().into()); return Err("No accounts found.".to_string().into());
@ -785,20 +784,17 @@ struct WithdrawAccount {
} }
fn prepare_withdraw_accounts( fn prepare_withdraw_accounts(
config: &Config, rpc_client: &RpcClient,
stake_pool: &StakePool, stake_pool: &StakePool,
pool_withdraw_authority: &Pubkey, pool_withdraw_authority: &Pubkey,
pool_amount: u64, pool_amount: u64,
) -> Result<Vec<WithdrawAccount>, Error> { ) -> Result<Vec<WithdrawAccount>, Error> {
let mut accounts = get_authority_accounts(config, &pool_withdraw_authority); let mut accounts = get_authority_accounts(rpc_client, &pool_withdraw_authority);
if accounts.is_empty() { if accounts.is_empty() {
return Err("No accounts found.".to_string().into()); return Err("No accounts found.".to_string().into());
} }
let min_balance = config let min_balance = rpc_client.get_minimum_balance_for_rent_exemption(STAKE_STATE_LEN)? + 1;
.rpc_client let pool_mint_data = rpc_client.get_account_data(&stake_pool.pool_mint)?;
.get_minimum_balance_for_rent_exemption(STAKE_STATE_LEN)?
+ 1;
let pool_mint_data = config.rpc_client.get_account_data(&stake_pool.pool_mint)?;
let pool_mint = TokenMint::unpack_from_slice(pool_mint_data.as_slice()).unwrap(); let pool_mint = TokenMint::unpack_from_slice(pool_mint_data.as_slice()).unwrap();
pick_withdraw_accounts( pick_withdraw_accounts(
&mut accounts, &mut accounts,
@ -905,8 +901,12 @@ fn command_withdraw(
} }
// Get the list of accounts to withdraw from // Get the list of accounts to withdraw from
let withdraw_accounts: Vec<WithdrawAccount> = let withdraw_accounts: Vec<WithdrawAccount> = prepare_withdraw_accounts(
prepare_withdraw_accounts(config, &pool_data, &pool_withdraw_authority, pool_amount)?; &config.rpc_client,
&pool_data,
&pool_withdraw_authority,
pool_amount,
)?;
// Construct transaction to withdraw from withdraw_accounts account list // Construct transaction to withdraw from withdraw_accounts account list
let mut instructions: Vec<Instruction> = vec![]; let mut instructions: Vec<Instruction> = vec![];