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