Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeCheng1208 committed Jul 23, 2018
0 parents commit ed82e3a
Show file tree
Hide file tree
Showing 109 changed files with 5,879 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/node_modules
/build

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
package-lock.json
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Nifty Game

This repo is a crypto card game base on ERC721, non-fungible token, using [OpenZepplin](https://github.com/OpenZeppelin/openzeppelin-solidity).

## How To Install Dependencies

First install required dependencies:

You'll need local ethereum node, I recommend `ganache-cli`. You can install it from npm.

```
npm install -g ganache-cli
```

Then install contract dependencies:

```
npm install
```

## How To Test

First make sure that local ethereum node is running. Execute:

```
ganache-cli --gasLimit 0xffffffffff -p 8545
```

Now you can compile and deploy contracts:

```
truffle compile && truffle migrate
```

Run contract tests:

```
truffle test
```
6 changes: 6 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# TODO

- [ ] Check the owner total owned
- [ ] Link to IPFS show the image
- [ ] Transfer Ownership test component
- [ ] Update CryptoHero information
40 changes: 40 additions & 0 deletions contracts/CryptoHerosToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pragma solidity ^0.4.17;

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

/**
* @title ERC721TokenMock
* This mock just provides a public mint and burn functions for testing purposes,
* and a public setter for metadata URI
*/
contract CryptoHerosToken is ERC721Token, Ownable {
mapping (uint256 => address) internal tokenOwner;

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

/**
* Only owner can mint
*/
function mint(address _to, string _uri) public onlyOwner {
uint256 _tokenId = totalSupply();
tokenOwner[_tokenId] = _to;
super._mint(_to, _tokenId);
super._setTokenURI(_tokenId, _uri);
}

function burn(uint256 _tokenId) public onlyOwner {
tokenOwner[_tokenId] = address(0);
super._burn(ownerOf(_tokenId), _tokenId);
}

function setTokenURI(uint256 _tokenId, string _uri) public onlyOwnerOf(_tokenId) {
super._setTokenURI(_tokenId, _uri);
}

function getOwnedTokens(address _owner) external view returns (uint256[]) {
return ownedTokens[_owner];
}
}
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.4.17;

contract Migrations {
address public owner;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender == owner) _;
}

constructor() public {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
23 changes: 23 additions & 0 deletions dapp/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"presets": [
"stage-2",
"react",
[
"env", {
"targets": {
"browsers": ["> 1%", "last 5 versions", "Firefox >= 45", "iOS >=8", "Safari >=8","ie >= 10"]
}
}
]
],
"plugins": [
"babel-plugin-transform-class-properties",
"transform-async-to-generator",
"transform-export-extensions",
"add-module-exports",
[
"transform-runtime", { "polyfill": false, "regenerator": true }
]
]
}

2 changes: 2 additions & 0 deletions dapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
node_modules
24 changes: 24 additions & 0 deletions dapp/CARD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Card

#### Token URI format
```
{"name": "Chicken Piemon", "image": "QmPmA4s34EakytF5GuCwxpB1Ns7riw6NdYSVHjnFK1vQs8", "HP": "0.9 ETH", "ATK": "9", "DEF": "5"}
```

#### Card List

Name | IPFS Hash | HP | ATK | DEF
--------------------------|:------------------------------------------------|:---------|:----|:----
Beef Noodles | QmeVXWcHeV5dFmeUWezMUah5p6JGKMH4qRLXNCoV4Tgfnj | 0.5 ETH | 6 | 6
Chichen Piemon | QmPmA4s34EakytF5GuCwxpB1Ns7riw6NdYSVHjnFK1vQs8 | 0.9 ETH | 9 | 5
Mongomon | QmXt25XMy8mSS4QD8YTTzGCjQukuvhYqD7wU7srV7THpU3 | 1.2 ETH | 10 | 8
Oyster Pancake | QmT54jmgV6r73wrK2Vb6nVKTp5DwXWgG8bwVGn5a7NKKM2 | 0.45 ETH | 5 | 3
Perl King | QmYDg33vcwxPWfnnd7C3jTbXNjLMfNRUvwDqyaVubnHosw | 0.35 ETH | 4 | 3
Pig Bloodmon | QmRwrHDeBNfJvznv1H3zTKyDEy8u4TcNm7R9ApXEvTpZ6W | 0.3 ETH | 3 | 6
Pork Belly Bao | Qmd6fU6fGtZAjUVRXfNAhVFY1hHAE4tASRScexsVocKPW9 | 1.0 ETH | 9 | 10
Pork Rice Lady | QmUxJMqPQXNYYQ5w6Ca7sTa4QZ3cT1HTW4zndKjugnqzFr | 0.5 ETH | 5 | 5
Rice Dum Dum | QmVdGLZ8kgCT27WjQFyZ5rvrb7Z7EfwdPMtvHi4kVTogHr | 0.5 ETH | 6 | 7
Taro Bella | QmfPRBPRFFk6Sap64RnxFMSXoiSkyaJb8vocAMzCq3HSSs | 0.3 ETH | 5 | 2
Tofu & Seaweed | QmZEQnZfoaQBopJjfSdfDZuTrFQGkAqcehjAFgxs2w1fEx | 0.1 ETH | 1 | 2
Xia Long Baby | Qmb6vdR94CFAaUZhxvaBFPLhY43rkKaZjhvpP5MQCBw1wx | 0.7 ETH | 8 | 5

