ZVM WEB IDE

enter your code below
TransferEvent = Event("transfer")
ApproveEvent = Event("approve")
TransferFromEvent = Event("transfer_from")
BurnEvent = Event("burn")
class Token(object):
    def __init__(self):
        self.name = 'Zv Token'
        self.symbol = "ZV"
        self.decimal = 3
        self.totalSupply = 100000
        self.balanceOf = zdict()
        self.allowance = zdict()
        self.balanceOf[msg.sender] = self.totalSupply

    def _transfer(self, _from, _to, _value):
        if _to not in self.balanceOf:
            self.balanceOf[_to] = 0
        if _from not in self.balanceOf:
            self.balanceOf[_from] = 0
        # Whether the account balance meets the transfer amount
        if self.balanceOf[_from] < _value:
            raise Exception('the account balance is less than the transfer amount')
        # Check if the transfer amount is legal
        if _value <= 0:
            raise Exception('the transfer amount must be greater than or equal to 0')
        # Transfer
        self.balanceOf[_from] -= _value
        self.balanceOf[_to] += _value

    @register.public(str, int)
    def transfer(self, _to, _value):
        self._transfer(msg.sender, _to, _value)
        TransferEvent.emit(msg.sender, _to, _value)

    @register.public(str, int)
    def approve(self, _spender, _value):
        if _value <= 0:
            raise Exception('the amount of authorization must be greater than or equal to 0')
        if msg.sender not in self.allowance:
            self.allowance[msg.sender] = zdict()
        self.allowance[msg.sender][_spender] = 0
        self.allowance[msg.sender][_spender] = _value
        ApproveEvent.emit(msg.sender, _spender, _value)

    @register.public(str, str, int)
    def transfer_from(self, _from, _to, _value):
        if _value > self.allowance[_from][msg.sender]:
            raise Exception('exceed authorized transfer limit')
        self.allowance[_from][msg.sender] -= _value
        self._transfer(_from, _to, _value)
        TransferFromEvent.emit(msg.sender, _from, _to, _value)

    @register.public(int)
    def burn(self, _value):
        if _value <= 0:
            raise Exception('the burn amount must be greater than or equal to 0')
        if self.balanceOf[msg.sender] < _value:
            raise Exception('insufficient account balance')
        self.balanceOf[msg.sender] -= _value
        self.totalSupply -= _value
        BurnEvent.emit(msg.sender, _value)