Add custodian option to withdraw-stake command (bp #9662) (#9675)

* Merge stake::withdraw instructions (#9617)

* Add custodian option to withdraw-stake command (#9662)

automerge

Co-authored-by: Greg Fitzgerald <greg@solana.com>
This commit is contained in:
mergify[bot]
2020-04-22 20:30:46 -07:00
committed by GitHub
parent 4509579e10
commit c0b250285a
6 changed files with 74 additions and 20 deletions

View File

@@ -328,8 +328,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),
@@ -337,24 +338,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)
}
@@ -535,7 +521,8 @@ mod tests {
&Pubkey::default(),
&Pubkey::default(),
&Pubkey::new_rand(),
100
100,
None,
)),
Err(InstructionError::InvalidAccountData),
);