Skip to content

Commit

Permalink
Removed the _tokenId argument from transferChild functions, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
mudgen committed Jun 4, 2018
1 parent 06d8638 commit b354e5c
Show file tree
Hide file tree
Showing 13 changed files with 713 additions and 218 deletions.
9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

446 changes: 446 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions composables-998.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
31 changes: 2 additions & 29 deletions contracts/Composable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

pragma solidity ^0.4.21;

import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
import "./ERC998PossessERC721.sol";
import "./ERC998PossessERC20.sol";
import "./ERC998PossessERC721.sol";

contract Composable is ERC721Token, ERC998PossessERC721, ERC998PossessERC20 {
contract Composable is ERC998PossessERC721, ERC998PossessERC20 {

/**************************************
* ERC-721 Setup Methods for Testing
Expand All @@ -23,30 +22,4 @@ contract Composable is ERC721Token, ERC998PossessERC721, ERC998PossessERC20 {
return allTokens.length;
}

/**************************************
* TODO Where should this go? We shouldn't include this in every contract...
**************************************/
// implementation of the owns method from cryptokitties
function _owns(address _claimant, uint256 _tokenId) internal view returns(bool) {
return (tokenOwner[_tokenId] == _claimant);
}

/**************************************
* We MUST override transferChild from this contract
*
* TODO is there a better way to handle the check of _owns for tokenID?
**************************************/
function transferChild(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId) public {
//how can we push down to extension?
require(_owns(msg.sender, _tokenId));
super.transferChild(_to, _tokenId, _childContract, _childTokenId);
}

function transferChildToComposable(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId, bytes _data) public {
//how can we push down to extension?
require(_owns(msg.sender, _tokenId));
super.transferChildToComposable(_to, _tokenId, _childContract, _childTokenId, _data);
}


}
2 changes: 1 addition & 1 deletion contracts/ERC20Receiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//jshint ignore: start

pragma solidity ^0.4.18;
pragma solidity ^0.4.21;

/**
* @title ERC721 token receiver interface
Expand Down
34 changes: 19 additions & 15 deletions contracts/ERC998PossessERC721.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";

//jshint ignore: start

pragma solidity ^0.4.24;

interface ERC998NFT {
event ReceivedChild(uint256 indexed _tokenId, address indexed _childContract, uint256 _childTokenId, address indexed _from);
event TransferChild(address indexed _to, bytes _data, uint256 indexed _childTokenId);
event TransferChild(address indexed _to, bytes _data, address indexed _childContract, uint256 indexed _childTokenId);

function childOwnerOf(address _childContract, uint256 _childTokenId) external view returns (uint256 tokenId);
function ownerOfChild(address _childContract, uint256 _childTokenId) external view returns (uint256 tokenId);
function onERC721Received(address _from, uint256 _childTokenId, bytes _data) external returns(bytes4);
function transferChild(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId) public;
function transferChildToComposable(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId, bytes data) public;
function transferChild(address _to, address _childContract, uint256 _childTokenId) public;
function transferChildToComposable(address _to, address _childContract, uint256 _childTokenId, bytes data) public;
}

interface ERC998NFTEnumerable {
Expand All @@ -26,8 +27,8 @@ interface ERC721SafeSender {
}


contract ERC998PossessERC721 is ERC998NFT, ERC998NFTEnumerable {
contract ERC998PossessERC721 is ERC721Token, ERC998NFT, ERC998NFTEnumerable {

//from zepellin ERC721Receiver.sol
bytes4 constant ERC721_RECEIVED = 0xf0b9e5ba;

Expand All @@ -44,9 +45,9 @@ contract ERC998PossessERC721 is ERC998NFT, ERC998NFTEnumerable {
mapping(uint256 => mapping(address => mapping(uint256 => uint256))) private childTokenIndex;

// child address => childId => tokenId
mapping(address => mapping(uint256 => uint256)) private childTokenOwner;
mapping(address => mapping(uint256 => uint256)) internal childTokenOwner;

function removeChild(uint256 _tokenId, address _childContract, uint256 _childTokenId) internal {
function removeChild(uint256 _tokenId, address _childContract, uint256 _childTokenId) private {
uint256 tokenIndex = childTokenIndex[_tokenId][_childContract][_childTokenId];
require(tokenIndex != 0, "Child token not owned by token.");

Expand Down Expand Up @@ -101,23 +102,25 @@ contract ERC998PossessERC721 is ERC998NFT, ERC998NFTEnumerable {
return ERC721_RECEIVED;
}

function transferChild(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId) public {
removeChild(_tokenId, _childContract, _childTokenId);
function transferChild(address _to, address _childContract, uint256 _childTokenId) public {
uint256 tokenId = ownerOfChild(_childContract, _childTokenId);
require(isApprovedOrOwner(msg.sender, tokenId));
removeChild(tokenId, _childContract, _childTokenId);
//require that the child was transfered safely to it's destination
require(
_childContract.call(
bytes4(keccak256("transferFrom(address,address,uint256)")), this, _to, _childTokenId
)
);
emit TransferChild(_to, new bytes(0), _childTokenId);
emit TransferChild(_to, new bytes(0), _childContract, _childTokenId);
}

function transferChildToComposable(address _to, uint256 _tokenId, address _childContract, uint256 _childTokenId, bytes _data) public {
transferChild(_to, _tokenId, _childContract, _childTokenId);
function transferChildToComposable(address _to, address _childContract, uint256 _childTokenId, bytes _data) public {
transferChild(_to, _childContract, _childTokenId);
ERC998NFT(_to).onERC721Received(this, _childTokenId, _data);
}

function childOwnerOf(address _childContract, uint256 _childTokenId) external view returns (uint256 tokenId) {
function ownerOfChild(address _childContract, uint256 _childTokenId) public view returns (uint256 tokenId) {
tokenId = childTokenOwner[_childContract][_childTokenId];
if(tokenId == 0) {
require(childTokenIndex[tokenId][_childContract][_childTokenId] != 0, "Child token is not owned by any tokens.");
Expand Down Expand Up @@ -153,3 +156,4 @@ contract ERC998PossessERC721 is ERC998NFT, ERC998NFTEnumerable {
}

}

2 changes: 1 addition & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.17;
pragma solidity ^0.4.24;

contract Migrations {
address public owner;
Expand Down
Loading

0 comments on commit b354e5c

Please sign in to comment.