Skip to content

Commit

Permalink
Support for new ERC721 interface
Browse files Browse the repository at this point in the history
- Tests for new features are pending
- ERC721 is abstract, since it requires metadata implementation
- Move some methods into DeprecatedERC721 contract
- Reorganise base vs full implementation
- Pending tokenByIndex
  • Loading branch information
spalladino committed Mar 7, 2018
1 parent 2e1a695 commit c03b84a
Show file tree
Hide file tree
Showing 17 changed files with 964 additions and 1,215 deletions.
11 changes: 11 additions & 0 deletions contracts/AddressUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.18;

library AddressUtils {

function isContract(address addr) internal view returns (bool) {
uint size;
assembly { size := extcodesize(addr) }
return size > 0;
}

}
19 changes: 0 additions & 19 deletions contracts/mocks/BaseERC721TokenMock.sol

This file was deleted.

17 changes: 17 additions & 0 deletions contracts/mocks/ERC721BasicTokenMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
*/
contract ERC721BasicTokenMock is ERC721BasicToken {
function mint(address _to, uint256 _tokenId) public {
super.doMint(_to, _tokenId);
}

function burn(uint256 _tokenId) public {
super.doBurn(_tokenId);
}
}
27 changes: 23 additions & 4 deletions contracts/mocks/ERC721TokenMock.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
pragma solidity ^0.4.18;

import "./BaseERC721TokenMock.sol";
import "./ERC721BasicTokenMock.sol";
import "../token/ERC721/ERC721Token.sol";

/**
* @title ERC721TokenMock
* This mock just provides a public mint and burn functions for testing purposes.
* This mock just provides a public mint and burn functions for testing purposes,
* and a mock metadata URI implementation
*/
contract ERC721TokenMock is ERC721Token, BaseERC721TokenMock {
contract ERC721TokenMock is ERC721Token, ERC721BasicTokenMock {
function ERC721TokenMock(string name, string symbol)
BaseERC721TokenMock()
ERC721BasicTokenMock()
ERC721Token(name, symbol)
public
{ }

// Mock implementation for testing.
// Do not use this code in production!
function tokenURI(uint256 _tokenId) public view returns (string) {
require(exists(_tokenId));

bytes memory uri = new bytes(78);

uint256 i;
uint256 value = _tokenId;

for (i = 0; i < 78; i++) {
uri[7 + 78 - i] = byte(value % 10 + 48);
value = value / 10;
}

return string(uri);
}
}
16 changes: 0 additions & 16 deletions contracts/token/ERC721/BaseERC721.sol

This file was deleted.

214 changes: 0 additions & 214 deletions contracts/token/ERC721/BaseERC721Token.sol

This file was deleted.

10 changes: 10 additions & 0 deletions contracts/token/ERC721/DeprecatedERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.18;

import "./ERC721.sol";

contract DeprecatedERC721 is ERC721 {
function takeOwnership(uint256 _tokenId) public;
function transfer(address _to, uint256 _tokenId) public;
function tokensOf(address _owner) public view returns (uint256[]);
}

35 changes: 35 additions & 0 deletions contracts/token/ERC721/DeprecatedERC721Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.4.18;

import "./DeprecatedERC721.sol";
import "./ERC721Token.sol";

contract DeprecatedERC721Token is DeprecatedERC721, ERC721Token {
/**
* @dev Claims the ownership of a given token ID
* @param _tokenId uint256 ID of the token being claimed by the msg.sender
*/
function takeOwnership(uint256 _tokenId) canTransfer(_tokenId) public {
require(msg.sender != ownerOf(_tokenId));
clearApprovalAndTransfer(ownerOf(_tokenId), msg.sender, _tokenId, "", false);
}

/**
* @dev Transfers the ownership of a given token ID to another address
* @param _to address to receive the ownership of the given token ID
* @param _tokenId uint256 ID of the token to be transferred
*/
function transfer(address _to, uint256 _tokenId) public {
address owner = ownerOf(_tokenId);
require(owner == msg.sender);
clearApprovalAndTransfer(owner, _to, _tokenId, "", false);
}

/**
* @dev Gets the list of tokens owned by a given address
* @param _owner address to query the tokens of
* @return uint256[] representing the list of tokens owned by the passed address
*/
function tokensOf(address _owner) public view returns (uint256[]) {
return ownedTokens[_owner];
}
}
Loading

0 comments on commit c03b84a

Please sign in to comment.