contract XcoinToken is EIP20Interface {
    //1.获取token名字，比如"X Coin"
    string public name;
     //2.获取Token简称,比如"XCO"
    string public symbol;
    //3.获取小数位，比如以太坊的decimals为18
    uint8 public decimals;
     //4.获取token发布的总量，比如XCO 2.8亿
    uint256 public totalSupply;

    mapping(address=>uint256) balances ;

    mapping(address=>mapping(address=>uint256)) allowances;
    constructor (string memory  _name,string memory  _symbol, uint8  _decimals,uint256  _totalSupply) public{       
    name = _name;
    symbol = _symbol;
    decimals = _decimals;
    totalSupply = _totalSupply;
    balances[msg.sender] = _totalSupply;
    }

    //获取_owner地址的余额
    function balanceOf(address _owner) public view returns (uint256 balance){
        return balances[_owner];
    }
    //转账:从自己账户向_to地址转入_value个Token
    function transfer(address _to, uint256 _value)public  returns (bool success){
        require(_value >0 && balances[_to] + _value > balances[_to] && balances[msg.sender] > _value);
        balances[_to] += _value;
        balances[msg.sender] -= _value;
        emit Transfer(msg.sender, _to,_value);

        return true;
    }

    //转账:从_from向_to转_value个Token
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        uint256 allowan = allowances[_from][_to];
        require(allowan > _value && balances[_from] >= _value && _to == msg.sender && balances[_to] + _value>balances[_to]);
        allowances[_from][_to] -= _value;
        balances[_from] -= _value;
        balances[_to] += _value;
        emit Transfer(_from,_to,_value);
        return true;
    }
    //允许_spender从自己(调用方)账户转走_value个Token
    function approve(address _spender, uint256 _value) public returns (bool success){
        require(_value >0 && balances[msg.sender] > _value);
        allowances[msg.sender][_spender] = _value;
        emit Approval(msg.sender,_spender,_value);
                return true;
    }
    //自己_owner查询_spender地址可以转走自己多少个Token
    function allowance(address _owner, address _spender) public view returns (uint256 remaining){
        return allowances[_owner][_spender];
    }
   
    

}
function balanceOf(address _owner) public view returns (uint256 balance){
    return balances[_owner];
}

//获取_owner地址的余额