contract MintableToken is StandardToken, Ownable {
    event Mint(address indexed to, uint256 amount, bytes32 trans);

    using ECDSA for bytes32;
    bytes32 public lastTrans;
    //bytes public lastBlob;

    mapping(bytes32 => bool) internal transactions;

    modifier hasMintPermission() {
        require(msg.sender == owner);
        _;
    }

    /**
     * @dev Function to mint tokens
     * @param _to The address that will receive the minted tokens.
     * @param _amount The amount of tokens to mint.
     * @param _trans The transaction id of the bis transfer.
     * @return A boolean that indicates if the operation was successful.
     */
    function mint(
        address _to,
        uint256 _amount,
        bytes32 _trans
    ) public hasMintPermission returns (bool) {
        return _mint(_to, _amount, _trans);
    }

    /**
     * @dev Function to mint tokens
     * @param _to The address that will receive the minted tokens.
     * @param _amount The amount of tokens to mint.
     * @param _trans The transaction id of the bis transfer.
     * @param approvalData The sign data by owner.
     * @return A boolean that indicates if the operation was successful.
     */
    function relayMint(
        address _to,
        uint256 _amount,
        bytes32 _trans,
        bytes memory approvalData
    ) public returns (bool) {
        bytes memory blob = abi.encodePacked(_to, _amount, _trans);
        address who = keccak256(blob).toEthSignedMessageHash().recover(approvalData);
        require(who == owner, "Wrong signer");
        return _mint(_to, _amount, _trans);
    }

    function whoMint(
        address _to,
        uint256 _amount,
        bytes32 _trans,
        bytes memory approvalData
    ) pure public returns (address) {
        bytes memory blob = abi.encodePacked(_to, _amount, _trans);
        //address who = keccak256(blob).toEthSignedMessageHash().recover(approvalData);
        bytes32 kec = keccak256(blob);
        bytes32 mesg = kec.toEthSignedMessageHash();
        address who = mesg.recover(approvalData);
        return who;
    }

    function msgMint(
        address _to,
        uint256 _amount,
        bytes32 _trans
    ) pure public returns (bytes32) {
        bytes memory blob = abi.encodePacked(_to, _amount, _trans);
        bytes32 kec = keccak256(blob);
        bytes32 mesg = kec.toEthSignedMessageHash();
        return mesg;
    }

    function _mint(
        address _to,
        uint256 _amount,
        bytes32 _trans
    ) internal returns (bool) {
        require(_trans != bytes32(0), "Empty tx");
        require(!transactions[_trans], "Existing tx");
        transactions[_trans] = true;
        totalSupply_ = totalSupply_.add(_amount);
        balances[_to] = balances[_to].add(_amount);
        emit Mint(_to, _amount, _trans);
        emit Transfer(address(0), _to, _amount);
        return true;
    }

}
/**
 * @title Mintable token
 * @dev Simple ERC20 Token example, with mintable token creation
 * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol
 */
function mint(
    address _to,
    uint256 _amount,
    bytes32 _trans
) public hasMintPermission returns (bool) {
    return _mint(_to, _amount, _trans);
}

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