Skip to content

Commit

Permalink
Update CryptoHerosToken
Browse files Browse the repository at this point in the history
  • Loading branch information
PhyrexTsai committed Jul 24, 2018
1 parent 99f3622 commit 14fa0a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
33 changes: 27 additions & 6 deletions contracts/CryptoHerosToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ contract CryptoHerosToken is ERC721Token, Ownable {
mapping (uint256 => address) internal tokenOwner;
uint constant minPrice = 0.01 ether;

string[] public images;
string[] public backgrounds;
string[] public descriptions;
uint[] public numbers;

struct Hero {
uint number;
string image;
Expand All @@ -24,26 +29,42 @@ contract CryptoHerosToken is ERC721Token, Ownable {

mapping(uint256 => Hero) public tokenProperty;


constructor(string name, string symbol) public
ERC721Token(name, symbol)
{ }

function initHeros(uint number, string image, string background, string desc) public onlyOwner {
heros.push(Hero(number, image, background, desc));
function initImage(string _image) public onlyOwner {
images.push(_image);
}

function initBackground(string _background) public onlyOwner {
backgrounds.push(_background);
}

function initNumberAndDescription(uint _number, string _description) public onlyOwner {
numbers.push(_number);
descriptions.push(_description);
}

/**
* Only owner can mint
*/
function mint() public payable {
require(heros.length > 0);
require(numbers.length > 0);
require(images.length > 0);
require(backgrounds.length > 0);
require(descriptions.length > 0);
require(msg.value >= minPrice);
require(owner.send(msg.value));
uint256 _tokenId = totalSupply();
tokenOwner[_tokenId] = msg.sender;
uint num = rand(0, numbers.length);
uint _number = numbers[num];
string _image = images[rand(0, images.length)];
string _background = backgrounds[rand(0, backgrounds.length)];
string _description = descriptions[num];
tokenProperty[_tokenId] = Hero({number: _number, image: _image, background: _background, description: _description});
super._mint(msg.sender, _tokenId);
//super._setTokenURI(_tokenId, heros[rand(0, heros.length)]);
tokenProperty[_tokenId] = heros[rand(0, heros.length)];
}

function burn(uint256 _tokenId) public onlyOwner {
Expand Down
6 changes: 3 additions & 3 deletions test/cryptoHerosToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ contract("CryptoHeros token", accounts => {

it("Should init hero", async () => {
let cryptoHerosToken = await CryptoHerosToken.deployed();
let result = await cryptoHerosToken.initHeros(0, 'image0', 'background0', 'dec0');
let result = await cryptoHerosToken.initImage('image0');
assert.equal(result.receipt.status, '0x1');
let result2 = await cryptoHerosToken.initHeros(1, 'image1', 'background1', 'dec1');
let result2 = await cryptoHerosToken.initBackground('background0');
assert.equal(result2.receipt.status, '0x1');
let result3 = await cryptoHerosToken.initHeros(2, 'image2', 'background2', 'dec2');
let result3 = await cryptoHerosToken.initNumberAndDescription(1, 'description0');
assert.equal(result3.receipt.status, '0x1');
//assert.equal(owner, accounts[0]);
});
Expand Down

0 comments on commit 14fa0a3

Please sign in to comment.