Permalink
Browse files

update safemath

  • Loading branch information...
conejoninja committed Jun 5, 2018
1 parent f7dc4c8 commit 769929d61dc6b53a8efa2358aae6053573c39ece
Showing with 26 additions and 48 deletions.
  1. +24 −9 contracts/system.sol
  2. +1 −1 contracts/tokens.sol
  3. +1 −38 contracts/whitelist.sol
@@ -19,38 +19,53 @@ v1.0

*/

pragma solidity ^0.4.22;
pragma solidity ^0.4.23;

/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);

/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}

/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
return a / b;
}

/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}

function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}

/**
* @title System
* @dev Abstract contract that includes some useful generic functions.
@@ -73,7 +73,7 @@ contract Tokens is HardcodedWallets, ERC20 {

// Token distribution
balances[_addressSCEscrow] = totalSupply;
emit Transfer(this, _addressSCEscrow, totalSupply);
emit Transfer(0x0, _addressSCEscrow, totalSupply);

}

@@ -13,7 +13,6 @@ contract Whitelist is HardcodedWallets {
// **** DATA

mapping (address => bool) public walletsICO;
mapping (address => bool) public managers;

// Checks whether a given wallet is authorized to ICO investing
function isInvestor(address _wallet) public constant returns (bool) {
@@ -23,7 +22,7 @@ contract Whitelist is HardcodedWallets {
/**
* @notice Registers an investor
*/
function addInvestor(address _wallet) external isManager returns (bool) {
function addInvestor(address _wallet) external onlyOwner returns (bool) {
// Checks whether this wallet has been previously added as an investor
if (walletsICO[_wallet]) {
error('addInvestor: this wallet has been previously granted as ICO investor');
@@ -36,46 +35,10 @@ contract Whitelist is HardcodedWallets {
return true;
}

modifier isManager(){
if (managers[msg.sender] || msg.sender == owner) {
_;
} else {
error("isManager: called by user that is not owner or manager");
}
}

// adds an address that will have the right to add investors
function addManager(address _managerAddr) external onlyOwner returns (bool) {
if(managers[_managerAddr]){
error("addManager: manager account already exists.");
return false;
}

managers[_managerAddr] = true;

emit AddManager(_managerAddr, timestamp());
}

// removes a manager address
function delManager(address _managerAddr) external onlyOwner returns (bool) {
if(!managers[_managerAddr]){
error("delManager: manager account not found.");
return false;
}

delete managers[_managerAddr];

emit DelManager(_managerAddr, timestamp());
}

// **** EVENTS

// Triggered when a wallet is granted to become an ICO investor
event AddInvestor(address indexed _wallet, uint256 _timestamp);
// Triggered when a manager is added
event AddManager(address indexed _managerAddr, uint256 _timestamp);
// Triggered when a manager is removed
event DelManager(address indexed _managerAddr, uint256 _timestamp);
}


0 comments on commit 769929d

Please sign in to comment.