61 changes: 61 additions & 0 deletions dapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Nifty game dapp

This is the CryptoHeros dapp.

### Technical stack

#### Frontend
- React
- Redux
- Saga
- Web3(MetaMask)

#### UI
- Sass
- Material-UI

#### Smart contract/Solidity
- Truffle

### Install flow

#### Install ganache

```
npm install -g ganache-cli
```

#### Install truffle

```
npm install -g truffle
```

#### Build repo

```
npm install
truffle compile
```

#### Start repo

Open a new console
```
ganache-cli
```

```
truffle migrate
npm start
```

#### Build repo

```
npm run build
```

## Reference
ganache-cli: https://github.com/trufflesuite/ganache-cli
truffle: https://github.com/trufflesuite/truffle
90 changes: 90 additions & 0 deletions dapp/config/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict';

const fs = require('fs');
const path = require('path');
const paths = require('./paths');

// Make sure that including paths.js after env.js will read .env variables.
delete require.cache[require.resolve('./paths')];

const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
throw new Error(
'The NODE_ENV environment variable is required but was not specified.'
);
}

// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
var dotenvFiles = [
`${paths.dotenv}.${NODE_ENV}.local`,
`${paths.dotenv}.${NODE_ENV}`,
// Don't include `.env.local` for `test` environment
// since normally you expect tests to produce the same
// results for everyone
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
paths.dotenv,
].filter(Boolean);

// Load environment variables from .env* files. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set.
// https://github.com/motdotla/dotenv
dotenvFiles.forEach(dotenvFile => {
if (fs.existsSync(dotenvFile)) {
require('dotenv').config({
path: dotenvFile,
});
}
});

// We support resolving modules according to `NODE_PATH`.
// This lets you use absolute paths in imports inside large monorepos:
// https://github.com/facebookincubator/create-react-app/issues/253.
// It works similar to `NODE_PATH` in Node itself:
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
// We also resolve them to make sure all tools using them work consistently.
const appDirectory = fs.realpathSync(process.cwd());
process.env.NODE_PATH = (process.env.NODE_PATH || '')
.split(path.delimiter)
.filter(folder => folder && !path.isAbsolute(folder))
.map(folder => path.resolve(appDirectory, folder))
.join(path.delimiter);

// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
// injected into the application via DefinePlugin in Webpack configuration.
const REACT_APP = /^REACT_APP_/i;

function getClientEnvironment(publicUrl) {
const raw = Object.keys(process.env)
.filter(key => REACT_APP.test(key))
.reduce(
(env, key) => {
env[key] = process.env[key];
return env;
},
{
// Useful for determining whether we’re running in production mode.
// Most importantly, it switches React into the correct mode.
NODE_ENV: process.env.NODE_ENV || 'development',
// Useful for resolving the correct path to static assets in `public`.
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
PUBLIC_URL: publicUrl,
}
);
// Stringify all values so we can feed into Webpack DefinePlugin
const stringified = {
'process.env': Object.keys(raw).reduce((env, key) => {
env[key] = JSON.stringify(raw[key]);
return env;
}, {}),
};

return { raw, stringified };
}

module.exports = getClientEnvironment;
14 changes: 14 additions & 0 deletions dapp/config/jest/cssTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// This is a custom Jest transformer turning style imports into empty objects.
// http://facebook.github.io/jest/docs/tutorial-webpack.html

module.exports = {
process() {
return 'module.exports = {};';
},
getCacheKey() {
// The output is always the same.
return 'cssTransform';
},
};
12 changes: 12 additions & 0 deletions dapp/config/jest/fileTransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const path = require('path');

// This is a custom Jest transformer turning file imports into filenames.
// http://facebook.github.io/jest/docs/tutorial-webpack.html

module.exports = {
process(src, filename) {
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
},
};
Loading

0 comments on commit ed82e3a

Please sign in to comment.