contract EGMToken is ERC20Interface, Tokenlock, UserLock {
  using SafeMath for uint;
    string public symbol;
  string public name;
  uint8 public decimals;
  uint _totalSupply;
  mapping(address => uint) balances;
  mapping(address => mapping(address => uint256)) public allowed;
  constructor() public {
    symbol = "EGM";
    name = "Gates Exchange miracle coin";//代币名
    decimals = 8;//小数位数
    _totalSupply = 100000000000000000;//发行总量
    balances[owner] = _totalSupply;
    emit Transfer(address(0), owner, _totalSupply);
  }
  //查询目前SUIBE存量（减去销毁）
  function totalSupply() public view returns(uint) {
    return _totalSupply.sub(balances[address(0)]);
  }
  //输入地址，查询余额
  function balanceOf(address tokenOwner) public view returns(uint balance) {
    return balances[tokenOwner];
  }
  //输入目标地址，金额，进行转账
  function transfer(address to, uint tokens) public validLock permissionCheck returns(bool success) {
    balances[msg.sender] = balances[msg.sender].sub(tokens);
    balances[to] = balances[to].add(tokens);
    emit Transfer(msg.sender, to, tokens);
    return true;
  }
  //输入委托人地址，输入委托金额，进行委托操作
  //「委托人可以自由的动用你的账户中被委托的金额」
  //该功能合理解释to https://blog.csdn.net/weixin_43343144/article/details/89017364
  function approve(address spender, uint tokens) public validLock permissionCheck returns(bool success) 
{
    allowed[msg.sender][spender] = tokens;
    emit Approval(msg.sender, spender, tokens);
    return true;
  }
  //「委托人特权」输入托付者地址，转账地址，转账金额。进行委托转账
  //「信任保证」
  function transferFrom(address _from, address to, uint tokens) public validLock permissionCheck 
returns(bool success) {
    balances[_from] = balances[_from].sub(tokens);
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(tokens);
    balances[to] = balances[to].add(tokens);
    emit Transfer(_from, to, tokens);
    return true;
  }
  //输入托付人地址，委托人地址，查询剩余委托金额
  function allowance(address tokenOwner, address spender) public view returns(uint remaining) {
    return allowed[tokenOwner][spender];
  }
  //「销毁操作」销毁自己拥有的SUIBE，SUIBE总量也会减少
  function burn(uint256 value) public validLock permissionCheck returns(bool success) {
    require(msg.sender != address(0));
    _totalSupply = _totalSupply.sub(value);
    balances[msg.sender] = balances[msg.sender].sub(value);
    emit Transfer(msg.sender, address(0), value);
    return true;
  }
  //信任支付
  //功能合理解释to https://blog.csdn.net/weixin_38746124/article/details/81511227
  function approveAndCall(address spender, uint tokens, bytes memory data) public validLock 
permissionCheck returns(bool success) {
    allowed[msg.sender][spender] = tokens;
    emit Approval(msg.sender, spender, tokens);
    ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, address(this), data);
    return true;
  }
  //错误转账回调
  function () external payable {
    revert();
  }
  //owner地址支持接受其他ERC20代币
  function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns(bool 
success) {
    return ERC20Interface(tokenAddress).transfer(owner, tokens);
  }
}
//「需要部署」，创建代币合约，功能已写在function前
function balanceOf(address tokenOwner) public view returns(uint balance) {
  return balances[tokenOwner];
}

//输入地址，查询余额