Created
November 25, 2018 08:37
-
-
Save derekalia/a8a2c2b8020738d65162f863c1b26626 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
import "./ERC721Token.sol"; | |
contract TribeToken is ERC721Token { | |
address public multisigAddress; | |
uint public pool; | |
constructor(string name, string symbol, address dao) public ERC721Token(name, symbol){ | |
multisigAddress = dao; | |
} | |
struct RequestTier { | |
string title; | |
string media; | |
uint price; | |
string[] users; | |
} | |
struct RequestItem { | |
string title; | |
RequestTier[] RequestTiers; | |
uint goal; | |
uint raised; | |
string id; | |
} | |
RequestItem[] public Requests; | |
uint public requestCount = 0; | |
struct Tier { | |
string title; | |
string media; | |
uint price; | |
} | |
Tier[] public Tiers; | |
int256 tokenCount = 0; | |
mapping(address => int) addressToPercentage; | |
// mapping(address => bool) addressToBool; | |
// Mapping of tokenId to token name | |
mapping(uint256 => string) internal idToName; | |
// Mapping of token name to the tokenId | |
// mapping(string => uint256) internal nameToId; | |
mapping(string => uint[]) internal nameToIdArray; | |
function create(string name,string uri) public payable returns (uint) { | |
// name restriction on token | |
// require(nameToId[name] == 0); | |
// increases length of all tokens in zep contract | |
// uint256 tokenId = allTokens.length + 1; | |
uint256 tokenId = allTokens.length; | |
tokenCount = tokenCount + 1; | |
// take that money and send it to the dao | |
multisigAddress.transfer(msg.value); | |
// mints the token | |
_mint(msg.sender, tokenId); | |
_setTokenURI(tokenId,uri); | |
// sets mapping and reverse mapping | |
idToName[tokenId] = name; | |
nameToIdArray[name].push(tokenId); | |
return tokenId; | |
} | |
//we need to keep track of how many people have this | |
function setPool(uint amount) public { | |
require(amount < 100); | |
pool = amount; | |
} | |
function getPool() view public returns (uint){ | |
return pool; | |
} | |
function getTokenArrayFromName(string name) view public returns (uint[]){ | |
return nameToIdArray[name]; | |
} | |
// Getters by token name and token id | |
function getTokenName(uint256 tokenId) view public returns (string){ | |
return idToName[tokenId]; | |
} | |
function payPool(address user) public payable { | |
user.transfer(msg.value); | |
} | |
// function getTokenId(string name) view public returns (uint) { | |
// return nameToId[name]; | |
// } | |
function getTokenCount() view public returns (int){ | |
return tokenCount; | |
} | |
// function setAddressToBool(address addr, bool b) public { | |
// addressToBool[addr] = b; | |
// } | |
// function getAddressToBool(address addr) view public returns (bool){ | |
// return addressToBool[addr]; | |
// } | |
function setAddressToPercentage(address addr,int number) public { | |
addressToPercentage[addr] = number; | |
} | |
function getAddressToPercentage(address addr) view public returns (int){ | |
return addressToPercentage[addr]; | |
} | |
function getDAO() view public returns (address){ | |
return multisigAddress; | |
} | |
function getTierCount() public constant returns(uint) { | |
return Tiers.length; | |
} | |
function addNewTier(string _title,string _media, uint _price) public returns(uint tiersLength) { | |
Tier memory obj; | |
obj.title = _title; | |
obj.media = _media; | |
obj.price = _price; | |
Tiers.push(obj); | |
return Tiers.length; | |
} | |
function getTier(uint index) view public returns (string,string,uint){ | |
return (Tiers[index].title, Tiers[index].media, Tiers[index].price); | |
} | |
function createNewRequest(string _title, uint _goal, string _id, string _reqItemTitle, uint _reqItemPrice ) public returns(uint tiersLength) { | |
Requests.length++; | |
RequestItem storage reqItem = Requests[Requests.length - 1]; | |
reqItem.title = _title; | |
reqItem.goal = _goal; | |
reqItem.id = _id; | |
RequestTier memory reqTier; | |
reqTier.title = _reqItemTitle; | |
reqTier.price = _reqItemPrice; | |
reqTier.media = ''; | |
reqTier.users = new string[](0); | |
reqItem.RequestTiers.push(reqTier); | |
return Requests.length; | |
} | |
function addRequestTier(uint _index, string _reqItemTitle, uint _reqItemPrice ) public returns(uint requestLenght) { | |
RequestTier memory reqTier; | |
reqTier.title = _reqItemTitle; | |
reqTier.price = _reqItemPrice; | |
reqTier.media = ''; | |
reqTier.users = new string[](0); | |
Requests[_index].RequestTiers.push(reqTier); | |
return Requests[_index].RequestTiers.length; | |
} | |
function getRequest(uint index) view public returns (string,string,uint,uint){ | |
return (Requests[index].title, Requests[index].id, Requests[index].goal, Requests[index].RequestTiers.length); | |
} | |
function joinRequestTier(uint _indexRequest, uint _indexReqTier,string name) public payable returns(uint tiersLength) { | |
Requests[_indexRequest].RequestTiers[_indexReqTier].users.push(name); | |
return Requests[_indexRequest].RequestTiers[_indexReqTier].users.length; | |
} | |
function getRequestSize() view public returns (uint){ | |
return requestCount; | |
} | |
function getRequestTier(uint index, uint tierIndex) view public returns (string,string,uint){ | |
return (Requests[index].RequestTiers[tierIndex].title, Requests[index].RequestTiers[tierIndex].media,Requests[index].RequestTiers[tierIndex].price); | |
} | |
function getRequestTierUserCount(uint index, uint tierIndex) view public returns (uint){ | |
return Requests[index].RequestTiers[tierIndex].users.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment