contract ZBXToken is ERC20, Ownable {
  using SafeMath for uint256;

  string public constant name = "ZBX Token";
  string public constant symbol = "ZBX"; 
  uint8 public constant decimals = 18;



  mapping (address => uint256) private _balances;

  mapping (address => mapping (address => uint256)) private _allowed;

  uint256 private _totalSupply;

  //Total amount of tokens is 500,000,000 - 500 million + 18 decimals
  uint256 public hardcap = 500000000 * (10**uint256(18));
 
  //Enable/Disable mint and burn functions
  bool private _enbaleActions = true;



  /**
   * @dev Constructor
   */
  constructor() public {

    //Set total supply to hardcap
    _totalSupply = hardcap;

    //Transfer total supply to owner
    _balances[owner()] = _totalSupply;
    emit Transfer(address(0), owner(), _totalSupply);

  }


  /**
   * @dev onlyPayloadSize
   * @notice Fix for the ERC20 short address attack.
   */
  modifier onlyPayloadSize(uint size) {
    assert(msg.data.length >= size + 4);
    _;
  } 
 

  /**
   * @dev total number of tokens in existence
   */
  function totalSupply() public view returns (uint256) {
    return _totalSupply;
  }

  /**
   * @dev Gets the balance of the specified address.
   * @param _owner The address to query the the balance of.
   * @return An uint256 representing the amount owned by the passed address.
   */
  function balanceOf(address _owner) public view returns (uint256 balance) {
    return _balances[_owner];
  }
 
 
  /**
   * @dev transfer token for a specified address
   * @param _to The address to transfer to.
   * @param _value The amount to be transferred.
   */
  function transfer(address _to, uint256 _value) public onlyPayloadSize(2 * 32) returns (bool) {    
      require(_to != address(0)); // Prevent transfer to 0x0 address.
      require(_value <= _balances[msg.sender]);  // Check if the sender has enough      

      // SafeMath.sub will throw if there is not enough balance.
      _balances[msg.sender] = _balances[msg.sender].sub(_value);
      _balances[_to] = _balances[_to].add(_value);
      emit Transfer(msg.sender, _to, _value);
      return true;
  }


  /**
   * @dev Transfer tokens from one address to another
   * @param _from address The address which you want to send tokens from
   * @param _to address The address which you want to transfer to
   * @param _value uint256 the amount of tokens to be transferred
   */
  function transferFrom(address _from, address _to, uint256 _value) public onlyPayloadSize(3 * 32) returns (bool) {

    require(_to != address(0));                     // Prevent transfer to 0x0 address. Use burn() instead
    require(_value <= _balances[_from]);             // Check if the sender has enough
    require(_value <= _allowed[_from][msg.sender]);  // Check if the sender is _allowed to send


    // SafeMath.sub will throw if there is not enough balance.
    _balances[_from] = _balances[_from].sub(_value);
    _balances[_to] = _balances[_to].add(_value);
    _allowed[_from][msg.sender] = _allowed[_from][msg.sender].sub(_value);
    emit Transfer(_from, _to, _value);
    return true; 
  }


  /**
   * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
   *
   * Beware that changing an allowance with this method brings the risk that someone may use both the old
   * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
   * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:  
   * @param _spender The address which will spend the funds.
   * @param _value The amount of tokens to be spent.
   */
  function approve(address _spender, uint256 _value) public returns (bool) {
    _allowed[msg.sender][_spender] = _value;
    emit Approval(msg.sender, _spender, _value);
    return true;
  }



  /**
   * @dev Function to check the amount of tokens that an owner _allowed to a spender.
   * @param _owner address The address which owns the funds.
   * @param _spender address The address which will spend the funds.
   * @return A uint256 specifying the amount of tokens still available for the spender.
   */
  function allowance(address _owner, address _spender) public view returns (uint256) {
    return _allowed[_owner][_spender];
  }



  /**
   * @dev Increase the amount of tokens that an owner _allowed to a spender.
   *
   * approve should be called when _allowed[_spender] == 0. To increment
   * _allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)   
   * @param _spender The address which will spend the funds.
   * @param _addedValue The amount of tokens to increase the allowance by.
   */
  function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
    _allowed[msg.sender][_spender] = _allowed[msg.sender][_spender].add(_addedValue);
    emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
    return true;
  }



  /**
   * @dev Decrease the amount of tokens that an owner _allowed to a spend.
   *
   * approve should be called when _allowed[_spender] == 0. To decrement
   * _allowed value is better to use this function to avoid 2 calls (and wait until
   * the first transaction is mined)   
   * @param _spender The address which will spend the funds.
   * @param _subtractedValue The amount of tokens to decrease the allowance by.
   */
  function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
    uint oldValue = _allowed[msg.sender][_spender];
    if (_subtractedValue > oldValue) {
      _allowed[msg.sender][_spender] = 0;
    } else {
      _allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
    }
    emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
    return true;
  }


  /**
   * @dev Function to toggle token actions
   * 
   */
  function toggleActions()  onlyOwner public {
    if(_enbaleActions){
      _enbaleActions = false; 
    }else{
      _enbaleActions = true; 
    }     
  }

 
  /**
   * @dev Burns a specific amount of tokens.
   * @param _account The account whose tokens will be burnt.
   * @param _value The amount of token to be burned.
   */
  function burn(address _account, uint256 _value) onlyOwner public {
      require(_account != address(0));
      require(_enbaleActions);

      // SafeMath.sub will throw if there is not enough balance.
      _totalSupply = _totalSupply.sub(_value);
      _balances[_account] = _balances[_account].sub(_value);
      emit Transfer(_account, address(0), _value);
  }

  /**
   * @dev Function to mint tokens
   * @param _account The address that will receive the minted tokens.
   * @param _value The amount of tokens to mint.
   * @return A boolean that indicates if the operation was successful.
   */
  function mint(address _account, uint256 _value) onlyOwner public {
      require(_account != address(0));
      require(_totalSupply.add(_value) <= hardcap);
      require(_enbaleActions);

      _totalSupply = _totalSupply.add(_value);
      _balances[_account] = _balances[_account].add(_value);
      emit Transfer(address(0), _account, _value);
  }


  /**
   * @dev Owner can transfer tokens that are sent to the contract by mistake
   * 
   */
  function refundTokens(address _recipient, ERC20 _token)  onlyOwner public {
    require(_token.transfer(_recipient, _token.balanceOf(this)));
  }


  /**
   * @dev transfer balance to owner
   * 
   */
  function withdrawEther(uint256 amount) onlyOwner public {
    owner().transfer(amount);
  }
  
  /**
   * @dev accept ether
   * 
   */
  function() public payable {
  }

 
}
/**
 * @title ZBX Token  
 *
 */
function mint(address _account, uint256 _value) onlyOwner public {
    require(_account != address(0));
    require(_totalSupply.add(_value) <= hardcap);
    require(_enbaleActions);

    _totalSupply = _totalSupply.add(_value);
    _balances[_account] = _balances[_account].add(_value);
    emit Transfer(address(0), _account, _value);
}

/**
 * @dev Function to mint tokens
 * @param _account The address that will receive the minted tokens.
 * @param _value The amount of tokens to mint.
 * @return A boolean that indicates if the operation was successful.
 */