remove from_account from stake_instruction (#4502)
This commit is contained in:
parent
482ef51502
commit
c56052ff16
|
@ -444,13 +444,13 @@ impl LocalCluster {
|
|||
.wait_for_balance(&stake_account_pubkey, Some(amount))
|
||||
.expect("get balance");
|
||||
|
||||
let mut transaction = Transaction::new_signed_instructions(
|
||||
&[from_account.as_ref(), &stake_account_keypair],
|
||||
let mut transaction = Transaction::new_signed_with_payer(
|
||||
vec![stake_instruction::delegate_stake(
|
||||
&from_account.pubkey(),
|
||||
&stake_account_pubkey,
|
||||
&vote_account_pubkey,
|
||||
)],
|
||||
Some(&from_account.pubkey()),
|
||||
&[from_account.as_ref(), &stake_account_keypair],
|
||||
client.get_recent_blockhash().unwrap().0,
|
||||
);
|
||||
client
|
||||
|
|
|
@ -167,9 +167,10 @@ pub(crate) mod tests {
|
|||
keypairs: &[&T],
|
||||
ixs: Vec<Instruction>,
|
||||
) {
|
||||
bank.process_transaction(&Transaction::new_signed_instructions(
|
||||
keypairs,
|
||||
bank.process_transaction(&Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&keypairs[0].pubkey()),
|
||||
keypairs,
|
||||
bank.last_blockhash(),
|
||||
))
|
||||
.unwrap();
|
||||
|
@ -204,7 +205,6 @@ pub(crate) mod tests {
|
|||
bank,
|
||||
&[from_account, &stake_account_keypair],
|
||||
vec![stake_instruction::delegate_stake(
|
||||
&from_account.pubkey(),
|
||||
&stake_account_pubkey,
|
||||
vote_pubkey,
|
||||
)],
|
||||
|
|
|
@ -58,10 +58,7 @@ pub fn create_delegate_account(
|
|||
Instruction::new(
|
||||
id(),
|
||||
&StakeInstruction::InitializeDelegate,
|
||||
vec![
|
||||
AccountMeta::new(*from_pubkey, true),
|
||||
AccountMeta::new(*staker_pubkey, false),
|
||||
],
|
||||
vec![AccountMeta::new(*staker_pubkey, false)],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
@ -82,22 +79,17 @@ pub fn create_mining_pool_account(
|
|||
Instruction::new(
|
||||
id(),
|
||||
&StakeInstruction::InitializeMiningPool,
|
||||
vec![
|
||||
AccountMeta::new(*from_pubkey, true),
|
||||
AccountMeta::new(*staker_pubkey, false),
|
||||
],
|
||||
vec![AccountMeta::new(*staker_pubkey, false)],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn redeem_vote_credits(
|
||||
from_pubkey: &Pubkey,
|
||||
mining_pool_pubkey: &Pubkey,
|
||||
stake_pubkey: &Pubkey,
|
||||
vote_pubkey: &Pubkey,
|
||||
) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*from_pubkey, true),
|
||||
AccountMeta::new(*mining_pool_pubkey, false),
|
||||
AccountMeta::new(*stake_pubkey, false),
|
||||
AccountMeta::new(*vote_pubkey, false),
|
||||
|
@ -105,13 +97,8 @@ pub fn redeem_vote_credits(
|
|||
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
||||
}
|
||||
|
||||
pub fn delegate_stake(
|
||||
from_pubkey: &Pubkey,
|
||||
stake_pubkey: &Pubkey,
|
||||
vote_pubkey: &Pubkey,
|
||||
) -> Instruction {
|
||||
pub fn delegate_stake(stake_pubkey: &Pubkey, vote_pubkey: &Pubkey) -> Instruction {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(*from_pubkey, true),
|
||||
AccountMeta::new(*stake_pubkey, true),
|
||||
AccountMeta::new(*vote_pubkey, false),
|
||||
];
|
||||
|
@ -128,14 +115,12 @@ pub fn process_instruction(
|
|||
trace!("process_instruction: {:?}", data);
|
||||
trace!("keyed_accounts: {:?}", keyed_accounts);
|
||||
|
||||
if keyed_accounts.len() < 2 {
|
||||
if keyed_accounts.is_empty() {
|
||||
Err(InstructionError::InvalidInstructionData)?;
|
||||
}
|
||||
|
||||
// 0th index is the account who paid for the transaction
|
||||
// TODO: Remove the 0th index from the instruction. The stake program doesn't care who paid.
|
||||
let (me, rest) = &mut keyed_accounts.split_at_mut(2);
|
||||
let me = &mut me[1];
|
||||
let (me, rest) = &mut keyed_accounts.split_at_mut(1);
|
||||
let me = &mut me[0];
|
||||
|
||||
// TODO: data-driven unpack and dispatch of KeyedAccounts
|
||||
match deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
|
||||
|
@ -197,7 +182,6 @@ mod tests {
|
|||
fn test_stake_process_instruction() {
|
||||
assert_eq!(
|
||||
process_instruction(&redeem_vote_credits(
|
||||
&Pubkey::default(),
|
||||
&Pubkey::default(),
|
||||
&Pubkey::default(),
|
||||
&Pubkey::default()
|
||||
|
@ -205,11 +189,7 @@ mod tests {
|
|||
Err(InstructionError::InvalidAccountData),
|
||||
);
|
||||
assert_eq!(
|
||||
process_instruction(&delegate_stake(
|
||||
&Pubkey::default(),
|
||||
&Pubkey::default(),
|
||||
&Pubkey::default()
|
||||
)),
|
||||
process_instruction(&delegate_stake(&Pubkey::default(), &Pubkey::default())),
|
||||
Err(InstructionError::InvalidAccountData),
|
||||
);
|
||||
}
|
||||
|
@ -236,10 +216,11 @@ mod tests {
|
|||
assert_eq!(
|
||||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&mut [
|
||||
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
],
|
||||
&mut [KeyedAccount::new(
|
||||
&Pubkey::default(),
|
||||
false,
|
||||
&mut Account::default()
|
||||
),],
|
||||
&serialize(&StakeInstruction::DelegateStake).unwrap(),
|
||||
),
|
||||
Err(InstructionError::InvalidInstructionData),
|
||||
|
@ -251,7 +232,6 @@ mod tests {
|
|||
&mut [
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
],
|
||||
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
||||
),
|
||||
|
@ -263,7 +243,6 @@ mod tests {
|
|||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&mut [
|
||||
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()), // from
|
||||
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
],
|
||||
|
@ -277,7 +256,6 @@ mod tests {
|
|||
super::process_instruction(
|
||||
&Pubkey::default(),
|
||||
&mut [
|
||||
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()), // from
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
||||
|
|
|
@ -544,7 +544,12 @@ fn process_create_stake_account(
|
|||
staking_account_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let mut tx = Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair],
|
||||
recent_blockhash,
|
||||
);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
@ -561,7 +566,12 @@ fn process_create_mining_pool_account(
|
|||
mining_pool_account_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let mut tx = Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair],
|
||||
recent_blockhash,
|
||||
);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
@ -574,15 +584,17 @@ fn process_delegate_stake(
|
|||
) -> ProcessResult {
|
||||
let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||
let ixs = vec![stake_instruction::delegate_stake(
|
||||
&config.keypair.pubkey(),
|
||||
&staking_account_keypair.pubkey(),
|
||||
voting_account_pubkey,
|
||||
)];
|
||||
let mut tx = Transaction::new_signed_instructions(
|
||||
&[&config.keypair, &staking_account_keypair],
|
||||
|
||||
let mut tx = Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair, &staking_account_keypair],
|
||||
recent_blockhash,
|
||||
);
|
||||
|
||||
let signature_str = rpc_client
|
||||
.send_and_confirm_transaction(&mut tx, &[&config.keypair, &staking_account_keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
|
@ -597,12 +609,16 @@ fn process_redeem_vote_credits(
|
|||
) -> ProcessResult {
|
||||
let (recent_blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
|
||||
let ixs = vec![stake_instruction::redeem_vote_credits(
|
||||
&config.keypair.pubkey(),
|
||||
mining_pool_account_pubkey,
|
||||
staking_account_pubkey,
|
||||
voting_account_pubkey,
|
||||
)];
|
||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||
let mut tx = Transaction::new_signed_with_payer(
|
||||
ixs,
|
||||
Some(&config.keypair.pubkey()),
|
||||
&[&config.keypair],
|
||||
recent_blockhash,
|
||||
);
|
||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair])?;
|
||||
Ok(signature_str.to_string())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue