Skip to content

Commit

Permalink
ERC20 totalSupply changed from public property to a function
Browse files Browse the repository at this point in the history
Fixes #434
  • Loading branch information
spalladino committed Jan 11, 2018
1 parent 9469772 commit 1972eab
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 9 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 @@ -6,7 +6,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/ERC23TokenMock.sol
Expand Up @@ -12,7 +12,7 @@ contract ERC23TokenMock is BasicToken {

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

// ERC23 compatible transfer function (except the name)
Expand Down
8 changes: 8 additions & 0 deletions contracts/mocks/SafeERC20Helper.sol
Expand Up @@ -4,6 +4,10 @@ import '../token/ERC20.sol';
import '../token/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 @@ -26,6 +30,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 @@ -21,7 +21,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 @@ -23,7 +23,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/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 1972eab

Please sign in to comment.