Last active
March 1, 2020 16:13
-
-
Save alaingoldman/1fe0950c8ab1a27fc14692527239af52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.21 <0.7.0; | |
import "./TradableERC.sol"; | |
contract TestCon is TradeableERC721Token { | |
constructor(address _proxyRegistryAddress) TradeableERC721Token("EggGame", "Egg", _proxyRegistryAddress) public { } | |
uint storedData; | |
function set(uint x) public { | |
storedData = x; | |
} | |
function get() public view returns (uint) { | |
return storedData; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "../client/node_modules/@openzeppelin/contracts/ownership/Ownable.sol"; | |
import "../client/node_modules/@openzeppelin/contracts/token/ERC721/ERC721Full.sol"; | |
library Strings { | |
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol | |
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) { | |
bytes memory _ba = bytes(_a); | |
bytes memory _bb = bytes(_b); | |
bytes memory _bc = bytes(_c); | |
bytes memory _bd = bytes(_d); | |
bytes memory _be = bytes(_e); | |
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); | |
bytes memory babcde = bytes(abcde); | |
uint k = 0; | |
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; | |
for (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; | |
for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; | |
for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; | |
for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i]; | |
return string(babcde); | |
} | |
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory) { | |
return strConcat(_a, _b, _c, _d, ""); | |
} | |
function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) { | |
return strConcat(_a, _b, _c, "", ""); | |
} | |
function strConcat(string memory _a, string memory _b) internal pure returns (string memory) { | |
return strConcat(_a, _b, "", "", ""); | |
} | |
function uint2str(uint _i) internal pure returns (string memory _uintAsString) { | |
if (_i == 0) { | |
return "0"; | |
} | |
uint j = _i; | |
uint len; | |
while (j != 0) { | |
len++; | |
j /= 10; | |
} | |
bytes memory bstr = new bytes(len); | |
uint k = len - 1; | |
while (_i != 0) { | |
bstr[k--] = byte(uint8(48 + _i % 10)); | |
_i /= 10; | |
} | |
return string(bstr); | |
} | |
} | |
contract OwnableDelegateProxy { } | |
contract ProxyRegistry { | |
mapping(address => OwnableDelegateProxy) public proxies; | |
} | |
/** | |
* @title TradeableERC721Token | |
* TradeableERC721Token - ERC721 contract that whitelists a trading address, and has minting functionality. | |
*/ | |
contract TradeableERC721Token is ERC721Full, Ownable { | |
using Strings for string; | |
address proxyRegistryAddress; | |
uint256 private _currentTokenId = 0; | |
constructor(string memory _name, string memory _symbol, address _proxyRegistryAddress) ERC721Full(_name, _symbol) public { | |
proxyRegistryAddress = _proxyRegistryAddress; | |
} | |
/** | |
* @dev Mints a token to an address with a tokenURI. | |
* @param _to address of the future owner of the token | |
*/ | |
function mintTo(address _to) public onlyOwner { | |
uint256 newTokenId = _getNextTokenId(); | |
_mint(_to, newTokenId); | |
_incrementTokenId(); | |
} | |
/** | |
* @dev calculates the next token ID based on value of _currentTokenId | |
* @return uint256 for the next token ID | |
*/ | |
function _getNextTokenId() private view returns (uint256) { | |
return _currentTokenId.add(1); | |
} | |
/** | |
* @dev increments the value of _currentTokenId | |
*/ | |
function _incrementTokenId() private { | |
_currentTokenId++; | |
} | |
function baseTokenURI() public view returns (string memory) { | |
return ""; | |
} | |
function tokenURI(uint256 _tokenId) external view returns (string memory) { | |
return Strings.strConcat( | |
baseTokenURI(), | |
Strings.uint2str(_tokenId) | |
); | |
} | |
/** | |
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings. | |
*/ | |
function isApprovedForAll( | |
address owner, | |
address operator | |
) | |
public | |
view | |
returns (bool) | |
{ | |
// Whitelist OpenSea proxy contract for easy trading. | |
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); | |
if (address(proxyRegistry.proxies(owner)) == operator) { | |
return true; | |
} | |
return super.isApprovedForAll(owner, operator); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment