Created
May 10, 2018 18:12
-
-
Save theblockstalk/abf8309a1060e6fecf3ef96d2f67fad3 to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.4.0; | |
import './Ownable.sol'; | |
contract SimpleCoin is Ownable{ | |
string name; | |
uint total; | |
uint limit; | |
mapping (address => uint) balances; | |
constructor(string _name, uint _total, uint _limit) { | |
total = _total; | |
name = _name; | |
limit = _limit; | |
balances[msg.sender] = total; | |
} | |
modifier limitTransfer(uint _value) { | |
assert(_value < limit); | |
_; | |
} | |
function setLimit(uint _limit) onlyOwner public { | |
LimitChanged(limit, _limit); | |
limit = _limit; | |
} | |
function totalSupply() constant returns (uint256 ) { | |
return total; | |
} | |
function balanceOf(address _owner) constant returns (uint256 ) { | |
return balances[_owner]; | |
} | |
function transfer(address _to, uint256 _value) limitTransfer(_value) returns (bool) { | |
assert(_to != msg.sender); | |
if (balances[msg.sender] >= _value) { | |
balances[msg.sender] -= _value; // OVERFLOW CAN HAPPEN HERE | |
balances[_to] += _value; // OVERFLOW CAN HAPPEN HERE | |
emit Transfer(msg.sender, _to, _value); | |
} else return false; | |
} | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event LimitChanged(uint oldLimit, uint newLimit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment