//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.18; contract ERC721 { function ownerOf(uint256) public returns (address); } contract ComposableAssetFactory { // which asset owns which other assets at which address mapping(uint256 => mapping(address => uint256)) children; // which address owns which tokens mapping(uint256 => address) owners; function registerOwner(uint256 _tokenID, address _contract) public { require(owners[_tokenID] == address(0)); ERC721 erc721 = ERC721(_contract); address owner = erc721.ownerOf(_tokenID); assert(owner == msg.sender); owners[_tokenID] = msg.sender; } // change owner of a token function changeOwner(address _newOwner, uint256 _tokenID) public { require(owners[_tokenID] == msg.sender); owners[_tokenID] = _newOwner; } // add child to a composable asset function addChild(uint256 _tokenID, address _childContract, uint256 _indexOrAmount) public { require( _childContract.call( bytes4(keccak256("transferFrom(address,address,uint256")), msg.sender, this, _indexOrAmount ) ); // set as child children[_tokenID][_childContract] = _indexOrAmount; } function transferERC721Child( address _to, uint256 _tokenID, address _childContract, uint256 _childTokenID ) public { // require ownership of parent token && // check parent token owns the child token require(owners[_tokenID] == msg.sender); require(children[_tokenID][_childContract] == _childTokenID); require( _childContract.call( // if true, transfer the child token // not a delegate call, the child token is owned by this contract bytes4(keccak256("transfer(address,uint256)")), _to, _childTokenID ) ); // remove the parent token's ownership of the child token children[_tokenID][_childContract] = 0; } function transferERC20Child( address _to, uint256 _tokenID, address _childContract, uint256 _amount ) public { require(owners[_tokenID] == msg.sender); require(children[_tokenID][_childContract] >= _amount); require( _childContract.call( // if true, transfer the child tokens // not a delegate call, the child tokens are owned by this contract bytes4(keccak256("transfer(address,uint256)")), _to, _amount ) ); //decrement the parent token's balance of child tokens by _amount children[_tokenID][_childContract] -= _amount; } }
0.4.18