Unverified Commit 9e1c934f by Matt Condon Committed by GitHub

Various fixes and formatting chores (#885)

* fix: clean up solium linting errors

* fix: make various contracts natspec compliant

* fix: this.balance deprecated; convert to address(this).balance

* fix: contract.call deprecated and switch to gasleft()

* fix: ignore empty block rule project-wide

* fix: add ignore cases for the rest of the linting warnings
parent a7e91856
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"plugins": ["security"], "plugins": ["security"],
"rules": { "rules": {
"quotes": ["error", "double"], "quotes": ["error", "double"],
"no-empty-blocks": "off",
"indentation": ["error", 2], "indentation": ["error", 2],
"arg-overflow": ["warning", 3], "arg-overflow": ["warning", 3],
"security/enforce-explicit-visibility": ["error"], "security/enforce-explicit-visibility": ["error"],
......
...@@ -43,7 +43,7 @@ contract Bounty is PullPayment, Destructible { ...@@ -43,7 +43,7 @@ contract Bounty is PullPayment, Destructible {
require(researcher != 0); require(researcher != 0);
// Check Target contract invariants // Check Target contract invariants
require(!target.checkInvariant()); require(!target.checkInvariant());
asyncSend(researcher, this.balance); asyncSend(researcher, address(this).balance);
claimed = true; claimed = true;
} }
......
...@@ -61,6 +61,7 @@ contract DayLimit { ...@@ -61,6 +61,7 @@ contract DayLimit {
* @return uint256 of today's index. * @return uint256 of today's index.
*/ */
function today() private view returns (uint256) { function today() private view returns (uint256) {
// solium-disable-next-line security/no-block-members
return block.timestamp / 1 days; return block.timestamp / 1 days;
} }
......
...@@ -47,6 +47,7 @@ library ECRecovery { ...@@ -47,6 +47,7 @@ library ECRecovery {
if (v != 27 && v != 28) { if (v != 27 && v != 28) {
return (address(0)); return (address(0));
} else { } else {
// solium-disable-next-line arg-overflow
return ecrecover(hash, v, r, s); return ecrecover(hash, v, r, s);
} }
} }
......
...@@ -23,7 +23,7 @@ contract LimitBalance { ...@@ -23,7 +23,7 @@ contract LimitBalance {
* @dev Checks if limit was reached. Case true, it throws. * @dev Checks if limit was reached. Case true, it throws.
*/ */
modifier limitedPayable() { modifier limitedPayable() {
require(this.balance <= limit); require(address(this).balance <= limit);
_; _;
} }
......
...@@ -12,7 +12,7 @@ contract ReentrancyGuard { ...@@ -12,7 +12,7 @@ contract ReentrancyGuard {
/** /**
* @dev We use a single lock for the whole contract. * @dev We use a single lock for the whole contract.
*/ */
bool private reentrancy_lock = false; bool private reentrancyLock = false;
/** /**
* @dev Prevents a contract from calling itself, directly or indirectly. * @dev Prevents a contract from calling itself, directly or indirectly.
...@@ -23,10 +23,10 @@ contract ReentrancyGuard { ...@@ -23,10 +23,10 @@ contract ReentrancyGuard {
* wrapper marked as `nonReentrant`. * wrapper marked as `nonReentrant`.
*/ */
modifier nonReentrant() { modifier nonReentrant() {
require(!reentrancy_lock); require(!reentrancyLock);
reentrancy_lock = true; reentrancyLock = true;
_; _;
reentrancy_lock = false; reentrancyLock = false;
} }
} }
...@@ -82,7 +82,12 @@ contract Crowdsale { ...@@ -82,7 +82,12 @@ contract Crowdsale {
weiRaised = weiRaised.add(weiAmount); weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens); _processPurchase(_beneficiary, tokens);
emit TokenPurchase(msg.sender, _beneficiary, weiAmount, tokens); emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount); _updatePurchasingState(_beneficiary, weiAmount);
......
...@@ -44,7 +44,7 @@ contract RefundVault is Ownable { ...@@ -44,7 +44,7 @@ contract RefundVault is Ownable {
require(state == State.Active); require(state == State.Active);
state = State.Closed; state = State.Closed;
emit Closed(); emit Closed();
wallet.transfer(this.balance); wallet.transfer(address(this).balance);
} }
function enableRefunds() onlyOwner public { function enableRefunds() onlyOwner public {
......
...@@ -34,6 +34,7 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale { ...@@ -34,6 +34,7 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
* @return The number of tokens a buyer gets per wei at a given time * @return The number of tokens a buyer gets per wei at a given time
*/ */
function getCurrentRate() public view returns (uint256) { function getCurrentRate() public view returns (uint256) {
// solium-disable-next-line security/no-block-members
uint256 elapsedTime = block.timestamp.sub(openingTime); uint256 elapsedTime = block.timestamp.sub(openingTime);
uint256 timeRange = closingTime.sub(openingTime); uint256 timeRange = closingTime.sub(openingTime);
uint256 rateRange = initialRate.sub(finalRate); uint256 rateRange = initialRate.sub(finalRate);
......
...@@ -18,6 +18,7 @@ contract TimedCrowdsale is Crowdsale { ...@@ -18,6 +18,7 @@ contract TimedCrowdsale is Crowdsale {
* @dev Reverts if not in crowdsale time range. * @dev Reverts if not in crowdsale time range.
*/ */
modifier onlyWhileOpen { modifier onlyWhileOpen {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= openingTime && block.timestamp <= closingTime); require(block.timestamp >= openingTime && block.timestamp <= closingTime);
_; _;
} }
...@@ -28,6 +29,7 @@ contract TimedCrowdsale is Crowdsale { ...@@ -28,6 +29,7 @@ contract TimedCrowdsale is Crowdsale {
* @param _closingTime Crowdsale closing time * @param _closingTime Crowdsale closing time
*/ */
function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public { function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public {
// solium-disable-next-line security/no-block-members
require(_openingTime >= block.timestamp); require(_openingTime >= block.timestamp);
require(_closingTime >= _openingTime); require(_closingTime >= _openingTime);
...@@ -40,6 +42,7 @@ contract TimedCrowdsale is Crowdsale { ...@@ -40,6 +42,7 @@ contract TimedCrowdsale is Crowdsale {
* @return Whether crowdsale period has elapsed * @return Whether crowdsale period has elapsed
*/ */
function hasClosed() public view returns (bool) { function hasClosed() public view returns (bool) {
// solium-disable-next-line security/no-block-members
return block.timestamp > closingTime; return block.timestamp > closingTime;
} }
......
...@@ -25,7 +25,7 @@ contract SimpleSavingsWallet is Heritable { ...@@ -25,7 +25,7 @@ contract SimpleSavingsWallet is Heritable {
* @dev wallet can receive funds. * @dev wallet can receive funds.
*/ */
function () public payable { function () public payable {
emit Received(msg.sender, msg.value, this.balance); emit Received(msg.sender, msg.value, address(this).balance);
} }
/** /**
...@@ -35,6 +35,6 @@ contract SimpleSavingsWallet is Heritable { ...@@ -35,6 +35,6 @@ contract SimpleSavingsWallet is Heritable {
require(payee != 0 && payee != address(this)); require(payee != 0 && payee != address(this));
require(amount > 0); require(amount > 0);
payee.transfer(amount); payee.transfer(amount);
emit Sent(payee, amount, this.balance); emit Sent(payee, amount, address(this).balance);
} }
} }
...@@ -21,6 +21,7 @@ contract ERC223TokenMock is BasicToken { ...@@ -21,6 +21,7 @@ contract ERC223TokenMock is BasicToken {
{ {
transfer(_to, _value); transfer(_to, _value);
bool isContract = false; bool isContract = false;
// solium-disable-next-line security/no-inline-assembly
assembly { assembly {
isContract := not(iszero(extcodesize(_to))) isContract := not(iszero(extcodesize(_to)))
} }
......
...@@ -14,9 +14,21 @@ contract ERC721ReceiverMock is ERC721Receiver { ...@@ -14,9 +14,21 @@ contract ERC721ReceiverMock is ERC721Receiver {
reverts = _reverts; reverts = _reverts;
} }
function onERC721Received(address _address, uint256 _tokenId, bytes _data) public returns(bytes4) { function onERC721Received(
address _address,
uint256 _tokenId,
bytes _data
)
public
returns(bytes4)
{
require(!reverts); require(!reverts);
emit Received(_address, _tokenId, _data, msg.gas); emit Received(
_address,
_tokenId,
_data,
gasleft() // msg.gas was deprecated in solidityv0.4.21
);
return retval; return retval;
} }
} }
...@@ -15,6 +15,7 @@ contract MessageHelper { ...@@ -15,6 +15,7 @@ contract MessageHelper {
} }
function call(address to, bytes data) public returns (bool) { function call(address to, bytes data) public returns (bool) {
// solium-disable-next-line security/no-low-level-calls
if (to.call(data)) if (to.call(data))
return true; return true;
else else
......
...@@ -4,6 +4,7 @@ pragma solidity ^0.4.21; ...@@ -4,6 +4,7 @@ pragma solidity ^0.4.21;
contract ReentrancyAttack { contract ReentrancyAttack {
function callSender(bytes4 data) public { function callSender(bytes4 data) public {
// solium-disable-next-line security/no-low-level-calls
require(msg.sender.call(data)); require(msg.sender.call(data));
} }
......
...@@ -27,7 +27,8 @@ contract ReentrancyMock is ReentrancyGuard { ...@@ -27,7 +27,8 @@ contract ReentrancyMock is ReentrancyGuard {
bytes4 func = bytes4(keccak256("countThisRecursive(uint256)")); bytes4 func = bytes4(keccak256("countThisRecursive(uint256)"));
if (n > 0) { if (n > 0) {
count(); count();
bool result = this.call(func, n - 1); // solium-disable-next-line security/no-low-level-calls
bool result = address(this).call(func, n - 1);
require(result == true); require(result == true);
} }
} }
......
...@@ -36,6 +36,7 @@ contract HasNoEther is Ownable { ...@@ -36,6 +36,7 @@ contract HasNoEther is Ownable {
* @dev Transfer all Ether held by the contract to the owner. * @dev Transfer all Ether held by the contract to the owner.
*/ */
function reclaimEther() external onlyOwner { function reclaimEther() external onlyOwner {
assert(owner.send(this.balance)); // solium-disable-next-line security/no-send
assert(owner.send(address(this).balance));
} }
} }
...@@ -81,6 +81,7 @@ contract Heritable is Ownable { ...@@ -81,6 +81,7 @@ contract Heritable is Ownable {
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
timeOfDeath_ = block.timestamp; timeOfDeath_ = block.timestamp;
} }
...@@ -97,6 +98,7 @@ contract Heritable is Ownable { ...@@ -97,6 +98,7 @@ contract Heritable is Ownable {
*/ */
function claimHeirOwnership() public onlyHeir { function claimHeirOwnership() public onlyHeir {
require(!ownerLives()); require(!ownerLives());
// 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_);
emit HeirOwnershipClaimed(owner, heir_); emit HeirOwnershipClaimed(owner, heir_);
......
...@@ -23,7 +23,7 @@ contract PullPayment { ...@@ -23,7 +23,7 @@ contract PullPayment {
uint256 payment = payments[payee]; uint256 payment = payments[payee];
require(payment != 0); require(payment != 0);
require(this.balance >= payment); require(address(this).balance >= payment);
totalPayments = totalPayments.sub(payment); totalPayments = totalPayments.sub(payment);
payments[payee] = 0; payments[payee] = 0;
......
...@@ -42,11 +42,11 @@ contract SplitPayment { ...@@ -42,11 +42,11 @@ contract SplitPayment {
require(shares[payee] > 0); require(shares[payee] > 0);
uint256 totalReceived = this.balance.add(totalReleased); uint256 totalReceived = address(this).balance.add(totalReleased);
uint256 payment = totalReceived.mul(shares[payee]).div(totalShares).sub(released[payee]); uint256 payment = totalReceived.mul(shares[payee]).div(totalShares).sub(released[payee]);
require(payment != 0); require(payment != 0);
require(this.balance >= payment); require(address(this).balance >= payment);
released[payee] = released[payee].add(payment); released[payee] = released[payee].add(payment);
totalReleased = totalReleased.add(payment); totalReleased = totalReleased.add(payment);
......
...@@ -21,6 +21,7 @@ contract TokenTimelock { ...@@ -21,6 +21,7 @@ contract TokenTimelock {
uint256 public releaseTime; uint256 public releaseTime;
function TokenTimelock(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public { function TokenTimelock(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public {
// solium-disable-next-line security/no-block-members
require(_releaseTime > block.timestamp); require(_releaseTime > block.timestamp);
token = _token; token = _token;
beneficiary = _beneficiary; beneficiary = _beneficiary;
...@@ -31,6 +32,7 @@ contract TokenTimelock { ...@@ -31,6 +32,7 @@ contract TokenTimelock {
* @notice Transfers tokens held by timelock to beneficiary. * @notice Transfers tokens held by timelock to beneficiary.
*/ */
function release() public { function release() public {
// solium-disable-next-line security/no-block-members
require(block.timestamp >= releaseTime); require(block.timestamp >= releaseTime);
uint256 amount = token.balanceOf(this); uint256 amount = token.balanceOf(this);
......
/* solium-disable security/no-block-members */
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import "./ERC20Basic.sol"; import "./ERC20Basic.sol";
......
...@@ -31,38 +31,38 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -31,38 +31,38 @@ contract ERC721BasicToken is ERC721Basic {
mapping (address => mapping (address => bool)) internal operatorApprovals; mapping (address => mapping (address => bool)) internal operatorApprovals;
/** /**
* @dev Guarantees msg.sender is owner of the given token * @dev Guarantees msg.sender is owner of the given token
* @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender * @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender
*/ */
modifier onlyOwnerOf(uint256 _tokenId) { modifier onlyOwnerOf(uint256 _tokenId) {
require(ownerOf(_tokenId) == msg.sender); require(ownerOf(_tokenId) == msg.sender);
_; _;
} }
/** /**
* @dev Checks msg.sender can transfer a token, by being owner, approved, or operator * @dev Checks msg.sender can transfer a token, by being owner, approved, or operator
* @param _tokenId uint256 ID of the token to validate * @param _tokenId uint256 ID of the token to validate
*/ */
modifier canTransfer(uint256 _tokenId) { modifier canTransfer(uint256 _tokenId) {
require(isApprovedOrOwner(msg.sender, _tokenId)); require(isApprovedOrOwner(msg.sender, _tokenId));
_; _;
} }
/** /**
* @dev Gets the balance of the specified address * @dev Gets the balance of the specified address
* @param _owner address to query the balance of * @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address * @return uint256 representing the amount owned by the passed address
*/ */
function balanceOf(address _owner) public view returns (uint256) { function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0)); require(_owner != address(0));
return ownedTokensCount[_owner]; return ownedTokensCount[_owner];
} }
/** /**
* @dev Gets the owner of the specified token ID * @dev Gets the owner of the specified token ID
* @param _tokenId uint256 ID of the token to query the owner of * @param _tokenId uint256 ID of the token to query the owner of
* @return owner address currently marked as the owner of the given token ID * @return owner address currently marked as the owner of the given token ID
*/ */
function ownerOf(uint256 _tokenId) public view returns (address) { function ownerOf(uint256 _tokenId) public view returns (address) {
address owner = tokenOwner[_tokenId]; address owner = tokenOwner[_tokenId];
require(owner != address(0)); require(owner != address(0));
...@@ -70,23 +70,23 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -70,23 +70,23 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Returns whether the specified token exists * @dev Returns whether the specified token exists
* @param _tokenId uint256 ID of the token to query the existance of * @param _tokenId uint256 ID of the token to query the existance of
* @return whether the token exists * @return whether the token exists
*/ */
function exists(uint256 _tokenId) public view returns (bool) { function exists(uint256 _tokenId) public view returns (bool) {
address owner = tokenOwner[_tokenId]; address owner = tokenOwner[_tokenId];
return owner != address(0); return owner != address(0);
} }
/** /**
* @dev Approves another address to transfer the given token ID * @dev Approves another address to transfer the given token ID
* @dev The zero address indicates there is no approved address. * @dev The zero address indicates there is no approved address.
* @dev There can only be one approved address per token at a given time. * @dev There can only be one approved address per token at a given time.
* @dev Can only be called by the token owner or an approved operator. * @dev Can only be called by the token owner or an approved operator.
* @param _to address to be approved for the given token ID * @param _to address to be approved for the given token ID
* @param _tokenId uint256 ID of the token to be approved * @param _tokenId uint256 ID of the token to be approved
*/ */
function approve(address _to, uint256 _tokenId) public { function approve(address _to, uint256 _tokenId) public {
address owner = ownerOf(_tokenId); address owner = ownerOf(_tokenId);
require(_to != owner); require(_to != owner);
...@@ -108,11 +108,11 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -108,11 +108,11 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Sets or unsets the approval of a given operator * @dev Sets or unsets the approval of a given operator
* @dev An operator is allowed to transfer all tokens of the sender on their behalf * @dev An operator is allowed to transfer all tokens of the sender on their behalf
* @param _to operator address to set the approval * @param _to operator address to set the approval
* @param _approved representing the status of the approval to be set * @param _approved representing the status of the approval to be set
*/ */
function setApprovalForAll(address _to, bool _approved) public { function setApprovalForAll(address _to, bool _approved) public {
require(_to != msg.sender); require(_to != msg.sender);
operatorApprovals[msg.sender][_to] = _approved; operatorApprovals[msg.sender][_to] = _approved;
...@@ -130,12 +130,12 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -130,12 +130,12 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Transfers the ownership of a given token ID to another address * @dev Transfers the ownership of a given token ID to another address
* @dev Usage of this method is discouraged, use `safeTransferFrom` whenever possible * @dev Usage of this method is discouraged, use `safeTransferFrom` whenever possible
* @dev Requires the msg sender to be the owner, approved, or operator * @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token * @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID * @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred * @param _tokenId uint256 ID of the token to be transferred
*/ */
function transferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) { function transferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) {
require(_from != address(0)); require(_from != address(0));
...@@ -149,15 +149,15 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -149,15 +149,15 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Safely transfers the ownership of a given token ID to another address * @dev Safely transfers the ownership of a given token ID to another address
* @dev If the target address is a contract, it must implement `onERC721Received`, * @dev If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value * which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise, * `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise,
* the transfer is reverted. * the transfer is reverted.
* @dev Requires the msg sender to be the owner, approved, or operator * @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token * @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID * @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred * @param _tokenId uint256 ID of the token to be transferred
*/ */
function safeTransferFrom( function safeTransferFrom(
address _from, address _from,
...@@ -167,21 +167,22 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -167,21 +167,22 @@ contract ERC721BasicToken is ERC721Basic {
public public
canTransfer(_tokenId) canTransfer(_tokenId)
{ {
// solium-disable-next-line arg-overflow
safeTransferFrom(_from, _to, _tokenId, ""); safeTransferFrom(_from, _to, _tokenId, "");
} }
/** /**
* @dev Safely transfers the ownership of a given token ID to another address * @dev Safely transfers the ownership of a given token ID to another address
* @dev If the target address is a contract, it must implement `onERC721Received`, * @dev If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value * which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise, * `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`; otherwise,
* the transfer is reverted. * the transfer is reverted.
* @dev Requires the msg sender to be the owner, approved, or operator * @dev Requires the msg sender to be the owner, approved, or operator
* @param _from current owner of the token * @param _from current owner of the token
* @param _to address to receive the ownership of the given token ID * @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred * @param _tokenId uint256 ID of the token to be transferred
* @param _data bytes data to send along with a safe transfer check * @param _data bytes data to send along with a safe transfer check
*/ */
function safeTransferFrom( function safeTransferFrom(
address _from, address _from,
address _to, address _to,
...@@ -192,6 +193,7 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -192,6 +193,7 @@ contract ERC721BasicToken is ERC721Basic {
canTransfer(_tokenId) canTransfer(_tokenId)
{ {
transferFrom(_from, _to, _tokenId); transferFrom(_from, _to, _tokenId);
// solium-disable-next-line arg-overflow
require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data)); require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data));
} }
...@@ -208,11 +210,11 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -208,11 +210,11 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to mint a new token * @dev Internal function to mint a new token
* @dev Reverts if the given token ID already exists * @dev Reverts if the given token ID already exists
* @param _to The address that will own the minted token * @param _to The address that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender * @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/ */
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);
...@@ -220,10 +222,10 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -220,10 +222,10 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to burn a specific token * @dev Internal function to burn a specific token
* @dev Reverts if the token does not exist * @dev Reverts if the token does not exist
* @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);
...@@ -231,11 +233,11 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -231,11 +233,11 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to clear current approval of a given token ID * @dev Internal function to clear current approval of a given token ID
* @dev Reverts if the given address is not indeed the owner of the token * @dev Reverts if the given address is not indeed the owner of the token
* @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)) {
...@@ -245,10 +247,10 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -245,10 +247,10 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to add a token ID to the list of a given address * @dev Internal function to add a token ID to the list of a given address
* @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;
...@@ -256,10 +258,10 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -256,10 +258,10 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to remove a token ID from the list of a given address * @dev Internal function to remove a token ID from the list of a given address
* @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);
...@@ -267,14 +269,14 @@ contract ERC721BasicToken is ERC721Basic { ...@@ -267,14 +269,14 @@ contract ERC721BasicToken is ERC721Basic {
} }
/** /**
* @dev Internal function to invoke `onERC721Received` on a target address * @dev Internal function to invoke `onERC721Received` on a target address
* @dev The call is not executed if the target address is not a contract * @dev The call is not executed if the target address is not a contract
* @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 _to target address that will receive the tokens * @param _to target address that will receive the tokens
* @param _tokenId uint256 ID of the token to be transferred * @param _tokenId uint256 ID of the token to be transferred
* @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,
......
...@@ -33,85 +33,85 @@ contract ERC721Token is ERC721, ERC721BasicToken { ...@@ -33,85 +33,85 @@ contract ERC721Token is ERC721, ERC721BasicToken {
mapping(uint256 => string) internal tokenURIs; mapping(uint256 => string) internal tokenURIs;
/** /**
* @dev Constructor function * @dev Constructor function
*/ */
function ERC721Token(string _name, string _symbol) public { function ERC721Token(string _name, string _symbol) public {
name_ = _name; name_ = _name;
symbol_ = _symbol; symbol_ = _symbol;
} }
/** /**
* @dev Gets the token name * @dev Gets the token name
* @return string representing the token name * @return string representing the token name
*/ */
function name() public view returns (string) { function name() public view returns (string) {
return name_; return name_;
} }
/** /**
* @dev Gets the token symbol * @dev Gets the token symbol
* @return string representing the token symbol * @return string representing the token symbol
*/ */
function symbol() public view returns (string) { function symbol() public view returns (string) {
return symbol_; return symbol_;
} }
/** /**
* @dev Returns an URI for a given token ID * @dev Returns an URI for a given token ID
* @dev Throws if the token ID does not exist. May return an empty string. * @dev Throws if the token ID does not exist. May return an empty string.
* @param _tokenId uint256 ID of the token to query * @param _tokenId uint256 ID of the token to query
*/ */
function tokenURI(uint256 _tokenId) public view returns (string) { function tokenURI(uint256 _tokenId) public view returns (string) {
require(exists(_tokenId)); require(exists(_tokenId));
return tokenURIs[_tokenId]; return tokenURIs[_tokenId];
} }
/** /**
* @dev Gets the token ID at a given index of the tokens list of the requested owner * @dev Gets the token ID at a given index of the tokens list of the requested owner
* @param _owner address owning the tokens list to be accessed * @param _owner address owning the tokens list to be accessed
* @param _index uint256 representing the index to be accessed of the requested tokens list * @param _index uint256 representing the index to be accessed of the requested tokens list
* @return uint256 token ID at the given index of the tokens list owned by the requested address * @return uint256 token ID at the given index of the tokens list owned by the requested address
*/ */
function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256) { function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256) {
require(_index < balanceOf(_owner)); require(_index < balanceOf(_owner));
return ownedTokens[_owner][_index]; return ownedTokens[_owner][_index];
} }
/** /**
* @dev Gets the total amount of tokens stored by the contract * @dev Gets the total amount of tokens stored by the contract
* @return uint256 representing the total amount of tokens * @return uint256 representing the total amount of tokens
*/ */
function totalSupply() public view returns (uint256) { function totalSupply() public view returns (uint256) {
return allTokens.length; return allTokens.length;
} }
/** /**
* @dev Gets the token ID at a given index of all the tokens in this contract * @dev Gets the token ID at a given index of all the tokens in this contract
* @dev Reverts if the index is greater or equal to the total number of tokens * @dev Reverts if the index is greater or equal to the total number of tokens
* @param _index uint256 representing the index to be accessed of the tokens list * @param _index uint256 representing the index to be accessed of the tokens list
* @return uint256 token ID at the given index of the tokens list * @return uint256 token ID at the given index of the tokens list
*/ */
function tokenByIndex(uint256 _index) public view returns (uint256) { function tokenByIndex(uint256 _index) public view returns (uint256) {
require(_index < totalSupply()); require(_index < totalSupply());
return allTokens[_index]; return allTokens[_index];
} }
/** /**
* @dev Internal function to set the token URI for a given token * @dev Internal function to set the token URI for a given token
* @dev Reverts if the token ID does not exist * @dev Reverts if the token ID does not exist
* @param _tokenId uint256 ID of the token to set its URI * @param _tokenId uint256 ID of the token to set its URI
* @param _uri string URI to assign * @param _uri string URI to assign
*/ */
function _setTokenURI(uint256 _tokenId, string _uri) internal { function _setTokenURI(uint256 _tokenId, string _uri) internal {
require(exists(_tokenId)); require(exists(_tokenId));
tokenURIs[_tokenId] = _uri; tokenURIs[_tokenId] = _uri;
} }
/** /**
* @dev Internal function to add a token ID to the list of a given address * @dev Internal function to add a token ID to the list of a given address
* @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;
...@@ -120,10 +120,10 @@ contract ERC721Token is ERC721, ERC721BasicToken { ...@@ -120,10 +120,10 @@ contract ERC721Token is ERC721, ERC721BasicToken {
} }
/** /**
* @dev Internal function to remove a token ID from the list of a given address * @dev Internal function to remove a token ID from the list of a given address
* @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);
...@@ -143,11 +143,11 @@ contract ERC721Token is ERC721, ERC721BasicToken { ...@@ -143,11 +143,11 @@ contract ERC721Token is ERC721, ERC721BasicToken {
} }
/** /**
* @dev Internal function to mint a new token * @dev Internal function to mint a new token
* @dev Reverts if the given token ID already exists * @dev Reverts if the given token ID already exists
* @param _to address the beneficiary that will own the minted token * @param _to address the beneficiary that will own the minted token
* @param _tokenId uint256 ID of the token to be minted by the msg.sender * @param _tokenId uint256 ID of the token to be minted by the msg.sender
*/ */
function _mint(address _to, uint256 _tokenId) internal { function _mint(address _to, uint256 _tokenId) internal {
super._mint(_to, _tokenId); super._mint(_to, _tokenId);
...@@ -156,11 +156,11 @@ contract ERC721Token is ERC721, ERC721BasicToken { ...@@ -156,11 +156,11 @@ contract ERC721Token is ERC721, ERC721BasicToken {
} }
/** /**
* @dev Internal function to burn a specific token * @dev Internal function to burn a specific token
* @dev Reverts if the token does not exist * @dev Reverts if the token does not exist
* @param _owner owner of the token to burn * @param _owner owner of the token to burn
* @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 {
super._burn(_owner, _tokenId); super._burn(_owner, _tokenId);
......
...@@ -5,16 +5,15 @@ import "../ERC20/ERC20.sol"; ...@@ -5,16 +5,15 @@ import "../ERC20/ERC20.sol";
/** /**
@title ERC827 interface, an extension of ERC20 token standard * @title ERC827 interface, an extension of ERC20 token standard
*
Interface of a ERC827 token, following the ERC20 standard with extra * @dev Interface of a ERC827 token, following the ERC20 standard with extra
methods to transfer value and data and execute calls in transfers and * @dev methods to transfer value and data and execute calls in transfers and
approvals. * @dev approvals.
*/ */
contract ERC827 is ERC20 { contract ERC827 is ERC20 {
function approve(address _spender, uint256 _value, bytes _data) public returns (bool);
function approve( address _spender, uint256 _value, bytes _data ) public returns (bool); function transfer(address _to, uint256 _value, bytes _data) public returns (bool);
function transfer( address _to, uint256 _value, bytes _data ) public returns (bool);
function transferFrom( function transferFrom(
address _from, address _from,
address _to, address _to,
...@@ -23,5 +22,4 @@ contract ERC827 is ERC20 { ...@@ -23,5 +22,4 @@ contract ERC827 is ERC20 {
) )
public public
returns (bool); returns (bool);
} }
/* solium-disable security/no-low-level-calls */
pragma solidity ^0.4.21; pragma solidity ^0.4.21;
import "./ERC827.sol"; import "./ERC827.sol";
...@@ -5,31 +7,32 @@ import "../ERC20/StandardToken.sol"; ...@@ -5,31 +7,32 @@ import "../ERC20/StandardToken.sol";
/** /**
@title ERC827, an extension of ERC20 token standard * @title ERC827, an extension of ERC20 token standard
*
Implementation the ERC827, following the ERC20 standard with extra * @dev Implementation the ERC827, following the ERC20 standard with extra
methods to transfer value and data and execute calls in transfers and * @dev methods to transfer value and data and execute calls in transfers and
approvals. * @dev approvals.
Uses OpenZeppelin StandardToken. *
* @dev Uses OpenZeppelin StandardToken.
*/ */
contract ERC827Token is ERC827, StandardToken { contract ERC827Token is ERC827, StandardToken {
/** /**
@dev Addition to ERC20 token methods. It allows to * @dev Addition to ERC20 token methods. It allows to
approve the transfer of value and execute a call with the sent data. * @dev approve the transfer of value and execute a call with the sent data.
*
Beware that changing an allowance with this method brings the risk that * @dev Beware that changing an allowance with this method brings the risk that
someone may use both the old and the new allowance by unfortunate * @dev someone may use both the old and the new allowance by unfortunate
transaction ordering. One possible solution to mitigate this race condition * @dev transaction ordering. One possible solution to mitigate this race condition
is to first reduce the spender's allowance to 0 and set the desired value * @dev is to first reduce the spender's allowance to 0 and set the desired value
afterwards: * @dev afterwards:
https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @dev https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
@param _spender The address that will spend the funds. * @param _spender The address that will spend the funds.
@param _value The amount of tokens to be spent. * @param _value The amount of tokens to be spent.
@param _data ABI-encoded contract call to call `_to` address. * @param _data ABI-encoded contract call to call `_to` address.
*
@return true if the call function was executed successfully * @return true if the call function was executed successfully
*/ */
function approve(address _spender, uint256 _value, bytes _data) public returns (bool) { function approve(address _spender, uint256 _value, bytes _data) public returns (bool) {
require(_spender != address(this)); require(_spender != address(this));
...@@ -42,14 +45,14 @@ contract ERC827Token is ERC827, StandardToken { ...@@ -42,14 +45,14 @@ contract ERC827Token is ERC827, StandardToken {
} }
/** /**
@dev Addition to ERC20 token methods. Transfer tokens to a specified * @dev Addition to ERC20 token methods. Transfer tokens to a specified
address and execute a call with the sent data on the same transaction * @dev address and execute a call with the sent data on the same transaction
*
@param _to address The address which you want to transfer to * @param _to address The address which you want to transfer to
@param _value uint256 the amout of tokens to be transfered * @param _value uint256 the amout of tokens to be transfered
@param _data ABI-encoded contract call to call `_to` address. * @param _data ABI-encoded contract call to call `_to` address.
*
@return true if the call function was executed successfully * @return true if the call function was executed successfully
*/ */
function transfer(address _to, uint256 _value, bytes _data) public returns (bool) { function transfer(address _to, uint256 _value, bytes _data) public returns (bool) {
require(_to != address(this)); require(_to != address(this));
...@@ -61,15 +64,15 @@ contract ERC827Token is ERC827, StandardToken { ...@@ -61,15 +64,15 @@ contract ERC827Token is ERC827, StandardToken {
} }
/** /**
@dev Addition to ERC20 token methods. Transfer tokens from one address to * @dev Addition to ERC20 token methods. Transfer tokens from one address to
another and make a contract call on the same transaction * @dev another and make a contract call on the same transaction
*
@param _from The address which you want to send tokens from * @param _from The address which you want to send tokens from
@param _to The address which you want to transfer to * @param _to The address which you want to transfer to
@param _value The amout of tokens to be transferred * @param _value The amout of tokens to be transferred
@param _data ABI-encoded contract call to call `_to` address. * @param _data ABI-encoded contract call to call `_to` address.
*
@return true if the call function was executed successfully * @return true if the call function was executed successfully
*/ */
function transferFrom( function transferFrom(
address _from, address _from,
...@@ -89,12 +92,13 @@ contract ERC827Token is ERC827, StandardToken { ...@@ -89,12 +92,13 @@ contract ERC827Token is ERC827, StandardToken {
/** /**
* @dev Addition to StandardToken methods. Increase the amount of tokens that * @dev Addition to StandardToken methods. Increase the amount of tokens that
* an owner allowed to a spender and execute a call with the sent data. * @dev an owner allowed to a spender and execute a call with the sent data.
*
* @dev approve should be called when allowed[_spender] == 0. To increment
* @dev allowed value is better to use this function to avoid 2 calls (and wait until
* @dev the first transaction is mined)
* @dev From MonolithDAO Token.sol
* *
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds. * @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by. * @param _addedValue The amount of tokens to increase the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address. * @param _data ABI-encoded contract call to call `_spender` address.
...@@ -111,12 +115,13 @@ contract ERC827Token is ERC827, StandardToken { ...@@ -111,12 +115,13 @@ contract ERC827Token is ERC827, StandardToken {
/** /**
* @dev Addition to StandardToken methods. Decrease the amount of tokens that * @dev Addition to StandardToken methods. Decrease the amount of tokens that
* an owner allowed to a spender and execute a call with the sent data. * @dev an owner allowed to a spender and execute a call with the sent data.
*
* @dev approve should be called when allowed[_spender] == 0. To decrement
* @dev allowed value is better to use this function to avoid 2 calls (and wait until
* @dev the first transaction is mined)
* @dev From MonolithDAO Token.sol
* *
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds. * @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by. * @param _subtractedValue The amount of tokens to decrease the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address. * @param _data ABI-encoded contract call to call `_spender` address.
......
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