Skip to content

Commit

Permalink
Add Account::is_frozen method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 21, 2020
1 parent 6d09b9f commit e116f95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 7 additions & 9 deletions token/program2/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ impl Processor {
if source_account.mint != dest_account.mint {
return Err(TokenError::MintMismatch.into());
}
if source_account.is_initialized == AccountState::Frozen
|| dest_account.is_initialized == AccountState::Frozen
{
if source_account.is_frozen() || dest_account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand Down Expand Up @@ -198,7 +196,7 @@ impl Processor {
let delegate_info = next_account_info(account_info_iter)?;
let owner_info = next_account_info(account_info_iter)?;

if source_account.is_initialized == AccountState::Frozen {
if source_account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand All @@ -224,7 +222,7 @@ impl Processor {
let mut source_account: &mut Account = state::unpack(&mut source_data)?;
let owner_info = next_account_info(account_info_iter)?;

if source_account.is_initialized == AccountState::Frozen {
if source_account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand Down Expand Up @@ -259,7 +257,7 @@ impl Processor {
let mut account_data = account_info.data.borrow_mut();
let mut account: &mut Account = state::unpack(&mut account_data)?;

if account.is_initialized == AccountState::Frozen {
if account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand Down Expand Up @@ -326,7 +324,7 @@ impl Processor {
let mut dest_account_data = dest_account_info.data.borrow_mut();
let mut dest_account: &mut Account = state::unpack(&mut dest_account_data)?;

if dest_account.is_initialized == AccountState::Frozen {
if dest_account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand Down Expand Up @@ -378,7 +376,7 @@ impl Processor {
if source_account.amount < amount {
return Err(TokenError::InsufficientFunds.into());
}
if source_account.is_initialized == AccountState::Frozen {
if source_account.is_frozen() {
return Err(TokenError::AccountFrozen.into());
}

Expand Down Expand Up @@ -461,7 +459,7 @@ impl Processor {
return Err(TokenError::MintMismatch.into());
}
if freeze && source_account.is_initialized != AccountState::Initialized
|| !freeze && source_account.is_initialized != AccountState::Frozen
|| !freeze && !source_account.is_frozen()
{
return Err(TokenError::InvalidState.into());
}
Expand Down
6 changes: 6 additions & 0 deletions token/program2/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub struct Account {
/// The amount delegated
pub delegated_amount: u64,
}
impl Account {
/// Checks if account is frozen
pub fn is_frozen(&self) -> bool {
self.is_initialized == AccountState::Frozen
}
}
impl IsInitialized for Account {
fn is_initialized(&self) -> bool {
self.is_initialized != AccountState::Uninitialized
Expand Down

0 comments on commit e116f95

Please sign in to comment.