Skip to content

Commit

Permalink
ERC20 totalSupply changed from public property to a function (#666)
Browse files Browse the repository at this point in the history
Fixes #434
  • Loading branch information
spalladino authored and frangio committed Jan 19, 2018
1 parent 9cc55ef commit 370e6a8
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/examples/SimpleToken.sol
Expand Up @@ -22,7 +22,7 @@ contract SimpleToken is StandardToken {
* @dev Constructor that gives msg.sender all of existing tokens.
*/
function SimpleToken() public {
totalSupply = INITIAL_SUPPLY;
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/BasicTokenMock.sol
Expand Up @@ -9,7 +9,7 @@ contract BasicTokenMock is BasicToken {

function BasicTokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply = initialBalance;
totalSupply_ = initialBalance;
}

}
2 changes: 1 addition & 1 deletion contracts/mocks/BurnableTokenMock.sol
Expand Up @@ -7,7 +7,7 @@ contract BurnableTokenMock is BurnableToken {

function BurnableTokenMock(address initialAccount, uint initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply = initialBalance;
totalSupply_ = initialBalance;
}

}
2 changes: 1 addition & 1 deletion contracts/mocks/ERC223TokenMock.sol
Expand Up @@ -12,7 +12,7 @@ contract ERC223TokenMock is BasicToken {

function ERC223TokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply = initialBalance;
totalSupply_ = initialBalance;
}

// ERC223 compatible transfer function (except the name)
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC827TokenMock.sol
Expand Up @@ -9,7 +9,7 @@ contract ERC827TokenMock is ERC827Token {

function ERC827TokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply = initialBalance;
totalSupply_ = initialBalance;
}

}
8 changes: 8 additions & 0 deletions contracts/mocks/SafeERC20Helper.sol
Expand Up @@ -5,6 +5,10 @@ import "../token/ERC20/SafeERC20.sol";


contract ERC20FailingMock is ERC20 {
function totalSupply() public view returns (uint256) {
return 0;
}

function transfer(address, uint256) public returns (bool) {
return false;
}
Expand All @@ -28,6 +32,10 @@ contract ERC20FailingMock is ERC20 {


contract ERC20SucceedingMock is ERC20 {
function totalSupply() public view returns (uint256) {
return 0;
}

function transfer(address, uint256) public returns (bool) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/StandardTokenMock.sol
Expand Up @@ -9,7 +9,7 @@ contract StandardTokenMock is StandardToken {

function StandardTokenMock(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply = initialBalance;
totalSupply_ = initialBalance;
}

}
9 changes: 9 additions & 0 deletions contracts/token/BasicToken.sol
Expand Up @@ -14,6 +14,15 @@ contract BasicToken is ERC20Basic {

mapping(address => uint256) balances;

uint256 totalSupply_;

/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}

/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/BurnableToken.sol
Expand Up @@ -22,7 +22,7 @@ contract BurnableToken is BasicToken {

address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
totalSupply_ = totalSupply_.sub(_value);
Burn(burner, _value);
}
}
2 changes: 1 addition & 1 deletion contracts/token/CappedToken.sol
Expand Up @@ -24,7 +24,7 @@ contract CappedToken is MintableToken {
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
require(totalSupply.add(_amount) <= cap);
require(totalSupply_.add(_amount) <= cap);

return super.mint(_to, _amount);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/ERC20/ERC20Basic.sol
Expand Up @@ -7,7 +7,7 @@ pragma solidity ^0.4.18;
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
uint256 public totalSupply;
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/MintableToken.sol
Expand Up @@ -32,7 +32,7 @@ contract MintableToken is StandardToken, Ownable {
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
Expand Down

0 comments on commit 370e6a8

Please sign in to comment.