Created
November 22, 2020 08:17
-
-
Save buhrmi/4263e43bd04a129d8039a882b88e4154 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.17+commit.d19bba13.js&optimize=false&runs=200&gist=
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 "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/token/ERC721/ERC721Full.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/ownership/Ownable.sol"; | |
import "./Strings.sol"; | |
contract OwnableDelegateProxy {} | |
contract Pricer { | |
function price(uint256 streamerID) public view returns (uint256) { | |
return uint256(keccak256(abi.encodePacked(streamerID, blockhash(block.number)))) % 1 ether; | |
} | |
} | |
contract ProxyRegistry { | |
mapping(address => OwnableDelegateProxy) public proxies; | |
} | |
/** | |
* @title ERC721Tradable | |
* ERC721Tradable - ERC721 contract that whitelists a trading address, and has minting functionality. | |
*/ | |
contract ERC721Tradable is ERC721Full, Ownable { | |
using Strings for string; | |
address proxyRegistryAddress; | |
Pricer pricer; | |
constructor( | |
string memory _name, | |
string memory _symbol, | |
address _proxyRegistryAddress | |
) public ERC721Full(_name, _symbol) { | |
proxyRegistryAddress = _proxyRegistryAddress; | |
pricer = new Pricer(); | |
}BA | |
function baseTokenURI() public pure returns (string memory) { | |
return ""; | |
} | |
function setPricer(Pricer p) public onlyOwner { | |
pricer = p; | |
} | |
function purchase(uint256 streamerID) public payable { | |
uint256 _price = pricer.price(streamerID); | |
require(msg.value >= _price); | |
_owner.transfer(msg.value); | |
_mint(msg.sender, streamerID); | |
} | |
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); | |
} | |
} |
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 "./ERC721Tradable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.5.0/contracts/ownership/Ownable.sol"; | |
/** | |
* @title Streamer | |
* Streamer - a contract for my non-fungible streamers. | |
*/ | |
contract Streamer is ERC721Tradable { | |
constructor(address _proxyRegistryAddress) | |
public | |
ERC721Tradable("Streamer", "OSC", _proxyRegistryAddress) | |
{} | |
function baseTokenURI() public pure returns (string memory) { | |
return "https://simplife.loca.lt/streamers/"; | |
} | |
function contractURI() public pure returns (string memory) { | |
return "https://simplife.loca.lt"; | |
} | |
} |
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; | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment