Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Mar 7, 2018
1 parent 2e1a695 commit b81b4e1
Show file tree
Hide file tree
Showing 16 changed files with 518 additions and 161 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.

19 changes: 19 additions & 0 deletions contracts/mocks/ERC721BasicTokenMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 ERC721BasicTokenMock() ERC721BasicToken() public { }

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.

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];
}
}
23 changes: 11 additions & 12 deletions contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
pragma solidity ^0.4.18;

import "./BaseERC721.sol";
import "./ERC721Basic.sol";

contract ERC721Enumerable is ERC721Basic {
function totalSupply() public view returns (uint256);
function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256 _tokenId);
//function tokenByIndex(uint256 _index) public view returns (uint256);
}

/**
* @title Full ERC721 interface
* @dev see https://github.com/ethereum/eips/issues/721 and https://github.com/ethereum/EIPs/pull/841
*/
contract ERC721 is BaseERC721 {
event OperatorApproval(address indexed _owner, address indexed _operator, bool _approved);

contract ERC721Metadata is ERC721Basic {
function name() public view returns (string _name);
function symbol() public view returns (string _symbol);
function takeOwnershipFor(address _to, uint256 _tokenId) public;
function setOperatorApproval(address _to, bool _approved) public;
function isOperatorApprovedFor(address _owner, address _operator) public view returns (bool);
function tokenOfOwnerByIndex(address _owner, uint256 _index) public view returns (uint256 _tokenId);
function tokenURI(uint256 _tokenId) public view returns (string);
}

contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata {
}
25 changes: 25 additions & 0 deletions contracts/token/ERC721/ERC721Basic.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.4.18;

/**
* @title Base ERC721 interface
* @dev see https://github.com/ethereum/eips/issues/721 and https://github.com/ethereum/EIPs/pull/841
*/
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);

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;
}
Loading

0 comments on commit b81b4e1

Please sign in to comment.