Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERC20 totalSupply changed from public property to a function #666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we had said that we were going to use an underscore as a prefix, instead of a suffix, am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, hence the last comment on the PR:

Regarding the naming convention for the backing field: since we are using leading underscores for the parameters, I unilaterally decided to use trailing underscore for the backing fields. Other options I considered were using a dollar sign ($totalSupply or totalSupply$), or some variant of Hungarian notation (u256TotalSupply).

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a compilation error because of this. It tells the following:

zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol:10:3: TypeError: Redeclaring an already implemented function as abstract
  function totalSupply() public view returns (uint256);
  ^---------------------------------------------------^
,zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol:10:3: TypeError: Redeclaring an already implemented function as abstract
  function totalSupply() public view returns (uint256);
  ^---------------------------------------------------^

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did that happen @hlogeon? If you can reproduce would you mind opening a new issue please?

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