Commit b0f20d43 by Leo Arias Committed by Francisco Giordano

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
parent fbfd1fed
...@@ -43,8 +43,22 @@ Any exception or additions specific to our project are documented below. ...@@ -43,8 +43,22 @@ Any exception or additions specific to our project are documented below.
``` ```
function test() { function test() {
uint256 functionVar; uint256 functionVar;
... ...
}
```
* Internal and private functions should have an underscore prefix.
```
function _testInternal() internal {
...
}
```
```
function _testPrivate() private {
...
} }
``` ```
......
...@@ -17,7 +17,7 @@ import "../cryptography/ECDSA.sol"; ...@@ -17,7 +17,7 @@ import "../cryptography/ECDSA.sol";
* valid addresses on-chain, simply sign a grant of the form * valid addresses on-chain, simply sign a grant of the form
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address. * keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
* Then restrict access to your crowdsale/whitelist/airdrop using the * Then restrict access to your crowdsale/whitelist/airdrop using the
* `onlyValidSignature` modifier (or implement your own using isValidSignature). * `onlyValidSignature` modifier (or implement your own using _isValidSignature).
* In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and * In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and
* `onlyValidSignatureAndData` can be used to restrict access to only a given method * `onlyValidSignatureAndData` can be used to restrict access to only a given method
* or a given method with given parameters respectively. * or a given method with given parameters respectively.
...@@ -42,7 +42,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -42,7 +42,7 @@ contract SignatureBouncer is Ownable, RBAC {
*/ */
modifier onlyValidSignature(bytes _signature) modifier onlyValidSignature(bytes _signature)
{ {
require(isValidSignature(msg.sender, _signature)); require(_isValidSignature(msg.sender, _signature));
_; _;
} }
...@@ -51,7 +51,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -51,7 +51,7 @@ contract SignatureBouncer is Ownable, RBAC {
*/ */
modifier onlyValidSignatureAndMethod(bytes _signature) modifier onlyValidSignatureAndMethod(bytes _signature)
{ {
require(isValidSignatureAndMethod(msg.sender, _signature)); require(_isValidSignatureAndMethod(msg.sender, _signature));
_; _;
} }
...@@ -60,7 +60,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -60,7 +60,7 @@ contract SignatureBouncer is Ownable, RBAC {
*/ */
modifier onlyValidSignatureAndData(bytes _signature) modifier onlyValidSignatureAndData(bytes _signature)
{ {
require(isValidSignatureAndData(msg.sender, _signature)); require(_isValidSignatureAndData(msg.sender, _signature));
_; _;
} }
...@@ -72,7 +72,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -72,7 +72,7 @@ contract SignatureBouncer is Ownable, RBAC {
onlyOwner onlyOwner
{ {
require(_bouncer != address(0)); require(_bouncer != address(0));
addRole(_bouncer, ROLE_BOUNCER); _addRole(_bouncer, ROLE_BOUNCER);
} }
/** /**
...@@ -82,19 +82,19 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -82,19 +82,19 @@ contract SignatureBouncer is Ownable, RBAC {
public public
onlyOwner onlyOwner
{ {
removeRole(_bouncer, ROLE_BOUNCER); _removeRole(_bouncer, ROLE_BOUNCER);
} }
/** /**
* @dev is the signature of `this + sender` from a bouncer? * @dev is the signature of `this + sender` from a bouncer?
* @return bool * @return bool
*/ */
function isValidSignature(address _address, bytes _signature) function _isValidSignature(address _address, bytes _signature)
internal internal
view view
returns (bool) returns (bool)
{ {
return isValidDataHash( return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address)), keccak256(abi.encodePacked(address(this), _address)),
_signature _signature
); );
...@@ -104,7 +104,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -104,7 +104,7 @@ contract SignatureBouncer is Ownable, RBAC {
* @dev is the signature of `this + sender + methodId` from a bouncer? * @dev is the signature of `this + sender + methodId` from a bouncer?
* @return bool * @return bool
*/ */
function isValidSignatureAndMethod(address _address, bytes _signature) function _isValidSignatureAndMethod(address _address, bytes _signature)
internal internal
view view
returns (bool) returns (bool)
...@@ -113,7 +113,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -113,7 +113,7 @@ contract SignatureBouncer is Ownable, RBAC {
for (uint i = 0; i < data.length; i++) { for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i]; data[i] = msg.data[i];
} }
return isValidDataHash( return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address, data)), keccak256(abi.encodePacked(address(this), _address, data)),
_signature _signature
); );
...@@ -124,7 +124,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -124,7 +124,7 @@ contract SignatureBouncer is Ownable, RBAC {
* @notice the _signature parameter of the method being validated must be the "last" parameter * @notice the _signature parameter of the method being validated must be the "last" parameter
* @return bool * @return bool
*/ */
function isValidSignatureAndData(address _address, bytes _signature) function _isValidSignatureAndData(address _address, bytes _signature)
internal internal
view view
returns (bool) returns (bool)
...@@ -134,7 +134,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -134,7 +134,7 @@ contract SignatureBouncer is Ownable, RBAC {
for (uint i = 0; i < data.length; i++) { for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i]; data[i] = msg.data[i];
} }
return isValidDataHash( return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address, data)), keccak256(abi.encodePacked(address(this), _address, data)),
_signature _signature
); );
...@@ -145,7 +145,7 @@ contract SignatureBouncer is Ownable, RBAC { ...@@ -145,7 +145,7 @@ contract SignatureBouncer is Ownable, RBAC {
* and then recover the signature and check it against the bouncer role * and then recover the signature and check it against the bouncer role
* @return bool * @return bool
*/ */
function isValidDataHash(bytes32 _hash, bytes _signature) function _isValidDataHash(bytes32 _hash, bytes _signature)
internal internal
view view
returns (bool) returns (bool)
......
...@@ -31,7 +31,7 @@ contract Whitelist is Ownable, RBAC { ...@@ -31,7 +31,7 @@ contract Whitelist is Ownable, RBAC {
public public
onlyOwner onlyOwner
{ {
addRole(_operator, ROLE_WHITELISTED); _addRole(_operator, ROLE_WHITELISTED);
} }
/** /**
...@@ -70,7 +70,7 @@ contract Whitelist is Ownable, RBAC { ...@@ -70,7 +70,7 @@ contract Whitelist is Ownable, RBAC {
public public
onlyOwner onlyOwner
{ {
removeRole(_operator, ROLE_WHITELISTED); _removeRole(_operator, ROLE_WHITELISTED);
} }
/** /**
......
...@@ -52,7 +52,7 @@ contract RBAC { ...@@ -52,7 +52,7 @@ contract RBAC {
* @param _operator address * @param _operator address
* @param _role the name of the role * @param _role the name of the role
*/ */
function addRole(address _operator, string _role) function _addRole(address _operator, string _role)
internal internal
{ {
roles[_role].add(_operator); roles[_role].add(_operator);
...@@ -64,7 +64,7 @@ contract RBAC { ...@@ -64,7 +64,7 @@ contract RBAC {
* @param _operator address * @param _operator address
* @param _role the name of the role * @param _role the name of the role
*/ */
function removeRole(address _operator, string _role) function _removeRole(address _operator, string _role)
internal internal
{ {
roles[_role].remove(_operator); roles[_role].remove(_operator);
......
...@@ -27,7 +27,7 @@ contract BreakInvariantBounty is PullPayment, Ownable { ...@@ -27,7 +27,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
* @return A target contract * @return A target contract
*/ */
function createTarget() public returns(Target) { function createTarget() public returns(Target) {
Target target = Target(deployContract()); Target target = Target(_deployContract());
researchers[target] = msg.sender; researchers[target] = msg.sender;
emit TargetCreated(target); emit TargetCreated(target);
return target; return target;
...@@ -42,7 +42,7 @@ contract BreakInvariantBounty is PullPayment, Ownable { ...@@ -42,7 +42,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
require(researcher != address(0)); require(researcher != address(0));
// Check Target contract invariants // Check Target contract invariants
require(!_target.checkInvariant()); require(!_target.checkInvariant());
asyncTransfer(researcher, address(this).balance); _asyncTransfer(researcher, address(this).balance);
claimed = true; claimed = true;
} }
...@@ -57,7 +57,7 @@ contract BreakInvariantBounty is PullPayment, Ownable { ...@@ -57,7 +57,7 @@ contract BreakInvariantBounty is PullPayment, Ownable {
* @dev Internal function to deploy the target contract. * @dev Internal function to deploy the target contract.
* @return A target contract address * @return A target contract address
*/ */
function deployContract() internal returns(address); function _deployContract() internal returns(address);
} }
......
...@@ -25,7 +25,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale { ...@@ -25,7 +25,7 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
require(!isFinalized); require(!isFinalized);
require(hasClosed()); require(hasClosed());
finalization(); _finalization();
emit CrowdsaleFinalized(); emit CrowdsaleFinalized();
isFinalized = true; isFinalized = true;
...@@ -33,10 +33,10 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale { ...@@ -33,10 +33,10 @@ contract FinalizableCrowdsale is Ownable, TimedCrowdsale {
/** /**
* @dev Can be overridden to add finalization logic. The overriding function * @dev Can be overridden to add finalization logic. The overriding function
* should call super.finalization() to ensure the chain of finalization is * should call super._finalization() to ensure the chain of finalization is
* executed entirely. * executed entirely.
*/ */
function finalization() internal { function _finalization() internal {
} }
} }
...@@ -51,7 +51,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { ...@@ -51,7 +51,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
/** /**
* @dev escrow finalization task, called when owner calls finalize() * @dev escrow finalization task, called when owner calls finalize()
*/ */
function finalization() internal { function _finalization() internal {
if (goalReached()) { if (goalReached()) {
escrow_.close(); escrow_.close();
escrow_.beneficiaryWithdraw(); escrow_.beneficiaryWithdraw();
...@@ -59,7 +59,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { ...@@ -59,7 +59,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
escrow_.enableRefunds(); escrow_.enableRefunds();
} }
super.finalization(); super._finalization();
} }
/** /**
......
...@@ -37,7 +37,7 @@ contract RBACWithAdmin is RBAC { ...@@ -37,7 +37,7 @@ contract RBACWithAdmin is RBAC {
constructor() constructor()
public public
{ {
addRole(msg.sender, ROLE_ADMIN); _addRole(msg.sender, ROLE_ADMIN);
} }
/** /**
...@@ -49,7 +49,7 @@ contract RBACWithAdmin is RBAC { ...@@ -49,7 +49,7 @@ contract RBACWithAdmin is RBAC {
public public
onlyAdmin onlyAdmin
{ {
addRole(_account, _roleName); _addRole(_account, _roleName);
} }
/** /**
...@@ -61,6 +61,6 @@ contract RBACWithAdmin is RBAC { ...@@ -61,6 +61,6 @@ contract RBACWithAdmin is RBAC {
public public
onlyAdmin onlyAdmin
{ {
removeRole(_account, _roleName); _removeRole(_account, _roleName);
} }
} }
...@@ -9,7 +9,7 @@ contract SignatureBouncerMock is SignatureBouncer { ...@@ -9,7 +9,7 @@ contract SignatureBouncerMock is SignatureBouncer {
view view
returns (bool) returns (bool)
{ {
return isValidSignature(_address, _signature); return _isValidSignature(_address, _signature);
} }
function onlyWithValidSignature(bytes _signature) function onlyWithValidSignature(bytes _signature)
...@@ -25,7 +25,7 @@ contract SignatureBouncerMock is SignatureBouncer { ...@@ -25,7 +25,7 @@ contract SignatureBouncerMock is SignatureBouncer {
view view
returns (bool) returns (bool)
{ {
return isValidSignatureAndMethod(_address, _signature); return _isValidSignatureAndMethod(_address, _signature);
} }
function onlyWithValidSignatureAndMethod(bytes _signature) function onlyWithValidSignatureAndMethod(bytes _signature)
...@@ -46,7 +46,7 @@ contract SignatureBouncerMock is SignatureBouncer { ...@@ -46,7 +46,7 @@ contract SignatureBouncerMock is SignatureBouncer {
view view
returns (bool) returns (bool)
{ {
return isValidSignatureAndData(_address, _signature); return _isValidSignatureAndData(_address, _signature);
} }
function onlyWithValidSignatureAndData(uint, bytes _signature) function onlyWithValidSignatureAndData(uint, bytes _signature)
......
...@@ -14,22 +14,22 @@ contract ERC721Mock is ERC721 { ...@@ -14,22 +14,22 @@ contract ERC721Mock is ERC721 {
{ } { }
function mint(address _to, uint256 _tokenId) public { function mint(address _to, uint256 _tokenId) public {
super._mint(_to, _tokenId); _mint(_to, _tokenId);
} }
function burn(uint256 _tokenId) public { function burn(uint256 _tokenId) public {
super._burn(ownerOf(_tokenId), _tokenId); _burn(ownerOf(_tokenId), _tokenId);
} }
function exists(uint256 _tokenId) public view returns (bool) { function exists(uint256 _tokenId) public view returns (bool) {
return super._exists(_tokenId); return _exists(_tokenId);
} }
function setTokenURI(uint256 _tokenId, string _uri) public { function setTokenURI(uint256 _tokenId, string _uri) public {
super._setTokenURI(_tokenId, _uri); _setTokenURI(_tokenId, _uri);
} }
function _removeTokenFrom(address _from, uint256 _tokenId) public { function removeTokenFrom(address _from, uint256 _tokenId) public {
super.removeTokenFrom(_from, _tokenId); _removeTokenFrom(_from, _tokenId);
} }
} }
...@@ -14,7 +14,7 @@ contract InsecureInvariantTargetMock is Target { ...@@ -14,7 +14,7 @@ contract InsecureInvariantTargetMock is Target {
contract InsecureInvariantTargetBounty is BreakInvariantBounty { contract InsecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) { function _deployContract() internal returns (address) {
return new InsecureInvariantTargetMock(); return new InsecureInvariantTargetMock();
} }
} }
...@@ -11,7 +11,7 @@ contract PullPaymentMock is PullPayment { ...@@ -11,7 +11,7 @@ contract PullPaymentMock is PullPayment {
// test helper function to call asyncTransfer // test helper function to call asyncTransfer
function callTransfer(address _dest, uint256 _amount) public { function callTransfer(address _dest, uint256 _amount) public {
asyncTransfer(_dest, _amount); _asyncTransfer(_dest, _amount);
} }
} }
...@@ -19,10 +19,10 @@ contract RBACMock is RBACWithAdmin { ...@@ -19,10 +19,10 @@ contract RBACMock is RBACWithAdmin {
constructor(address[] _advisors) constructor(address[] _advisors)
public public
{ {
addRole(msg.sender, ROLE_ADVISOR); _addRole(msg.sender, ROLE_ADVISOR);
for (uint256 i = 0; i < _advisors.length; i++) { for (uint256 i = 0; i < _advisors.length; i++) {
addRole(_advisors[i], ROLE_ADVISOR); _addRole(_advisors[i], ROLE_ADVISOR);
} }
} }
...@@ -64,6 +64,6 @@ contract RBACMock is RBACWithAdmin { ...@@ -64,6 +64,6 @@ contract RBACMock is RBACWithAdmin {
checkRole(_account, ROLE_ADVISOR); checkRole(_account, ROLE_ADVISOR);
// remove the advisor's role // remove the advisor's role
removeRole(_account, ROLE_ADVISOR); _removeRole(_account, ROLE_ADVISOR);
} }
} }
...@@ -14,7 +14,7 @@ contract SecureInvariantTargetMock is Target { ...@@ -14,7 +14,7 @@ contract SecureInvariantTargetMock is Target {
contract SecureInvariantTargetBounty is BreakInvariantBounty { contract SecureInvariantTargetBounty is BreakInvariantBounty {
function deployContract() internal returns (address) { function _deployContract() internal returns (address) {
return new SecureInvariantTargetMock(); return new SecureInvariantTargetMock();
} }
} }
...@@ -86,7 +86,7 @@ contract Heritable is Ownable { ...@@ -86,7 +86,7 @@ contract Heritable is Ownable {
* have to wait for `heartbeatTimeout` seconds. * have to wait for `heartbeatTimeout` seconds.
*/ */
function proclaimDeath() public onlyHeir { function proclaimDeath() public onlyHeir {
require(ownerLives()); require(_ownerLives());
emit OwnerProclaimedDead(owner, heir_, timeOfDeath_); emit OwnerProclaimedDead(owner, heir_, timeOfDeath_);
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
timeOfDeath_ = block.timestamp; timeOfDeath_ = block.timestamp;
...@@ -104,7 +104,7 @@ contract Heritable is Ownable { ...@@ -104,7 +104,7 @@ contract Heritable is Ownable {
* @dev Allows heir to transfer ownership only if heartbeat has timed out. * @dev Allows heir to transfer ownership only if heartbeat has timed out.
*/ */
function claimHeirOwnership() public onlyHeir { function claimHeirOwnership() public onlyHeir {
require(!ownerLives()); require(!_ownerLives());
// solium-disable-next-line security/no-block-members // solium-disable-next-line security/no-block-members
require(block.timestamp >= timeOfDeath_ + heartbeatTimeout_); require(block.timestamp >= timeOfDeath_ + heartbeatTimeout_);
emit OwnershipTransferred(owner, heir_); emit OwnershipTransferred(owner, heir_);
...@@ -113,7 +113,7 @@ contract Heritable is Ownable { ...@@ -113,7 +113,7 @@ contract Heritable is Ownable {
timeOfDeath_ = 0; timeOfDeath_ = 0;
} }
function ownerLives() internal view returns (bool) { function _ownerLives() internal view returns (bool) {
return timeOfDeath_ == 0; return timeOfDeath_ == 0;
} }
} }
...@@ -15,7 +15,7 @@ contract Superuser is Ownable, RBAC { ...@@ -15,7 +15,7 @@ contract Superuser is Ownable, RBAC {
string public constant ROLE_SUPERUSER = "superuser"; string public constant ROLE_SUPERUSER = "superuser";
constructor () public { constructor () public {
addRole(msg.sender, ROLE_SUPERUSER); _addRole(msg.sender, ROLE_SUPERUSER);
} }
/** /**
...@@ -48,8 +48,8 @@ contract Superuser is Ownable, RBAC { ...@@ -48,8 +48,8 @@ contract Superuser is Ownable, RBAC {
*/ */
function transferSuperuser(address _newSuperuser) public onlySuperuser { function transferSuperuser(address _newSuperuser) public onlySuperuser {
require(_newSuperuser != address(0)); require(_newSuperuser != address(0));
removeRole(msg.sender, ROLE_SUPERUSER); _removeRole(msg.sender, ROLE_SUPERUSER);
addRole(_newSuperuser, ROLE_SUPERUSER); _addRole(_newSuperuser, ROLE_SUPERUSER);
} }
/** /**
......
...@@ -6,7 +6,7 @@ import "./Escrow.sol"; ...@@ -6,7 +6,7 @@ import "./Escrow.sol";
/** /**
* @title PullPayment * @title PullPayment
* @dev Base contract supporting async send for pull payments. Inherit from this * @dev Base contract supporting async send for pull payments. Inherit from this
* contract and use asyncTransfer instead of send or transfer. * contract and use _asyncTransfer instead of send or transfer.
*/ */
contract PullPayment { contract PullPayment {
Escrow private escrow; Escrow private escrow;
...@@ -36,7 +36,7 @@ contract PullPayment { ...@@ -36,7 +36,7 @@ contract PullPayment {
* @param _dest The destination address of the funds. * @param _dest The destination address of the funds.
* @param _amount The amount to transfer. * @param _amount The amount to transfer.
*/ */
function asyncTransfer(address _dest, uint256 _amount) internal { function _asyncTransfer(address _dest, uint256 _amount) internal {
escrow.deposit.value(_amount)(_dest); escrow.deposit.value(_amount)(_dest);
} }
} }
...@@ -26,7 +26,7 @@ contract SplitPayment { ...@@ -26,7 +26,7 @@ contract SplitPayment {
require(_payees.length > 0); require(_payees.length > 0);
for (uint256 i = 0; i < _payees.length; i++) { for (uint256 i = 0; i < _payees.length; i++) {
addPayee(_payees[i], _shares[i]); _addPayee(_payees[i], _shares[i]);
} }
} }
...@@ -64,7 +64,7 @@ contract SplitPayment { ...@@ -64,7 +64,7 @@ contract SplitPayment {
* @param _payee The address of the payee to add. * @param _payee The address of the payee to add.
* @param _shares The number of shares owned by the payee. * @param _shares The number of shares owned by the payee.
*/ */
function addPayee(address _payee, uint256 _shares) internal { function _addPayee(address _payee, uint256 _shares) internal {
require(_payee != address(0)); require(_payee != address(0));
require(_shares > 0); require(_shares > 0);
require(shares[_payee] == 0); require(shares[_payee] == 0);
......
...@@ -28,7 +28,7 @@ contract RBACMintableToken is ERC20Mintable, RBAC { ...@@ -28,7 +28,7 @@ contract RBACMintableToken is ERC20Mintable, RBAC {
* @param _minter address * @param _minter address
*/ */
function addMinter(address _minter) public onlyOwner { function addMinter(address _minter) public onlyOwner {
addRole(_minter, ROLE_MINTER); _addRole(_minter, ROLE_MINTER);
} }
/** /**
...@@ -36,6 +36,6 @@ contract RBACMintableToken is ERC20Mintable, RBAC { ...@@ -36,6 +36,6 @@ contract RBACMintableToken is ERC20Mintable, RBAC {
* @param _minter address * @param _minter address
*/ */
function removeMinter(address _minter) public onlyOwner { function removeMinter(address _minter) public onlyOwner {
removeRole(_minter, ROLE_MINTER); _removeRole(_minter, ROLE_MINTER);
} }
} }
...@@ -125,8 +125,8 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 { ...@@ -125,8 +125,8 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
* @param _to address representing the new owner of the given token ID * @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/ */
function addTokenTo(address _to, uint256 _tokenId) internal { function _addTokenTo(address _to, uint256 _tokenId) internal {
super.addTokenTo(_to, _tokenId); super._addTokenTo(_to, _tokenId);
uint256 length = ownedTokens[_to].length; uint256 length = ownedTokens[_to].length;
ownedTokens[_to].push(_tokenId); ownedTokens[_to].push(_tokenId);
ownedTokensIndex[_tokenId] = length; ownedTokensIndex[_tokenId] = length;
...@@ -137,8 +137,8 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 { ...@@ -137,8 +137,8 @@ contract ERC721 is SupportsInterfaceWithLookup, ERC721Basic, IERC721 {
* @param _from address representing the previous owner of the given token ID * @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/ */
function removeTokenFrom(address _from, uint256 _tokenId) internal { function _removeTokenFrom(address _from, uint256 _tokenId) internal {
super.removeTokenFrom(_from, _tokenId); super._removeTokenFrom(_from, _tokenId);
// To prevent a gap in the array, we store the last token in the index of the token to delete, and // To prevent a gap in the array, we store the last token in the index of the token to delete, and
// then delete the last slot. // then delete the last slot.
......
...@@ -130,12 +130,12 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -130,12 +130,12 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
) )
public public
{ {
require(isApprovedOrOwner(msg.sender, _tokenId)); require(_isApprovedOrOwner(msg.sender, _tokenId));
require(_to != address(0)); require(_to != address(0));
clearApproval(_from, _tokenId); _clearApproval(_from, _tokenId);
removeTokenFrom(_from, _tokenId); _removeTokenFrom(_from, _tokenId);
addTokenTo(_to, _tokenId); _addTokenTo(_to, _tokenId);
emit Transfer(_from, _to, _tokenId); emit Transfer(_from, _to, _tokenId);
} }
...@@ -185,7 +185,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -185,7 +185,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
{ {
transferFrom(_from, _to, _tokenId); transferFrom(_from, _to, _tokenId);
// solium-disable-next-line arg-overflow // solium-disable-next-line arg-overflow
require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data)); require(_checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
} }
/** /**
...@@ -205,7 +205,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -205,7 +205,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @return bool whether the msg.sender is approved for the given token ID, * @return bool whether the msg.sender is approved for the given token ID,
* is an operator of the owner, or is the owner of the token * is an operator of the owner, or is the owner of the token
*/ */
function isApprovedOrOwner( function _isApprovedOrOwner(
address _spender, address _spender,
uint256 _tokenId uint256 _tokenId
) )
...@@ -232,7 +232,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -232,7 +232,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
*/ */
function _mint(address _to, uint256 _tokenId) internal { function _mint(address _to, uint256 _tokenId) internal {
require(_to != address(0)); require(_to != address(0));
addTokenTo(_to, _tokenId); _addTokenTo(_to, _tokenId);
emit Transfer(address(0), _to, _tokenId); emit Transfer(address(0), _to, _tokenId);
} }
...@@ -242,8 +242,8 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -242,8 +242,8 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _tokenId uint256 ID of the token being burned by the msg.sender * @param _tokenId uint256 ID of the token being burned by the msg.sender
*/ */
function _burn(address _owner, uint256 _tokenId) internal { function _burn(address _owner, uint256 _tokenId) internal {
clearApproval(_owner, _tokenId); _clearApproval(_owner, _tokenId);
removeTokenFrom(_owner, _tokenId); _removeTokenFrom(_owner, _tokenId);
emit Transfer(_owner, address(0), _tokenId); emit Transfer(_owner, address(0), _tokenId);
} }
...@@ -253,7 +253,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -253,7 +253,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _owner owner of the token * @param _owner owner of the token
* @param _tokenId uint256 ID of the token to be transferred * @param _tokenId uint256 ID of the token to be transferred
*/ */
function clearApproval(address _owner, uint256 _tokenId) internal { function _clearApproval(address _owner, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _owner); require(ownerOf(_tokenId) == _owner);
if (tokenApprovals[_tokenId] != address(0)) { if (tokenApprovals[_tokenId] != address(0)) {
tokenApprovals[_tokenId] = address(0); tokenApprovals[_tokenId] = address(0);
...@@ -265,7 +265,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -265,7 +265,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _to address representing the new owner of the given token ID * @param _to address representing the new owner of the given token ID
* @param _tokenId uint256 ID of the token to be added to the tokens list of the given address * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
*/ */
function addTokenTo(address _to, uint256 _tokenId) internal { function _addTokenTo(address _to, uint256 _tokenId) internal {
require(tokenOwner[_tokenId] == address(0)); require(tokenOwner[_tokenId] == address(0));
tokenOwner[_tokenId] = _to; tokenOwner[_tokenId] = _to;
ownedTokensCount[_to] = ownedTokensCount[_to].add(1); ownedTokensCount[_to] = ownedTokensCount[_to].add(1);
...@@ -276,7 +276,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -276,7 +276,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _from address representing the previous owner of the given token ID * @param _from address representing the previous owner of the given token ID
* @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/ */
function removeTokenFrom(address _from, uint256 _tokenId) internal { function _removeTokenFrom(address _from, uint256 _tokenId) internal {
require(ownerOf(_tokenId) == _from); require(ownerOf(_tokenId) == _from);
ownedTokensCount[_from] = ownedTokensCount[_from].sub(1); ownedTokensCount[_from] = ownedTokensCount[_from].sub(1);
tokenOwner[_tokenId] = address(0); tokenOwner[_tokenId] = address(0);
...@@ -291,7 +291,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic { ...@@ -291,7 +291,7 @@ contract ERC721Basic is SupportsInterfaceWithLookup, IERC721Basic {
* @param _data bytes optional data to send along with the call * @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value * @return whether the call correctly returned the expected magic value
*/ */
function checkAndCallSafeTransfer( function _checkAndCallSafeTransfer(
address _from, address _from,
address _to, address _to,
uint256 _tokenId, uint256 _tokenId,
......
...@@ -76,13 +76,13 @@ contract('ERC721', function (accounts) { ...@@ -76,13 +76,13 @@ contract('ERC721', function (accounts) {
describe('removeTokenFrom', function () { describe('removeTokenFrom', function () {
it('reverts if the correct owner is not passed', async function () { it('reverts if the correct owner is not passed', async function () {
await assertRevert( await assertRevert(
this.token._removeTokenFrom(anyone, firstTokenId, { from: creator }) this.token.removeTokenFrom(anyone, firstTokenId, { from: creator })
); );
}); });
context('once removed', function () { context('once removed', function () {
beforeEach(async function () { beforeEach(async function () {
await this.token._removeTokenFrom(creator, firstTokenId, { from: creator }); await this.token.removeTokenFrom(creator, firstTokenId, { from: creator });
}); });
it('has been removed', async function () { it('has been removed', async function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment