Skip to content

Instantly share code, notes, and snippets.

@khovratovich
Last active October 3, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khovratovich/e888f76169fdf01ab94eeafd170c287f to your computer and use it in GitHub Desktop.
Save khovratovich/e888f76169fdf01ab94eeafd170c287f to your computer and use it in GitHub Desktop.
WIZ Token Contract
pragma solidity ^0.4.17;
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Base {
function max(uint a, uint b) returns (uint) { return a >= b ? a : b; }
function min(uint a, uint b) returns (uint) { return a <= b ? a : b; }
modifier only(address allowed) {
require(msg.sender == allowed);
_;
}
function isContract(address _addr) constant internal returns (bool) {
if (_addr == 0) return false;
uint size;
assembly {
size := extcodesize(_addr)
}
return (size > 0);
}
// *************************************************
// * reentrancy handling *
// *************************************************
uint constant internal L00 = 2 ** 0;
uint constant internal L01 = 2 ** 1;
uint constant internal L02 = 2 ** 2;
uint constant internal L03 = 2 ** 3;
uint constant internal L04 = 2 ** 4;
uint constant internal L05 = 2 ** 5;
uint private bitlocks = 0;
modifier noReentrancy(uint m) {
var _locks = bitlocks;
require(_locks & m <= 0);
bitlocks |= m;
_;
bitlocks = _locks;
}
modifier noAnyReentrancy {
var _locks = bitlocks;
require(_locks <= 0);
bitlocks = uint(-1);
_;
bitlocks = _locks;
}
modifier reentrant { _; }
}
contract Owned is Base {
address public owner;
address public newOwner;
function Owned() {
owner = msg.sender;
}
function transferOwnership(address _newOwner) only(owner) {
newOwner = _newOwner;
}
function acceptOwnership() only(newOwner) {
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
event OwnershipTransferred(address indexed _from, address indexed _to);
}
contract ERC20 is Owned {
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
function transfer(address _to, uint256 _value) isStartedOnly returns (bool success) {
if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint256 _value) isStartedOnly returns (bool success) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) isStartedOnly returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
bool public isStarted = false;
modifier onlyHolder(address holder) {
require(balanceOf(holder) != 0);
_;
}
modifier isStartedOnly() {
require(isStarted);
_;
}
}
contract Token is ERC20 {
using SafeMath for uint256;
string public name = "CrowdWizToken";
string public symbol = "WIZ";
uint public decimals = 18;
address public crowdsaleMinter;
modifier onlyCrowdsaleMinter(){
require(msg.sender == crowdsaleMinter);
_;
}
modifier isNotStartedOnly() {
require(!isStarted);
_;
}
function Token(address _crowdsaleMinter){
crowdsaleMinter = _crowdsaleMinter;
}
// ------------------------------------------------------------------------
// Don't accept ethers
// ------------------------------------------------------------------------
function () {
revert();
}
function getTotalSupply()
public
constant
returns(uint)
{
return totalSupply;
}
function start()
public
onlyCrowdsaleMinter
isNotStartedOnly
{
isStarted = true;
}
function emergencyStop()
public
only(owner)
{
isStarted = false;
}
//================= Crowdsale Only =================
function mint(address _to, uint _amount) public
onlyCrowdsaleMinter
isNotStartedOnly
returns(bool)
{
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment