fixes for StandardToken
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
pragma solidity ^0.4.0;
|
||||
import './PullPayment.sol';
|
||||
import './examples/ExampleToken.sol';
|
||||
|
||||
/*
|
||||
* Bounty
|
||||
* This bounty will pay out if you can cause a Token's balance
|
||||
* This bounty will pay out if you can cause a ExampleToken's balance
|
||||
* to be lower than its totalSupply, which would mean that it doesn't
|
||||
* have sufficient ether for everyone to withdraw.
|
||||
*/
|
||||
@ -16,16 +17,16 @@ contract Bounty is PullPayment {
|
||||
if (claimed) throw;
|
||||
}
|
||||
|
||||
function createTarget() returns(Token) {
|
||||
Token target = new Token(0);
|
||||
function createTarget() returns(ExampleToken) {
|
||||
ExampleToken target = new ExampleToken();
|
||||
researchers[target] = msg.sender;
|
||||
return target;
|
||||
}
|
||||
|
||||
function claim(Token target) {
|
||||
function claim(ExampleToken target) {
|
||||
address researcher = researchers[target];
|
||||
if (researcher == 0) throw;
|
||||
// check Token contract invariants
|
||||
// check ExampleToken contract invariants
|
||||
if (target.totalSupply() == target.balance) {
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -4,14 +4,13 @@ pragma solidity ^0.4.0;
|
||||
// see https://github.com/ethereum/EIPs/issues/20
|
||||
|
||||
contract ERC20 {
|
||||
function totalSupply() constant returns (uint);
|
||||
function balanceOf(address who) constant returns (uint);
|
||||
function allowance(address owner, address spender) constant returns (uint);
|
||||
uint public totalSupply;
|
||||
function balanceOf(address who) constant returns (uint);
|
||||
function allowance(address owner, address spender) constant returns (uint);
|
||||
|
||||
function transfer(address to, uint value) returns (bool ok);
|
||||
function transferFrom(address from, address to, uint value) returns (bool ok);
|
||||
function approve(address spender, uint value) returns (bool ok);
|
||||
|
||||
event Transfer(address indexed from, address indexed to, uint value);
|
||||
event Approval(address indexed owner, address indexed spender, uint value);
|
||||
function transfer(address to, uint value) returns (bool ok);
|
||||
function transferFrom(address from, address to, uint value) returns (bool ok);
|
||||
function approve(address spender, uint value) returns (bool ok);
|
||||
event Transfer(address indexed from, address indexed to, uint value);
|
||||
event Approval(address indexed owner, address indexed spender, uint value);
|
||||
}
|
||||
|
||||
@ -12,11 +12,10 @@ import './SafeMath.sol';
|
||||
*/
|
||||
contract StandardToken is ERC20, SafeMath {
|
||||
|
||||
mapping(address => uint256) balances;
|
||||
mapping (address => mapping (address => uint256)) allowed;
|
||||
uint256 public totalSupply;
|
||||
mapping(address => uint) balances;
|
||||
mapping (address => mapping (address => uint)) allowed;
|
||||
|
||||
function transfer(address _to, uint256 _value) returns (bool success) {
|
||||
function transfer(address _to, uint _value) returns (bool success) {
|
||||
if (balances[msg.sender] < _value) {
|
||||
throw;
|
||||
}
|
||||
@ -26,7 +25,7 @@ contract StandardToken is ERC20, SafeMath {
|
||||
return true;
|
||||
}
|
||||
|
||||
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
|
||||
function transferFrom(address _from, address _to, uint _value) returns (bool success) {
|
||||
var _allowance = allowed[_from][msg.sender];
|
||||
if (balances[_from] < _value ||
|
||||
_allowance < _value) {
|
||||
@ -40,17 +39,17 @@ contract StandardToken is ERC20, SafeMath {
|
||||
return true;
|
||||
}
|
||||
|
||||
function balanceOf(address _owner) constant returns (uint256 balance) {
|
||||
function balanceOf(address _owner) constant returns (uint balance) {
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function approve(address _spender, uint256 _value) returns (bool success) {
|
||||
function approve(address _spender, uint _value) 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) {
|
||||
function allowance(address _owner, address _spender) constant returns (uint remaining) {
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
|
||||
|
||||
32
contracts/examples/ExampleToken.sol
Normal file
32
contracts/examples/ExampleToken.sol
Normal file
@ -0,0 +1,32 @@
|
||||
pragma solidity ^0.4.0;
|
||||
|
||||
import "../StandardToken.sol";
|
||||
|
||||
contract ExampleToken is StandardToken {
|
||||
|
||||
string public name = "ExampleToken";
|
||||
string public symbol = "TOK";
|
||||
uint public decimals = 18;
|
||||
|
||||
// 1 ether = 500 example tokens
|
||||
uint PRICE = 500;
|
||||
|
||||
|
||||
function () payable {
|
||||
createTokens(msg.sender);
|
||||
}
|
||||
|
||||
function createTokens(address recipient) payable {
|
||||
if (msg.value == 0) throw;
|
||||
|
||||
uint tokens = safeMul(msg.value, getPrice());
|
||||
|
||||
totalSupply = safeAdd(totalSupply, tokens);
|
||||
balances[recipient] = safeAdd(balances[recipient], tokens);
|
||||
}
|
||||
|
||||
// replace this with any other price function
|
||||
function getPrice() constant returns (uint result){
|
||||
return PRICE;
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,7 @@
|
||||
"main": "truffle.js",
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test": "truffle test",
|
||||
"install": "scripts/install.sh"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user