contract TWOToken is ERC20Interface, OwnerHelper
{
    using SafeMath for uint;
    
    string public name;
    uint public decimals;
    string public symbol;

    // Founder
    address private founder;
    
    // Total
    uint public totalTokenSupply;

    mapping (address => uint) public balances;
    mapping (address => mapping ( address => uint )) public approvals;
    mapping (address => bool) private whiteAddresses; // Lock : false, unLock : true
    
    bool public tokenLock = false;

    // Token Total
    uint constant private E18 = 1000000000000000000;

    constructor(address _founder, uint _totalTokenSupply) public {
        name        = "two#";
        decimals    = 18;
        symbol      = "TO1";

        founder = _founder;
        totalTokenSupply  = _totalTokenSupply * E18;
        balances[founder] = totalTokenSupply;
        emit Transfer(0x0, founder, totalTokenSupply);
    }

    // ERC - 20 Interface -----
    modifier notLocked {
        require(isTransferable() == true);
        _;
    }

    function lock(address who) onlyOwner public {
        
        whiteAddresses[who] = false;
    }
    
    function unlock(address who) onlyOwner public {
        
        whiteAddresses[who] = true;
    }
    
    function isLocked(address who) public view returns(bool) {
        
        return whiteAddresses[who];
    }

    function totalSupply() view public returns (uint) 
    {
        return totalTokenSupply;
    }
    
    function balanceOf(address _who) view public returns (uint) 
    {
        return balances[_who];
    }
    
    function transfer(address _to, uint _value) notLocked public returns (bool) 
    {
        require(balances[msg.sender] >= _value);
        
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        
        emit Transfer(msg.sender, _to, _value);
        
        return true;
    }
    
    function approve(address _spender, uint _value) notLocked public returns (bool)
    {
        require(balances[msg.sender] >= _value);
        
        approvals[msg.sender][_spender] = _value;
        
        emit Approval(msg.sender, _spender, _value);
        
        return true; 
    }
    
    function allowance(address _owner, address _spender) view public returns (uint) 
    {
        return approvals[_owner][_spender];
    }

    function transferFrom(address _from, address _to, uint _value) notLocked public returns (bool) 
    {
        require(balances[_from] >= _value);
        require(approvals[_from][msg.sender] >= _value);
        
        approvals[_from][msg.sender] = approvals[_from][msg.sender].sub(_value);
        balances[_from] = balances[_from].sub(_value);
        balances[_to]  = balances[_to].add(_value);
        
        emit Transfer(_from, _to, _value);
        
        return true;
    }
    
    // Lock Function -----
    
    function isTransferable() private view returns (bool)
    {
        if(tokenLock == false)
        {
            return true;
        }
        else {
          if(msg.sender == owner)
          {
            return true;
          }

          if (whiteAddresses[msg.sender]) // true is unLocked
          {
              return true;
          }
        }
        
        return false;
    }
    
    function setTokenUnlock() onlyOwner public
    {
        require(tokenLock == true);
        
        tokenLock = false;
    }
    
    function setTokenLock() onlyOwner public
    {
        require(tokenLock == false);
        
        tokenLock = true;
    }
    
    function close() onlyOwner public
    {
        selfdestruct(msg.sender);
    }
    
    // -----
}
function isTransferable() private view returns (bool)
{
    if(tokenLock == false)
    {
        return true;
    }
    else {
      if(msg.sender == owner)
      {
        return true;
      }

      if (whiteAddresses[msg.sender]) // true is unLocked
      {
          return true;
      }
    }
        
    return false;
}

// Lock Function -----