parent
f8c486ea1b
commit
0a0f8c58a2
@ -0,0 +1,28 @@ |
||||
pragma solidity ^0.4.0; |
||||
|
||||
/** |
||||
* Math operations with safety checks |
||||
*/ |
||||
contract SafeMath { |
||||
function safeMul(uint a, uint b) internal returns (uint) { |
||||
uint c = a * b; |
||||
assert(a == 0 || c / a == b); |
||||
return c; |
||||
} |
||||
|
||||
function safeSub(uint a, uint b) internal returns (uint) { |
||||
assert(b <= a); |
||||
return a - b; |
||||
} |
||||
|
||||
function safeAdd(uint a, uint b) internal returns (uint) { |
||||
uint c = a + b; |
||||
assert(c>=a && c>=b); |
||||
return c; |
||||
} |
||||
|
||||
function assert(bool assertion) internal { |
||||
if (!assertion) throw; |
||||
} |
||||
} |
||||
|
@ -1,42 +1,43 @@ |
||||
pragma solidity ^0.4.0; |
||||
|
||||
// Everything throws instead of returning false on failure. |
||||
import './ERC20.sol'; |
||||
import './SafeMath.sol'; |
||||
|
||||
/** |
||||
* ERC 20 token |
||||
* ERC20 token |
||||
* |
||||
* https://github.com/ethereum/EIPs/issues/20 |
||||
* Based on code by FirstBlood: |
||||
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol |
||||
*/ |
||||
contract BaseToken is ERC20 { |
||||
contract StandardToken is ERC20, SafeMath { |
||||
|
||||
mapping(address => uint256) balances; |
||||
mapping (address => mapping (address => uint256)) allowed; |
||||
uint256 public totalSupply; |
||||
|
||||
|
||||
function transfer(address _to, uint256 _value) 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; } |
||||
if (balances[msg.sender] < _value) { |
||||
throw; |
||||
} |
||||
balances[msg.sender] = safeSub(balances[msg.sender], _value); |
||||
balances[_to] = safeAdd(balances[_to], _value); |
||||
Transfer(msg.sender, _to, _value); |
||||
return true; |
||||
} |
||||
|
||||
function transferFrom(address _from, address _to, uint256 _value) 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; } |
||||
var _allowance = allowed[_from][msg.sender]; |
||||
if (balances[_from] < _value || |
||||
_allowance < _value)) { |
||||
throw; |
||||
} |
||||
|
||||
balances[_to] = safeAdd(balances[_to], _value); |
||||
balances[_from] = safeSub(balances[_from], _value); |
||||
allowed[_from][msg.sender] = safeSub(_allowance, _value); |
||||
Transfer(_from, _to, _value); |
||||
return true; |
||||
} |
||||
|
||||
function balanceOf(address _owner) constant returns (uint256 balance) { |
Loading…
Reference in new issue