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(), &withdraw_authority.pubkey(),
destination_account_pubkey, destination_account_pubkey,
lamports, lamports,
None,
)]; )];
let fee_payer = config.signers[fee_payer]; let fee_payer = config.signers[fee_payer];

View File

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

View File

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

View File

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