diff --git a/contracts/AddressUtils.sol b/contracts/AddressUtils.sol index 7a2c08e90a8..931fc76d0bb 100644 --- a/contracts/AddressUtils.sol +++ b/contracts/AddressUtils.sol @@ -1,20 +1,27 @@ pragma solidity ^0.4.18; + /** * Utility library of inline functions on addresses */ library AddressUtils { /** - * Returns whether there is code in the target address + * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. - * @param addr address address to check - * @return whether there is code in the target address + * @param addr address to check + * @return whether the target address is a contract */ function isContract(address addr) internal view returns (bool) { uint256 size; - assembly { size := extcodesize(addr) } + // XXX Currently there is no better way to check if there is a contract in an address + // than to check the size of the code at that address. + // See https://ethereum.stackexchange.com/a/14016/36603 + // for more details about how this works. + // TODO Check this again before the Serenity release, because all addresses will be + // contracts then. + assembly { size := extcodesize(addr) } // solium-disable-line security/no-inline-assembly return size > 0; } diff --git a/contracts/DayLimit.sol b/contracts/DayLimit.sol index adacd7a62f5..ae7c25bbd24 100644 --- a/contracts/DayLimit.sol +++ b/contracts/DayLimit.sol @@ -61,7 +61,7 @@ contract DayLimit { * @return uint256 of today's index. */ function today() private view returns (uint256) { - return now / 1 days; + return block.timestamp / 1 days; } /** diff --git a/contracts/ECRecovery.sol b/contracts/ECRecovery.sol index e3a71688333..78d88579e3c 100644 --- a/contracts/ECRecovery.sol +++ b/contracts/ECRecovery.sol @@ -5,6 +5,10 @@ pragma solidity ^0.4.18; * @title Eliptic curve signature operations * * @dev Based on https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d + * + * TODO Remove this library once solidity supports passing a signature to ecrecover. + * See https://github.com/ethereum/solidity/issues/864 + * */ library ECRecovery { @@ -25,6 +29,9 @@ library ECRecovery { } // Divide the signature in r, s and v variables + // ecrecover takes the signature parameters, and the only way to get them + // currently is to use assembly. + // solium-disable-next-line security/no-inline-assembly assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) diff --git a/contracts/MerkleProof.sol b/contracts/MerkleProof.sol index e0e2ce88b7b..1c8e8a1c7ea 100644 --- a/contracts/MerkleProof.sol +++ b/contracts/MerkleProof.sol @@ -24,6 +24,7 @@ library MerkleProof { bytes32 computedHash = _leaf; for (uint256 i = 32; i <= _proof.length; i += 32) { + // solium-disable-next-line security/no-inline-assembly assembly { // Load the current element of the proof proofElement := mload(add(_proof, i)) diff --git a/contracts/crowdsale/Crowdsale.sol b/contracts/crowdsale/Crowdsale.sol index b1904865da3..7f2b89aa4c7 100644 --- a/contracts/crowdsale/Crowdsale.sol +++ b/contracts/crowdsale/Crowdsale.sol @@ -3,6 +3,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/ERC20.sol"; import "../math/SafeMath.sol"; + /** * @title Crowdsale * @dev Crowdsale is a base contract for managing a token crowdsale, @@ -11,11 +12,10 @@ import "../math/SafeMath.sol"; * functionality and/or custom behavior. * The external interface represents the basic interface for purchasing tokens, and conform * the base architecture for crowdsales. They are *not* intended to be modified / overriden. - * The internal interface conforms the extensible and modifiable surface of crowdsales. Override + * The internal interface conforms the extensible and modifiable surface of crowdsales. Override * the methods to add functionality. Consider using 'super' where appropiate to concatenate * behavior. */ - contract Crowdsale { using SafeMath for uint256; diff --git a/contracts/crowdsale/distribution/FinalizableCrowdsale.sol b/contracts/crowdsale/distribution/FinalizableCrowdsale.sol index 472e2796a0c..10d60aefae3 100644 --- a/contracts/crowdsale/distribution/FinalizableCrowdsale.sol +++ b/contracts/crowdsale/distribution/FinalizableCrowdsale.sol @@ -4,6 +4,7 @@ import "../../math/SafeMath.sol"; import "../../ownership/Ownable.sol"; import "../validation/TimedCrowdsale.sol"; + /** * @title FinalizableCrowdsale * @dev Extension of Crowdsale where an owner can do extra work @@ -37,4 +38,5 @@ contract FinalizableCrowdsale is TimedCrowdsale, Ownable { */ function finalization() internal { } + } diff --git a/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol b/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol index 3f45ad06346..f4f4c2dd4c8 100644 --- a/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol +++ b/contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol @@ -4,6 +4,7 @@ import "../validation/TimedCrowdsale.sol"; import "../../token/ERC20/ERC20.sol"; import "../../math/SafeMath.sol"; + /** * @title PostDeliveryCrowdsale * @dev Crowdsale that locks tokens from withdrawal until it ends. @@ -13,15 +14,6 @@ contract PostDeliveryCrowdsale is TimedCrowdsale { mapping(address => uint256) public balances; - /** - * @dev Overrides parent by storing balances instead of issuing tokens right away. - * @param _beneficiary Token purchaser - * @param _tokenAmount Amount of tokens purchased - */ - function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal { - balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount); - } - /** * @dev Withdraw tokens only after crowdsale ends. */ @@ -32,4 +24,14 @@ contract PostDeliveryCrowdsale is TimedCrowdsale { balances[msg.sender] = 0; _deliverTokens(msg.sender, amount); } + + /** + * @dev Overrides parent by storing balances instead of issuing tokens right away. + * @param _beneficiary Token purchaser + * @param _tokenAmount Amount of tokens purchased + */ + function _processPurchase(address _beneficiary, uint256 _tokenAmount) internal { + balances[_beneficiary] = balances[_beneficiary].add(_tokenAmount); + } + } diff --git a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol index ae4ca416939..bdccaeb03e6 100644 --- a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol +++ b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol @@ -3,9 +3,10 @@ pragma solidity ^0.4.18; import "../validation/TimedCrowdsale.sol"; import "../../math/SafeMath.sol"; + /** * @title IncreasingPriceCrowdsale - * @dev Extension of Crowdsale contract that increases the price of tokens linearly in time. + * @dev Extension of Crowdsale contract that increases the price of tokens linearly in time. * Note that what should be provided to the constructor is the initial and final _rates_, that is, * the amount of tokens per wei contributed. Thus, the initial rate must be greater than the final rate. */ @@ -28,12 +29,12 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale { } /** - * @dev Returns the rate of tokens per wei at the present time. - * Note that, as price _increases_ with time, the rate _decreases_. + * @dev Returns the rate of tokens per wei at the present time. + * Note that, as price _increases_ with time, the rate _decreases_. * @return The number of tokens a buyer gets per wei at a given time */ function getCurrentRate() public view returns (uint256) { - uint256 elapsedTime = now.sub(openingTime); + uint256 elapsedTime = block.timestamp.sub(openingTime); uint256 timeRange = closingTime.sub(openingTime); uint256 rateRange = initialRate.sub(finalRate); return initialRate.sub(elapsedTime.mul(rateRange).div(timeRange)); diff --git a/contracts/crowdsale/validation/TimedCrowdsale.sol b/contracts/crowdsale/validation/TimedCrowdsale.sol index b015a1c74d1..e7b311a51e5 100644 --- a/contracts/crowdsale/validation/TimedCrowdsale.sol +++ b/contracts/crowdsale/validation/TimedCrowdsale.sol @@ -15,10 +15,10 @@ contract TimedCrowdsale is Crowdsale { uint256 public closingTime; /** - * @dev Reverts if not in crowdsale time range. + * @dev Reverts if not in crowdsale time range. */ modifier onlyWhileOpen { - require(now >= openingTime && now <= closingTime); + require(block.timestamp >= openingTime && block.timestamp <= closingTime); _; } @@ -28,7 +28,7 @@ contract TimedCrowdsale is Crowdsale { * @param _closingTime Crowdsale closing time */ function TimedCrowdsale(uint256 _openingTime, uint256 _closingTime) public { - require(_openingTime >= now); + require(_openingTime >= block.timestamp); require(_closingTime >= _openingTime); openingTime = _openingTime; @@ -40,9 +40,9 @@ contract TimedCrowdsale is Crowdsale { * @return Whether crowdsale period has elapsed */ function hasClosed() public view returns (bool) { - return now > closingTime; + return block.timestamp > closingTime; } - + /** * @dev Extend parent behavior requiring to be within contributing period * @param _beneficiary Token purchaser diff --git a/contracts/examples/SampleCrowdsale.sol b/contracts/examples/SampleCrowdsale.sol index 969ed460bb7..f386d5d15d3 100644 --- a/contracts/examples/SampleCrowdsale.sol +++ b/contracts/examples/SampleCrowdsale.sol @@ -33,7 +33,16 @@ contract SampleCrowdsaleToken is MintableToken { */ contract SampleCrowdsale is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale { - function SampleCrowdsale(uint256 _openingTime, uint256 _closingTime, uint256 _rate, address _wallet, uint256 _cap, MintableToken _token, uint256 _goal) public + function SampleCrowdsale( + uint256 _openingTime, + uint256 _closingTime, + uint256 _rate, + address _wallet, + uint256 _cap, + MintableToken _token, + uint256 _goal + ) + public Crowdsale(_rate, _wallet, _token) CappedCrowdsale(_cap) TimedCrowdsale(_openingTime, _closingTime) diff --git a/contracts/mocks/ERC223TokenMock.sol b/contracts/mocks/ERC223TokenMock.sol index 80952071660..46cd66fbb62 100644 --- a/contracts/mocks/ERC223TokenMock.sol +++ b/contracts/mocks/ERC223TokenMock.sol @@ -2,10 +2,12 @@ pragma solidity ^0.4.18; import "../token/ERC20/BasicToken.sol"; + contract ERC223ContractInterface { function tokenFallback(address _from, uint256 _value, bytes _data) external; } + contract ERC223TokenMock is BasicToken { function ERC223TokenMock(address initialAccount, uint256 initialBalance) public { @@ -18,11 +20,11 @@ contract ERC223TokenMock is BasicToken { returns (bool success) { transfer(_to, _value); - bool is_contract = false; + bool isContract = false; assembly { - is_contract := not(iszero(extcodesize(_to))) + isContract := not(iszero(extcodesize(_to))) } - if (is_contract) { + if (isContract) { ERC223ContractInterface receiver = ERC223ContractInterface(_to); receiver.tokenFallback(msg.sender, _value, _data); } diff --git a/contracts/mocks/ERC721BasicTokenMock.sol b/contracts/mocks/ERC721BasicTokenMock.sol index e4064a4d13b..d960b80d60d 100644 --- a/contracts/mocks/ERC721BasicTokenMock.sol +++ b/contracts/mocks/ERC721BasicTokenMock.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "../token/ERC721/ERC721BasicToken.sol"; + /** * @title ERC721BasicTokenMock * This mock just provides a public mint and burn functions for testing purposes diff --git a/contracts/mocks/ERC721ReceiverMock.sol b/contracts/mocks/ERC721ReceiverMock.sol index 3d7439578ff..e132475d6c1 100644 --- a/contracts/mocks/ERC721ReceiverMock.sol +++ b/contracts/mocks/ERC721ReceiverMock.sol @@ -2,10 +2,11 @@ pragma solidity ^0.4.18; import "../token/ERC721/ERC721Receiver.sol"; + contract ERC721ReceiverMock is ERC721Receiver { bytes4 retval; bool reverts; - + event Received(address _address, uint256 _tokenId, bytes _data, uint256 _gas); function ERC721ReceiverMock(bytes4 _retval, bool _reverts) public { diff --git a/contracts/mocks/ERC721TokenMock.sol b/contracts/mocks/ERC721TokenMock.sol index 008a9335c1a..f3ade6f10dd 100644 --- a/contracts/mocks/ERC721TokenMock.sol +++ b/contracts/mocks/ERC721TokenMock.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "../token/ERC721/ERC721Token.sol"; + /** * @title ERC721TokenMock * This mock just provides a public mint and burn functions for testing purposes, @@ -23,4 +24,4 @@ contract ERC721TokenMock is ERC721Token { function setTokenURI(uint256 _tokenId, string _uri) public { super._setTokenURI(_tokenId, _uri); } -} \ No newline at end of file +} diff --git a/contracts/mocks/MessageHelper.sol b/contracts/mocks/MessageHelper.sol index f990241dab0..8ce37cfbc23 100644 --- a/contracts/mocks/MessageHelper.sol +++ b/contracts/mocks/MessageHelper.sol @@ -1,5 +1,6 @@ pragma solidity ^0.4.11; + contract MessageHelper { event Show(bytes32 b32, uint256 number, string text); diff --git a/contracts/mocks/RefundableCrowdsaleImpl.sol b/contracts/mocks/RefundableCrowdsaleImpl.sol index 96ec7a72f40..471bc0a8882 100644 --- a/contracts/mocks/RefundableCrowdsaleImpl.sol +++ b/contracts/mocks/RefundableCrowdsaleImpl.sol @@ -3,6 +3,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/MintableToken.sol"; import "../crowdsale/distribution/RefundableCrowdsale.sol"; + contract RefundableCrowdsaleImpl is RefundableCrowdsale { function RefundableCrowdsaleImpl ( @@ -12,7 +13,7 @@ contract RefundableCrowdsaleImpl is RefundableCrowdsale { address _wallet, MintableToken _token, uint256 _goal - ) + ) public Crowdsale(_rate, _wallet, _token) TimedCrowdsale(_openingTime, _closingTime) diff --git a/contracts/mocks/StandardTokenMock.sol b/contracts/mocks/StandardTokenMock.sol index 778b78bd925..2fd572283df 100644 --- a/contracts/mocks/StandardTokenMock.sol +++ b/contracts/mocks/StandardTokenMock.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/StandardToken.sol"; + // mock class using StandardToken contract StandardTokenMock is StandardToken { diff --git a/contracts/mocks/TimedCrowdsaleImpl.sol b/contracts/mocks/TimedCrowdsaleImpl.sol index ad2b3f3249e..f2c3793e105 100644 --- a/contracts/mocks/TimedCrowdsaleImpl.sol +++ b/contracts/mocks/TimedCrowdsaleImpl.sol @@ -3,6 +3,7 @@ pragma solidity ^0.4.18; import "../token/ERC20/ERC20.sol"; import "../crowdsale/validation/TimedCrowdsale.sol"; + contract TimedCrowdsaleImpl is TimedCrowdsale { function TimedCrowdsaleImpl ( @@ -11,7 +12,7 @@ contract TimedCrowdsaleImpl is TimedCrowdsale { uint256 _rate, address _wallet, ERC20 _token - ) + ) public Crowdsale(_rate, _wallet, _token) TimedCrowdsale(_openingTime, _closingTime) diff --git a/contracts/token/ERC20/SafeERC20.sol b/contracts/token/ERC20/SafeERC20.sol index 1cf3adfab0c..42f7e8d4ece 100644 --- a/contracts/token/ERC20/SafeERC20.sol +++ b/contracts/token/ERC20/SafeERC20.sol @@ -15,7 +15,14 @@ library SafeERC20 { assert(token.transfer(to, value)); } - function safeTransferFrom(ERC20 token, address from, address to, uint256 value) internal { + function safeTransferFrom( + ERC20 token, + address from, + address to, + uint256 value + ) + internal + { assert(token.transferFrom(from, to, value)); } diff --git a/contracts/token/ERC20/TokenTimelock.sol b/contracts/token/ERC20/TokenTimelock.sol index 5e00973d627..a59fce18d11 100644 --- a/contracts/token/ERC20/TokenTimelock.sol +++ b/contracts/token/ERC20/TokenTimelock.sol @@ -21,7 +21,7 @@ contract TokenTimelock { uint256 public releaseTime; function TokenTimelock(ERC20Basic _token, address _beneficiary, uint256 _releaseTime) public { - require(_releaseTime > now); + require(_releaseTime > block.timestamp); token = _token; beneficiary = _beneficiary; releaseTime = _releaseTime; @@ -31,7 +31,7 @@ contract TokenTimelock { * @notice Transfers tokens held by timelock to beneficiary. */ function release() public { - require(now >= releaseTime); + require(block.timestamp >= releaseTime); uint256 amount = token.balanceOf(this); require(amount > 0); diff --git a/contracts/token/ERC20/TokenVesting.sol b/contracts/token/ERC20/TokenVesting.sol index f22e42e8ff3..14bca117782 100644 --- a/contracts/token/ERC20/TokenVesting.sol +++ b/contracts/token/ERC20/TokenVesting.sol @@ -40,7 +40,15 @@ contract TokenVesting is Ownable { * @param _duration duration in seconds of the period in which the tokens will vest * @param _revocable whether the vesting is revocable or not */ - function TokenVesting(address _beneficiary, uint256 _start, uint256 _cliff, uint256 _duration, bool _revocable) public { + function TokenVesting( + address _beneficiary, + uint256 _start, + uint256 _cliff, + uint256 _duration, + bool _revocable + ) + public + { require(_beneficiary != address(0)); require(_cliff <= _duration); @@ -104,12 +112,12 @@ contract TokenVesting is Ownable { uint256 currentBalance = token.balanceOf(this); uint256 totalBalance = currentBalance.add(released[token]); - if (now < cliff) { + if (block.timestamp < cliff) { return 0; - } else if (now >= start.add(duration) || revoked[token]) { + } else if (block.timestamp >= start.add(duration) || revoked[token]) { return totalBalance; } else { - return totalBalance.mul(now.sub(start)).div(duration); + return totalBalance.mul(block.timestamp.sub(start)).div(duration); } } } diff --git a/contracts/token/ERC721/DeprecatedERC721.sol b/contracts/token/ERC721/DeprecatedERC721.sol index 01b6c234a8d..3d5972d3ede 100644 --- a/contracts/token/ERC721/DeprecatedERC721.sol +++ b/contracts/token/ERC721/DeprecatedERC721.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "./ERC721.sol"; + /** * @title ERC-721 methods shipped in OpenZeppelin v1.7.0, removed in the latest version of the standard * @dev Only use this interface for compatibility with previously deployed contracts @@ -12,4 +13,3 @@ contract DeprecatedERC721 is ERC721 { function transfer(address _to, uint256 _tokenId) public; function tokensOf(address _owner) public view returns (uint256[]); } - diff --git a/contracts/token/ERC721/ERC721.sol b/contracts/token/ERC721/ERC721.sol index a2fc4e324aa..4ddbbfd537b 100644 --- a/contracts/token/ERC721/ERC721.sol +++ b/contracts/token/ERC721/ERC721.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "./ERC721Basic.sol"; + /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md @@ -12,6 +13,7 @@ contract ERC721Enumerable is ERC721Basic { function tokenByIndex(uint256 _index) public view returns (uint256); } + /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md @@ -22,6 +24,7 @@ contract ERC721Metadata is ERC721Basic { function tokenURI(uint256 _tokenId) public view returns (string); } + /** * @title ERC-721 Non-Fungible Token Standard, full implementation interface * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md diff --git a/contracts/token/ERC721/ERC721Basic.sol b/contracts/token/ERC721/ERC721Basic.sol index 5ebbfc3cb41..4006b71dfd4 100644 --- a/contracts/token/ERC721/ERC721Basic.sol +++ b/contracts/token/ERC721/ERC721Basic.sol @@ -1,5 +1,6 @@ pragma solidity ^0.4.18; + /** * @title ERC721 Non-Fungible Token Standard basic interface * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md @@ -7,19 +8,25 @@ pragma solidity ^0.4.18; contract ERC721Basic { event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); - event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); + event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); function balanceOf(address _owner) public view returns (uint256 _balance); function ownerOf(uint256 _tokenId) public view returns (address _owner); function exists(uint256 _tokenId) public view returns (bool _exists); - + function approve(address _to, uint256 _tokenId) public; function getApproved(uint256 _tokenId) public view returns (address _operator); - + function setApprovalForAll(address _operator, bool _approved) public; function isApprovedForAll(address _owner, address _operator) public view returns (bool); function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes _data) public; + function safeTransferFrom(address _from, address _to, uint256 _tokenId) public; + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId, + bytes _data + ) + public; } diff --git a/contracts/token/ERC721/ERC721BasicToken.sol b/contracts/token/ERC721/ERC721BasicToken.sol index f6826a4650d..f83dc04e1e6 100644 --- a/contracts/token/ERC721/ERC721BasicToken.sol +++ b/contracts/token/ERC721/ERC721BasicToken.sol @@ -5,6 +5,7 @@ import "./ERC721Receiver.sol"; import "../../math/SafeMath.sol"; import "../../AddressUtils.sol"; + /** * @title ERC721 Non-Fungible Token Standard basic implementation * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md @@ -12,10 +13,10 @@ import "../../AddressUtils.sol"; contract ERC721BasicToken is ERC721Basic { using SafeMath for uint256; using AddressUtils for address; - + // Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` // which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` - bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; + bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; // Mapping from token ID to owner mapping (uint256 => address) internal tokenOwner; @@ -106,7 +107,6 @@ contract ERC721BasicToken is ERC721Basic { return tokenApprovals[_tokenId]; } - /** * @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 @@ -144,7 +144,7 @@ contract ERC721BasicToken is ERC721Basic { clearApproval(_from, _tokenId); removeTokenFrom(_from, _tokenId); addTokenTo(_to, _tokenId); - + Transfer(_from, _to, _tokenId); } @@ -159,7 +159,14 @@ contract ERC721BasicToken is ERC721Basic { * @param _to address to receive the ownership of the given token ID * @param _tokenId uint256 ID of the token to be transferred */ - function safeTransferFrom(address _from, address _to, uint256 _tokenId) public canTransfer(_tokenId) { + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId + ) + public + canTransfer(_tokenId) + { safeTransferFrom(_from, _to, _tokenId, ""); } @@ -175,7 +182,15 @@ contract ERC721BasicToken is ERC721Basic { * @param _tokenId uint256 ID of the token to be transferred * @param _data bytes data to send along with a safe transfer check */ - function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes _data) public canTransfer(_tokenId) { + function safeTransferFrom( + address _from, + address _to, + uint256 _tokenId, + bytes _data + ) + public + canTransfer(_tokenId) + { transferFrom(_from, _to, _tokenId); require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data)); } @@ -260,7 +275,15 @@ contract ERC721BasicToken is ERC721Basic { * @param _data bytes optional data to send along with the call * @return whether the call correctly returned the expected magic value */ - function checkAndCallSafeTransfer(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) { + function checkAndCallSafeTransfer( + address _from, + address _to, + uint256 _tokenId, + bytes _data + ) + internal + returns (bool) + { if (!_to.isContract()) { return true; } diff --git a/contracts/token/ERC721/ERC721Holder.sol b/contracts/token/ERC721/ERC721Holder.sol index 4bd4b0c7c0e..67bcc0670d3 100644 --- a/contracts/token/ERC721/ERC721Holder.sol +++ b/contracts/token/ERC721/ERC721Holder.sol @@ -2,6 +2,7 @@ pragma solidity ^0.4.18; import "./ERC721Receiver.sol"; + contract ERC721Holder is ERC721Receiver { function onERC721Received(address, uint256, bytes) public returns(bytes4) { return ERC721_RECEIVED; diff --git a/contracts/token/ERC721/ERC721Receiver.sol b/contracts/token/ERC721/ERC721Receiver.sol index 81154d379e9..f34e1304fd4 100644 --- a/contracts/token/ERC721/ERC721Receiver.sol +++ b/contracts/token/ERC721/ERC721Receiver.sol @@ -1,5 +1,6 @@ pragma solidity ^0.4.18; + /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers @@ -11,7 +12,7 @@ contract ERC721Receiver { * Equals to `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`, * which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` */ - bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; + bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba; /** * @notice Handle the receipt of an NFT @@ -20,7 +21,7 @@ contract ERC721Receiver { * transfer. This function MUST use 50,000 gas or less. Return of other * than the magic value MUST result in the transaction being reverted. * Note: the contract address is always the message sender. - * @param _from The sending address + * @param _from The sending address * @param _tokenId The NFT identifier which is being transfered * @param _data Additional data with no specified format * @return `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))` diff --git a/contracts/token/ERC721/ERC721Token.sol b/contracts/token/ERC721/ERC721Token.sol index 495a071014f..647953b2522 100644 --- a/contracts/token/ERC721/ERC721Token.sol +++ b/contracts/token/ERC721/ERC721Token.sol @@ -30,7 +30,7 @@ contract ERC721Token is ERC721, ERC721BasicToken { // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) internal allTokensIndex; - // Optional mapping for token URIs + // Optional mapping for token URIs mapping(uint256 => string) internal tokenURIs; /** @@ -67,17 +67,6 @@ contract ERC721Token is ERC721, ERC721BasicToken { return tokenURIs[_tokenId]; } - /** - * @dev Internal function to set the token URI for a given token - * @dev Reverts if the token ID does not exist - * @param _tokenId uint256 ID of the token to set its URI - * @param _uri string URI to assign - */ - function _setTokenURI(uint256 _tokenId, string _uri) internal { - require(exists(_tokenId)); - tokenURIs[_tokenId] = _uri; - } - /** * @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 @@ -108,6 +97,17 @@ contract ERC721Token is ERC721, ERC721BasicToken { return allTokens[_index]; } + /** + * @dev Internal function to set the token URI for a given token + * @dev Reverts if the token ID does not exist + * @param _tokenId uint256 ID of the token to set its URI + * @param _uri string URI to assign + */ + function _setTokenURI(uint256 _tokenId, string _uri) internal { + require(exists(_tokenId)); + tokenURIs[_tokenId] = _uri; + } + /** * @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 @@ -151,7 +151,7 @@ contract ERC721Token is ERC721, ERC721BasicToken { */ function _mint(address _to, uint256 _tokenId) internal { super._mint(_to, _tokenId); - + allTokensIndex[_tokenId] = allTokens.length; allTokens.push(_tokenId); } diff --git a/contracts/token/ERC827/ERC827.sol b/contracts/token/ERC827/ERC827.sol index 31a17cd809f..67cd9e11c7c 100644 --- a/contracts/token/ERC827/ERC827.sol +++ b/contracts/token/ERC827/ERC827.sol @@ -15,6 +15,13 @@ contract ERC827 is ERC20 { function approve( address _spender, uint256 _value, bytes _data ) public returns (bool); function transfer( address _to, uint256 _value, bytes _data ) public returns (bool); - function transferFrom( address _from, address _to, uint256 _value, bytes _data ) public returns (bool); + function transferFrom( + address _from, + address _to, + uint256 _value, + bytes _data + ) + public + returns (bool); } diff --git a/contracts/token/ERC827/ERC827Token.sol b/contracts/token/ERC827/ERC827Token.sol index bed4968ea34..98f068575ba 100644 --- a/contracts/token/ERC827/ERC827Token.sol +++ b/contracts/token/ERC827/ERC827Token.sol @@ -3,6 +3,7 @@ pragma solidity ^0.4.13; import "./ERC827.sol"; import "../ERC20/StandardToken.sol"; + /** @title ERC827, an extension of ERC20 token standard @@ -70,7 +71,14 @@ contract ERC827Token is ERC827, StandardToken { @return true if the call function was executed successfully */ - function transferFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) { + function transferFrom( + address _from, + address _to, + uint256 _value, + bytes _data + ) + public returns (bool) + { require(_to != address(this)); super.transferFrom(_from, _to, _value);