fixes for StandardToken

This commit is contained in:
Manuel Araoz
2016-10-14 12:38:01 -03:00
parent a1f7de0ca1
commit dbc2853372
5 changed files with 54 additions and 23 deletions

View File

@ -1,9 +1,10 @@
pragma solidity ^0.4.0; pragma solidity ^0.4.0;
import './PullPayment.sol'; import './PullPayment.sol';
import './examples/ExampleToken.sol';
/* /*
* Bounty * 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 * to be lower than its totalSupply, which would mean that it doesn't
* have sufficient ether for everyone to withdraw. * have sufficient ether for everyone to withdraw.
*/ */
@ -16,16 +17,16 @@ contract Bounty is PullPayment {
if (claimed) throw; if (claimed) throw;
} }
function createTarget() returns(Token) { function createTarget() returns(ExampleToken) {
Token target = new Token(0); ExampleToken target = new ExampleToken();
researchers[target] = msg.sender; researchers[target] = msg.sender;
return target; return target;
} }
function claim(Token target) { function claim(ExampleToken target) {
address researcher = researchers[target]; address researcher = researchers[target];
if (researcher == 0) throw; if (researcher == 0) throw;
// check Token contract invariants // check ExampleToken contract invariants
if (target.totalSupply() == target.balance) { if (target.totalSupply() == target.balance) {
throw; throw;
} }

View File

@ -4,14 +4,13 @@ pragma solidity ^0.4.0;
// see https://github.com/ethereum/EIPs/issues/20 // see https://github.com/ethereum/EIPs/issues/20
contract ERC20 { contract ERC20 {
function totalSupply() constant returns (uint); uint public totalSupply;
function balanceOf(address who) constant returns (uint); function balanceOf(address who) constant returns (uint);
function allowance(address owner, address spender) constant returns (uint); function allowance(address owner, address spender) constant returns (uint);
function transfer(address to, uint value) returns (bool ok); function transfer(address to, uint value) returns (bool ok);
function transferFrom(address from, 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); function approve(address spender, uint value) returns (bool ok);
event Transfer(address indexed from, address indexed to, uint value);
event Transfer(address indexed from, address indexed to, uint value); event Approval(address indexed owner, address indexed spender, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
} }

View File

@ -12,11 +12,10 @@ import './SafeMath.sol';
*/ */
contract StandardToken is ERC20, SafeMath { contract StandardToken is ERC20, SafeMath {
mapping(address => uint256) balances; mapping(address => uint) balances;
mapping (address => mapping (address => uint256)) allowed; mapping (address => mapping (address => uint)) allowed;
uint256 public totalSupply;
function transfer(address _to, uint256 _value) returns (bool success) { function transfer(address _to, uint _value) returns (bool success) {
if (balances[msg.sender] < _value) { if (balances[msg.sender] < _value) {
throw; throw;
} }
@ -26,7 +25,7 @@ contract StandardToken is ERC20, SafeMath {
return true; 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]; var _allowance = allowed[_from][msg.sender];
if (balances[_from] < _value || if (balances[_from] < _value ||
_allowance < _value) { _allowance < _value) {
@ -40,17 +39,17 @@ contract StandardToken is ERC20, SafeMath {
return true; return true;
} }
function balanceOf(address _owner) constant returns (uint256 balance) { function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner]; 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; allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value); Approval(msg.sender, _spender, _value);
return true; 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]; return allowed[_owner][_spender];
} }

View 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;
}
}

View File

@ -5,7 +5,7 @@
"main": "truffle.js", "main": "truffle.js",
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "truffle test",
"install": "scripts/install.sh" "install": "scripts/install.sh"
}, },
"repository": { "repository": {