Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Correct comment stating lockup gates stake authorize ixs (#10063)
Browse files Browse the repository at this point in the history
* Correct old comment stating lockup gates stake authorize ixs

* Delete dead stake code
  • Loading branch information
jstarry authored May 15, 2020
1 parent 6a6c5f1 commit b762319
Showing 1 changed file with 2 additions and 53 deletions.
55 changes: 2 additions & 53 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,11 @@ pub enum StakeAuthorize {

#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
pub struct Lockup {
/// UnixTimestamp at which this stake will allow withdrawal, or
/// changes to authorized staker or withdrawer, unless the
/// UnixTimestamp at which this stake will allow withdrawal, unless the
/// transaction is signed by the custodian
pub unix_timestamp: UnixTimestamp,
/// epoch height at which this stake will allow withdrawal, or
/// changes to authorized staker or withdrawer, unless the
/// epoch height at which this stake will allow withdrawal, unless the
/// transaction is signed by the custodian
/// to the custodian
pub epoch: Epoch,
/// custodian signature on a transaction exempts the operation from
/// lockup constraints
Expand Down Expand Up @@ -153,21 +150,6 @@ impl Meta {
}
Ok(())
}

pub fn authorize_withdraw(
&mut self,
authority: &Pubkey,
signers: &HashSet<Pubkey>,
clock: &Clock,
) -> Result<(), InstructionError> {
// verify that lockup has expired or that the authorization
// is *also* signed by the custodian
if self.lockup.is_in_force(clock, signers) {
return Err(StakeError::LockupInForce.into());
}
self.authorized
.authorize(signers, authority, StakeAuthorize::Withdrawer)
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -949,39 +931,6 @@ mod tests {
);
}

#[test]
fn test_meta_authorize_withdraw() {
let staker = Pubkey::new_rand();
let custodian = Pubkey::new_rand();
let mut meta = Meta {
authorized: Authorized::auto(&staker),
lockup: Lockup {
epoch: 0,
unix_timestamp: 0,
custodian,
},
..Meta::default()
};
// verify sig check
let mut signers = HashSet::new();
signers.insert(staker);
let mut clock = Clock::default();

// verify lockup check
meta.lockup.epoch = 1;
assert_eq!(
meta.authorize_withdraw(&staker, &signers, &clock),
Err(StakeError::LockupInForce.into())
);
// verify lockup check defeated by custodian
signers.insert(custodian);
assert_eq!(meta.authorize_withdraw(&staker, &signers, &clock), Ok(()));
// verify lock expiry
signers.remove(&custodian);
clock.epoch = 1;
assert_eq!(meta.authorize_withdraw(&staker, &signers, &clock), Ok(()));
}

#[test]
fn test_stake_state_stake_from_fail() {
let mut stake_account = Account::new(0, std::mem::size_of::<StakeState>(), &id());
Expand Down

0 comments on commit b762319

Please sign in to comment.