Merge stake::withdraw instructions (#9617)

This commit is contained in:
Greg Fitzgerald 2020-04-20 18:16:50 -06:00 committed by GitHub
parent b1a0abc7a6
commit a6ad660e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 20 deletions

View File

@ -1002,6 +1002,7 @@ pub fn process_withdraw_stake(
&withdraw_authority.pubkey(),
destination_account_pubkey,
lamports,
None,
)];
let fee_payer = config.signers[fee_payer];

View File

@ -327,8 +327,9 @@ pub fn withdraw(
withdrawer_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
custodian_pubkey: Option<&Pubkey>,
) -> Instruction {
let account_metas = vec![
let mut account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*to_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
@ -336,24 +337,9 @@ pub fn withdraw(
]
.with_signer(withdrawer_pubkey);
Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas)
}
pub fn withdraw_early(
stake_pubkey: &Pubkey,
withdrawer_pubkey: &Pubkey,
to_pubkey: &Pubkey,
lamports: u64,
custodian_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*to_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
]
.with_signer(withdrawer_pubkey)
.with_signer(custodian_pubkey);
if let Some(custodian_pubkey) = custodian_pubkey {
account_metas = account_metas.with_signer(custodian_pubkey)
}
Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas)
}
@ -537,7 +523,8 @@ mod tests {
&Pubkey::default(),
&Pubkey::default(),
&Pubkey::new_rand(),
100
100,
None,
)),
Err(InstructionError::InvalidAccountData),
);

View File

@ -224,6 +224,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&Pubkey::new_rand(),
1,
None,
)],
Some(&mint_pubkey),
);
@ -318,6 +319,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&Pubkey::new_rand(),
lamports / 2 - split_staked + 1,
None,
)],
Some(&mint_pubkey),
);
@ -339,6 +341,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&Pubkey::new_rand(),
lamports / 2,
None,
)],
Some(&mint_pubkey),
);
@ -354,6 +357,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&Pubkey::new_rand(),
lamports / 2 - split_staked,
None,
)],
Some(&mint_pubkey),
);
@ -378,6 +382,7 @@ fn test_stake_account_lifetime() {
&stake_pubkey,
&Pubkey::new_rand(),
split_staked,
None,
)],
Some(&mint_pubkey),
);

View File

@ -450,6 +450,7 @@ mod test {
&stake3_keypair.pubkey(),
&payer.pubkey(),
one_sol,
None,
)],
Some(&payer.pubkey()),
),