Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions contracts/token/CategorizedERC721/CategorizedERC721Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pragma solidity ^0.4.18;

import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import 'zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol';

contract CategorizedERC721Token is ERC721Token, Ownable {

// event fired when a new category is created
event CategoryCreated(uint categoryId, uint fromTokenId, uint toTokenId);

// array with the supply of each category
uint[] categoriesSupply;

// mapping between the tokenId and categoryId
mapping (uint => uint) private tokenIdCategoryId;

// method used to create a new category and mint the tokens
function createCategory(uint _supply) public onlyOwner{
uint categoryId = categoriesSupply.push(_supply);

uint startTokenId = totalSupply();
uint lastTokenId = startTokenId + _supply - 1;
for(uint tokenId = startTokenId; tokenId <= lastTokenId; tokenId++) {
_mint(msg.sender, tokenId);
tokenIdCategoryId[tokenId] = categoryId;
}

CategoryCreated(categoryId, startTokenId, lastTokenId);
}
// method to extend the amount of tokens for a given category
function increaseCategorySupply(uint _categoryId, uint _extraSupply) public onlyOwner{
require(categoriesSupply[_categoryId] > 0);

uint currentSupply = categoriesSupply[_categoryId];

uint newSupply = currentSupply + _extraSupply;
categoriesSupply[_categoryId] = newSupply;

uint startTokenId = totalSupply();
uint lastTokenId = startTokenId + _extraSupply - 1;
for(uint tokenId = startTokenId; tokenId <= lastTokenId; tokenId++) {
_mint(msg.sender, tokenId);
tokenIdCategoryId[tokenId] = _categoryId;
}
}

// get the categoryId for a given token
function getCategoryId(uint _tokenId) public view returns (uint) {
require(_tokenId < totalSupply());
return tokenIdCategoryId[_tokenId];
}

// get the total supply for a given category
function getCategorySupply(uint _categoryId) public view returns (uint){
require(_categoryId < categoriesSupply.length);
return categoriesSupply[_categoryId];
}
}