Last active
September 9, 2017 14:48
-
-
Save jacqueswww/c7df86eeadb97a3df7414e9b6d5b6ddf to your computer and use it in GitHub Desktop.
Attempt at translating MyToken example to viper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Viper Port of MyToken | |
# Originally found at https://www.ethereum.org/token | |
# Public variables of the token | |
name: public(bytes32) | |
symbol: public(bytes32) | |
totalSupply: public(num) | |
decimals: public(num) | |
balanceOf: public(num256[address]) | |
def __init__( | |
_name: bytes32, _symbol: bytes32, _decimals: num, initialSupply: num): | |
self.name = _name | |
self.symbol = _symbol | |
self.decimals = _decimals | |
self.totalSupply = initialSupply | |
self.balanceOf[msg.sender] = initialSupply | |
# Send `_value` tokens to `_to` from your account | |
def transfer(_to: address, _value: num256): | |
assert self.balanceOf[msg.sender] > _value | |
assert self.balanceOf[_to] + _value > self.balanceOf[_to] | |
self.balanceOf[msg.sender] -= _value # Subtract from the sender | |
self.balanceOf[_to] += _value # Add the same to the recipient |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment