Merge stake::withdraw instructions (#9617)
This commit is contained in:
parent
b1a0abc7a6
commit
a6ad660e5e
|
@ -1002,6 +1002,7 @@ pub fn process_withdraw_stake(
|
|||
&withdraw_authority.pubkey(),
|
||||
destination_account_pubkey,
|
||||
lamports,
|
||||
None,
|
||||
)];
|
||||
|
||||
let fee_payer = config.signers[fee_payer];
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
|
|
|
@ -450,6 +450,7 @@ mod test {
|
|||
&stake3_keypair.pubkey(),
|
||||
&payer.pubkey(),
|
||||
one_sol,
|
||||
None,
|
||||
)],
|
||||
Some(&payer.pubkey()),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue