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

Conversation

spalladino
Copy link
Contributor

  • πŸ“˜ I've reviewed the OpenZeppelin Contributor Guidelines
  • βœ… I've added tests where applicable to test my new functionality.
  • πŸ“– I've made sure that my contracts are well-documented.
  • 🎨 I've run the JavaScript linter (npm run lint:fix) and fixed all issues.

Fixes #434


πŸš€ Description

Having ERC20#totalSupply defined as a public property made it impossible to override it in any child class, due to a solidity limitation. As such, it was impossible to change the getter behaviour while retaining the ERC20 interface, at least without modifying the OpenZeppelin base contract (which is something we definitely want to avoid).

This PR removes the public property definition from the ERC20Basic interface, and replaces it with just the signature for the getter. The implementation is provided in BasicToken, the first contract that implements that interface, backed by a totalSupply_ internal field.

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).

@spalladino
Copy link
Contributor Author

Heh, PR 666 😈

@@ -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).

frangio
frangio previously approved these changes Jan 18, 2018
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Not happy with the trailing underscore notation but cannot think of a better alternative.

@spalladino
Copy link
Contributor Author

@frangio please re-review :-)

@frangio frangio merged commit 370e6a8 into OpenZeppelin:master Jan 19, 2018
@frangio frangio removed the review label Jan 19, 2018
@@ -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?

ProphetDaniel pushed a commit to classicdelta/Smart-Contracts that referenced this pull request Mar 9, 2018
hbdgr added a commit to JoyPlatform/joy-contracts that referenced this pull request Jul 17, 2018
JoyGaming pushed a commit to JoyPlatform/joy-contracts that referenced this pull request Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

totalSupply should be a function, not state variable
4 participants