contract MintableToken is StandardToken {
  event MinterTransferred(address indexed previousMinter, address indexed newMinter);
  event Mint(address indexed to, uint256 amount);
  event MintFinished();
  event Burn(address indexed from, uint256 value);

  bool public mintingFinished = false;
  address public minter;

  constructor() public {
    minter = msg.sender;
    emit MinterTransferred(address(0), minter);
  }

  modifier canMint() {
    require(!mintingFinished, "Minting is already finished.");
    _;
  }

  modifier hasPermission() {
    require(msg.sender == owner || msg.sender == minter, "You must be either owner or minter.");
    _;
  }

  /**
   * @dev Function to mint tokens
   * @param _to The address that will receive the minted tokens.
   * @param _amount The amount of tokens to mint.
   * @return A boolean that indicates if the operation was successful.
   */
  function mint(address _to, uint256 _amount) canMint hasPermission external returns (bool) {
    require(_to != address(0), "Invalid destination address.");

    totalSupply = totalSupply.add(_amount);
    balances[_to] = balances[_to].add(_amount);
    emit Mint(_to, _amount);
    emit Transfer(address(0), _to, _amount);
    return true;
  }

  /**
   * @dev Function to stop minting new tokens.
   * @return True if the operation was successful.
   */
  function finishMinting() canMint onlyOwner external returns (bool) {
    mintingFinished = true;
    emit MintFinished();
    return true;
  }

  function transferMinter(address newMinter) public onlyOwner {
    require(newMinter != address(0), "Invalid new minter address.");
    address prevMinter = minter;
    minter = newMinter;
    emit MinterTransferred(prevMinter, minter);
  }

  function burn(address _from, uint256 _amount) external hasPermission {
    require(_from != address(0), "Invalid source address.");

    balances[_from] = balances[_from].sub(_amount);
    totalSupply = totalSupply.sub(_amount);
    emit Transfer(_from, address(0), _amount);
    emit Burn(_from, _amount);
  }
}
/**
 * @title Mintable token
 * @dev Simple ERC20 Token example, with mintable token creation
 * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120
 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
 */
function mint(address _to, uint256 _amount) canMint hasPermission external returns (bool) {
  require(_to != address(0), "Invalid destination address.");

  totalSupply = totalSupply.add(_amount);
  balances[_to] = balances[_to].add(_amount);
  emit Mint(_to, _amount);
  emit Transfer(address(0), _to, _amount);
  return true;
}

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