Skip to content

Commit

Permalink
Use boolean for toggle fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 25, 2020
1 parent 68dd692 commit 45c35dd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions token/program2/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Processor {
pub fn process_toggle_freeze_account(
program_id: &Pubkey,
accounts: &[AccountInfo],
desired_account_state: AccountState,
freeze: bool,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
let source_account_info = next_account_info(account_info_iter)?;
Expand All @@ -468,8 +468,8 @@ impl Processor {
if mint_info.key != &source_account.mint {
return Err(TokenError::MintMismatch.into());
}
if desired_account_state == AccountState::Frozen && source_account.is_frozen()
|| desired_account_state == AccountState::Initialized && !source_account.is_frozen()
if freeze && source_account.is_frozen()
|| !freeze && !source_account.is_frozen()
{
return Err(TokenError::InvalidState.into());
}
Expand All @@ -491,7 +491,11 @@ impl Processor {
}
}

source_account.state = desired_account_state;
source_account.state = if freeze {
AccountState::Frozen
} else {
AccountState::Initialized
};

Ok(())
}
Expand Down Expand Up @@ -557,11 +561,11 @@ impl Processor {
}
TokenInstruction::FreezeAccount => {
info!("Instruction: FreezeAccount");
Self::process_toggle_freeze_account(program_id, accounts, AccountState::Frozen)
Self::process_toggle_freeze_account(program_id, accounts, true)
}
TokenInstruction::ThawAccount => {
info!("Instruction: FreezeAccount");
Self::process_toggle_freeze_account(program_id, accounts, AccountState::Initialized)
Self::process_toggle_freeze_account(program_id, accounts, false)
}
}
}
Expand Down

0 comments on commit 45c35dd

Please sign in to comment.