Skip to content

Commit b0f20d4

Browse files
Leo Ariasfrangio
authored andcommitted
Add a leading underscore to internal and private functions. (#1257)
* Add a leading underscore to internal and private functions. Fixes #1176 * Remove super * update the ERC721 changes * add missing underscore after merge * Fix mock
1 parent fbfd1fe commit b0f20d4

22 files changed

+90
-76
lines changed

CODE_STYLE.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,22 @@ Any exception or additions specific to our project are documented below.
4343
4444
```
4545
function test() {
46-
uint256 functionVar;
47-
...
46+
uint256 functionVar;
47+
...
48+
}
49+
```
50+
51+
* Internal and private functions should have an underscore prefix.
52+
53+
```
54+
function _testInternal() internal {
55+
...
56+
}
57+
```
58+
59+
```
60+
function _testPrivate() private {
61+
...
4862
}
4963
```
5064

contracts/access/SignatureBouncer.sol

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import "../cryptography/ECDSA.sol";
1717
* valid addresses on-chain, simply sign a grant of the form
1818
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
1919
* Then restrict access to your crowdsale/whitelist/airdrop using the
20-
* `onlyValidSignature` modifier (or implement your own using isValidSignature).
20+
* `onlyValidSignature` modifier (or implement your own using _isValidSignature).
2121
* In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and
2222
* `onlyValidSignatureAndData` can be used to restrict access to only a given method
2323
* or a given method with given parameters respectively.
@@ -42,7 +42,7 @@ contract SignatureBouncer is Ownable, RBAC {
4242
*/
4343
modifier onlyValidSignature(bytes _signature)
4444
{
45-
require(isValidSignature(msg.sender, _signature));
45+
require(_isValidSignature(msg.sender, _signature));
4646
_;
4747
}
4848

@@ -51,7 +51,7 @@ contract SignatureBouncer is Ownable, RBAC {
5151
*/
5252
modifier onlyValidSignatureAndMethod(bytes _signature)
5353
{
54-
require(isValidSignatureAndMethod(msg.sender, _signature));
54+
require(_isValidSignatureAndMethod(msg.sender, _signature));
5555
_;
5656
}
5757

@@ -60,7 +60,7 @@ contract SignatureBouncer is Ownable, RBAC {
6060
*/
6161
modifier onlyValidSignatureAndData(bytes _signature)
6262
{
63-
require(isValidSignatureAndData(msg.sender, _signature));
63+
require(_isValidSignatureAndData(msg.sender, _signature));
6464
_;
6565
}
6666

@@ -72,7 +72,7 @@ contract SignatureBouncer is Ownable, RBAC {
7272
onlyOwner
7373
{
7474
require(_bouncer != address(0));
75-
addRole(_bouncer, ROLE_BOUNCER);
75+
_addRole(_bouncer, ROLE_BOUNCER);
7676
}
7777

7878
/**
@@ -82,19 +82,19 @@ contract SignatureBouncer is Ownable, RBAC {
8282
public
8383
onlyOwner
8484
{
85-
removeRole(_bouncer, ROLE_BOUNCER);
85+
_removeRole(_bouncer, ROLE_BOUNCER);
8686
}
8787

8888
/**
8989
* @dev is the signature of `this + sender` from a bouncer?
9090
* @return bool
9191
*/
92-
function isValidSignature(address _address, bytes _signature)
92+
function _isValidSignature(address _address, bytes _signature)
9393
internal
9494
view
9595
returns (bool)
9696
{
97-
return isValidDataHash(
97+
return _isValidDataHash(
9898
keccak256(abi.encodePacked(address(this), _address)),
9999
_signature
100100
);
@@ -104,7 +104,7 @@ contract SignatureBouncer is Ownable, RBAC {
104104
* @dev is the signature of `this + sender + methodId` from a bouncer?
105105
* @return bool
106106
*/
107-
function isValidSignatureAndMethod(address _address, bytes _signature)
107+
function _isValidSignatureAndMethod(address _address, bytes _signature)
108108
internal
109109
view
110110
returns (bool)
@@ -113,7 +113,7 @@ contract SignatureBouncer is Ownable, RBAC {
113113
for (uint i = 0; i < data.length; i++) {
114114
data[i] = msg.data[i];
115115
}
116-
return isValidDataHash(
116+
return _isValidDataHash(
117117
keccak256(abi.encodePacked(address(this), _address, data)),
118118
_signature
119119
);
@@ -124,7 +124,7 @@ contract SignatureBouncer is Ownable, RBAC {
124124
* @notice the _signature parameter of the method being validated must be the "last" parameter
125125
* @return bool
126126
*/
127-
function isValidSignatureAndData(address _address, bytes _signature)
127+
function _isValidSignatureAndData(address _address, bytes _signature)
128128
internal
129129
view
130130
returns (bool)
@@ -134,7 +134,7 @@ contract SignatureBouncer is Ownable, RBAC {
134134
for (uint i = 0; i < data.length; i++) {
135135
data[i] = msg.data[i];
136136
}
137-
return isValidDataHash(
137+
return _isValidDataHash(
138138
keccak256(abi.encodePacked(address(this), _address, data)),
139139
_signature
140140
);
@@ -145,7 +145,7 @@ contract SignatureBouncer is Ownable, RBAC {
145145
* and then recover the signature and check it against the bouncer role
146146
* @return bool
147147
*/
148-
function isValidDataHash(bytes32 _hash, bytes _signature)
148+
function _isValidDataHash(bytes32 _hash, bytes _signature)
149149
internal
150150
view
151151
returns (bool)

contracts/access/Whitelist.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contract Whitelist is Ownable, RBAC {
3131
public
3232
onlyOwner
3333
{
34-
addRole(_operator, ROLE_WHITELISTED);
34+
_addRole(_operator, ROLE_WHITELISTED);
3535
}
3636

3737
/**
@@ -70,7 +70,7 @@ contract Whitelist is Ownable, RBAC {
7070
public
7171
onlyOwner
7272
{
73-
removeRole(_operator, ROLE_WHITELISTED);
73+
_removeRole(_operator, ROLE_WHITELISTED);
7474
}
7575

7676
/**

contracts/access/rbac/RBAC.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ contract RBAC {
5252
* @param _operator address
5353
* @param _role the name of the role
5454
*/
55-
function addRole(address _operator, string _role)
55+
function _addRole(address _operator, string _role)
5656
internal
5757
{
5858
roles[_role].add(_operator);
@@ -64,7 +64,7 @@ contract RBAC {
6464
* @param _operator address
6565
* @param _role the name of the role
6666
*/
67-
function removeRole(address _operator, string _role)
67+
function _removeRole(address _operator, string _role)
6868
internal
6969
{
7070
roles[_role].remove(_operator);

contracts/bounties/BreakInvariantBounty.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
2727
* @return A target contract
2828
*/
2929
function createTarget() public returns(Target) {
30-
Target target = Target(deployContract());
30+
Target target = Target(_deployContract());
3131
researchers[target] = msg.sender;
3232
emit TargetCreated(target);
3333
return target;
@@ -42,7 +42,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
4242
require(researcher != address(0));
4343
// Check Target contract invariants
4444
require(!_target.checkInvariant());
45-
asyncTransfer(researcher, address(this).balance);
45+
_asyncTransfer(researcher, address(this).balance);
4646
claimed = true;
4747
}
4848

@@ -57,7 +57,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
5757
* @dev Internal function to deploy the target contract.
5858
* @return A target contract address
5959
*/
60-
function deployContract() internal returns(address);
60+
function _deployContract() internal returns(address);
6161

6262
}
6363

contracts/crowdsale/distribution/FinalizableCrowdsale.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
2525
require(!isFinalized);
2626
require(hasClosed());
2727

28-
finalization();
28+
_finalization();
2929
emit CrowdsaleFinalized();
3030

3131
isFinalized = true;
3232
}
3333

3434
/**
3535
* @dev Can be overridden to add finalization logic. The overriding function
36-
* should call super.finalization() to ensure the chain of finalization is
36+
* should call super._finalization() to ensure the chain of finalization is
3737
* executed entirely.
3838
*/
39-
function finalization() internal {
39+
function _finalization() internal {
4040
}
4141

4242
}

contracts/crowdsale/distribution/RefundableCrowdsale.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
5151
/**
5252
* @dev escrow finalization task, called when owner calls finalize()
5353
*/
54-
function finalization() internal {
54+
function _finalization() internal {
5555
if (goalReached()) {
5656
escrow_.close();
5757
escrow_.beneficiaryWithdraw();
5858
} else {
5959
escrow_.enableRefunds();
6060
}
6161

62-
super.finalization();
62+
super._finalization();
6363
}
6464

6565
/**

contracts/examples/RBACWithAdmin.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract RBACWithAdmin is RBAC {
3737
constructor()
3838
public
3939
{
40-
addRole(msg.sender, ROLE_ADMIN);
40+
_addRole(msg.sender, ROLE_ADMIN);
4141
}
4242

4343
/**
@@ -49,7 +49,7 @@ contract RBACWithAdmin is RBAC {
4949
public
5050
onlyAdmin
5151
{
52-
addRole(_account, _roleName);
52+
_addRole(_account, _roleName);
5353
}
5454

5555
/**
@@ -61,6 +61,6 @@ contract RBACWithAdmin is RBAC {
6161
public
6262
onlyAdmin
6363
{
64-
removeRole(_account, _roleName);
64+
_removeRole(_account, _roleName);
6565
}
6666
}

contracts/mocks/BouncerMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract SignatureBouncerMock is SignatureBouncer {
99
view
1010
returns (bool)
1111
{
12-
return isValidSignature(_address, _signature);
12+
return _isValidSignature(_address, _signature);
1313
}
1414

1515
function onlyWithValidSignature(bytes _signature)
@@ -25,7 +25,7 @@ contract SignatureBouncerMock is SignatureBouncer {
2525
view
2626
returns (bool)
2727
{
28-
return isValidSignatureAndMethod(_address, _signature);
28+
return _isValidSignatureAndMethod(_address, _signature);
2929
}
3030

3131
function onlyWithValidSignatureAndMethod(bytes _signature)
@@ -46,7 +46,7 @@ contract SignatureBouncerMock is SignatureBouncer {
4646
view
4747
returns (bool)
4848
{
49-
return isValidSignatureAndData(_address, _signature);
49+
return _isValidSignatureAndData(_address, _signature);
5050
}
5151

5252
function onlyWithValidSignatureAndData(uint, bytes _signature)

contracts/mocks/ERC721Mock.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ contract ERC721Mock is ERC721 {
1414
{ }
1515

1616
function mint(address _to, uint256 _tokenId) public {
17-
super._mint(_to, _tokenId);
17+
_mint(_to, _tokenId);
1818
}
1919

2020
function burn(uint256 _tokenId) public {
21-
super._burn(ownerOf(_tokenId), _tokenId);
21+
_burn(ownerOf(_tokenId), _tokenId);
2222
}
2323

2424
function exists(uint256 _tokenId) public view returns (bool) {
25-
return super._exists(_tokenId);
25+
return _exists(_tokenId);
2626
}
2727

2828
function setTokenURI(uint256 _tokenId, string _uri) public {
29-
super._setTokenURI(_tokenId, _uri);
29+
_setTokenURI(_tokenId, _uri);
3030
}
3131

32-
function _removeTokenFrom(address _from, uint256 _tokenId) public {
33-
super.removeTokenFrom(_from, _tokenId);
32+
function removeTokenFrom(address _from, uint256 _tokenId) public {
33+
_removeTokenFrom(_from, _tokenId);
3434
}
3535
}

0 commit comments

Comments
 (0)