├── mock
└── .gitkeep
├── .eslintrc
├── .roadhogrc.mock.js
├── src
├── index.css
├── assets
│ └── yay.jpg
├── index.js
├── router.js
├── routes
│ ├── IndexPage.js
│ └── IndexPage.css
├── utils
│ └── request.js
├── components
│ ├── Example.js
│ ├── MainPanel.js
│ ├── GameContract.js
│ ├── Common.js
│ └── TokenContract.js
├── services
│ ├── contract
│ │ ├── divieslongAbi.json
│ │ ├── gameAbi.json
│ │ ├── tokenAbi.json
│ │ ├── hourglassAbi.json
│ │ └── pklongAbi.json
│ ├── common.js
│ └── example.js
└── models
│ ├── example.js
│ └── common.js
├── common.png
├── .webpackrc
├── dist
├── static
│ └── yay.44dd3333.jpg
└── index.html
├── README.md
├── .gitignore
├── .editorconfig
├── public
└── index.html
├── package.json
└── contracts
├── game.sol
└── token.sol
/mock/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "umi"
3 | }
4 |
--------------------------------------------------------------------------------
/.roadhogrc.mock.js:
--------------------------------------------------------------------------------
1 |
2 | export default {
3 | };
4 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 |
2 | html, body, :global(#root) {
3 | height: 100%;
4 | }
5 |
6 |
--------------------------------------------------------------------------------
/common.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cowkeys/ethcontract-calling-web/com/common.png
--------------------------------------------------------------------------------
/src/assets/yay.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cowkeys/ethcontract-calling-web/com/src/assets/yay.jpg
--------------------------------------------------------------------------------
/.webpackrc:
--------------------------------------------------------------------------------
1 | {
2 | "extraBabelPlugins": [
3 | ["import", { "libraryName": "antd", "style": "css" }]
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/dist/static/yay.44dd3333.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cowkeys/ethcontract-calling-web/com/dist/static/yay.44dd3333.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### intro
3 |
4 | 输入 etherscan.io 已经认证的合约地址
5 | 可通过metamask 直接调用合约方法。
6 |
7 | ### web
8 |
9 | 
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # production
7 | /dist/*.async.js
8 |
9 | # misc
10 | .DS_Store
11 | npm-debug.log*
12 | /.idea
13 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.md]
13 | trim_trailing_whitespace = false
14 |
15 | [Makefile]
16 | indent_style = tab
17 |
--------------------------------------------------------------------------------
/dist/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dva Demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Dva Demo
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import dva from 'dva';
2 | import './index.css';
3 |
4 | // 1. Initialize
5 | const app = dva();
6 |
7 | // 2. Plugins
8 | // app.use({});
9 |
10 | // 3. Model
11 | app.model(require('./models/example').default);
12 |
13 | app.model(require('./models/common').default);
14 |
15 | // 4. Router
16 | app.router(require('./router').default);
17 |
18 | // 5. Start
19 | app.start('#root');
20 |
--------------------------------------------------------------------------------
/src/router.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Router, Route, Switch } from 'dva/router';
3 | import IndexPage from './routes/IndexPage';
4 |
5 | function RouterConfig({ history }) {
6 | return (
7 |
8 |
9 |
10 |
11 |
12 | );
13 | }
14 |
15 | export default RouterConfig;
16 |
--------------------------------------------------------------------------------
/src/routes/IndexPage.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { connect } from 'dva';
3 | import styles from './IndexPage.css';
4 | import Example from '../components/Example';
5 |
6 | function IndexPage() {
7 | return (
8 |
9 |
10 |
11 |
12 | );
13 | }
14 |
15 | IndexPage.propTypes = {
16 | };
17 |
18 | export default connect()(IndexPage);
19 |
--------------------------------------------------------------------------------
/src/routes/IndexPage.css:
--------------------------------------------------------------------------------
1 |
2 | .normal {
3 | font-family: Georgia, sans-serif;
4 | margin-top: 3em;
5 | text-align: center;
6 | }
7 |
8 | .title {
9 | font-size: 2.5rem;
10 | font-weight: normal;
11 | letter-spacing: -1px;
12 | }
13 |
14 | .welcome {
15 | height: 328px;
16 | #background: url(../assets/yay.jpg) no-repeat center 0;
17 | #background-size: 388px 328px;
18 | }
19 |
20 | .list {
21 | font-size: 1.2em;
22 | margin-top: 1.8em;
23 | list-style: none;
24 | line-height: 1.5em;
25 | }
26 |
27 | .list code {
28 | background: #f7f7f7;
29 | }
30 |
--------------------------------------------------------------------------------
/src/utils/request.js:
--------------------------------------------------------------------------------
1 | import fetch from 'dva/fetch';
2 |
3 | function parseJSON(response) {
4 | return response.json();
5 | }
6 |
7 | function checkStatus(response) {
8 | if (response.status >= 200 && response.status < 300) {
9 | return response;
10 | }
11 |
12 | const error = new Error(response.statusText);
13 | error.response = response;
14 | throw error;
15 | }
16 |
17 | /**
18 | * Requests a URL, returning a promise.
19 | *
20 | * @param {string} url The URL we want to request
21 | * @param {object} [options] The options we want to pass to "fetch"
22 | * @return {object} An object containing either "data" or "err"
23 | */
24 | export default function request(url, options) {
25 | return fetch(url, options)
26 | .then(checkStatus)
27 | .then(parseJSON)
28 | .then(data => ({ data }))
29 | .catch(err => ({ err }));
30 | }
31 |
--------------------------------------------------------------------------------
/src/components/Example.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Tabs } from 'antd';
3 | import {connect} from "dva/index";
4 | import MainPanel from './MainPanel';
5 | import Common from './Common';
6 | import GameContract from './GameContract';
7 | import TokenContract from './TokenContract';
8 |
9 | const TabPane = Tabs.TabPane;
10 |
11 |
12 | function callback(key) {
13 | console.log(key);
14 | }
15 |
16 | const Example = () => {
17 | return (
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | );
35 | };
36 |
37 | Example.propTypes = {
38 | };
39 |
40 | export default connect()(Example);
41 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "scripts": {
4 | "start": "roadhog server",
5 | "build": "roadhog build",
6 | "lint": "eslint --ext .js src test",
7 | "precommit": "npm run lint"
8 | },
9 | "dependencies": {
10 | "antd": "^3.8.2",
11 | "babel-plugin-import": "^1.8.0",
12 | "big-number": "^1.0.0",
13 | "bignumber.js": "^7.2.1",
14 | "dva": "^2.4.0",
15 | "eth-query": "^2.1.2",
16 | "ethjs-contract": "^0.2.3",
17 | "ethjs-query": "^0.3.8",
18 | "monaco-editor": "^0.14.3",
19 | "react": "^16.2.0",
20 | "react-dom": "^16.2.0",
21 | "react-monaco-editor": "^0.18.0",
22 | "web3": "^1.0.0-beta.35"
23 | },
24 | "devDependencies": {
25 | "babel-plugin-dva-hmr": "^0.3.2",
26 | "eslint": "^4.14.0",
27 | "eslint-config-umi": "^0.1.1",
28 | "eslint-plugin-flowtype": "^2.34.1",
29 | "eslint-plugin-import": "^2.6.0",
30 | "eslint-plugin-jsx-a11y": "^5.1.1",
31 | "eslint-plugin-react": "^7.1.0",
32 | "husky": "^0.12.0",
33 | "redbox-react": "^1.4.3",
34 | "roadhog": "^2.0.0"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/services/contract/divieslongAbi.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"pushers_","outputs":[{"name":"tracker","type":"uint256"},{"name":"time","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pusherTracker_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"balances","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_percent","type":"uint256"}],"name":"distribute","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"rateLimiter_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"pusher","type":"address"},{"indexed":false,"name":"startingBalance","type":"uint256"},{"indexed":false,"name":"masternodePayout","type":"uint256"},{"indexed":false,"name":"finalBalance","type":"uint256"},{"indexed":false,"name":"compressedData","type":"uint256"}],"name":"onDistribute","type":"event"}]
2 |
--------------------------------------------------------------------------------
/src/services/contract/gameAbi.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[],"name":"keyprice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"pIDxAddr_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"pID_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"SeeleTotal_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"endRound","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"}],"name":"BuyKeyFromSeele","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"plyr_","outputs":[{"name":"id","type":"uint256"},{"name":"addr","type":"address"},{"name":"name","type":"bytes32"},{"name":"gen","type":"uint256"},{"name":"aff","type":"uint256"},{"name":"keys","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"}]
2 |
--------------------------------------------------------------------------------
/src/models/example.js:
--------------------------------------------------------------------------------
1 | import * as examples from '../services/example';
2 | import {BigNumber} from "bignumber.js/bignumber";
3 |
4 | export default {
5 |
6 | namespace: 'example',
7 |
8 | state: {
9 | address:"0x",
10 | balance:0,
11 | allowance:0,
12 | gamekeys:0,
13 | dividend:0,
14 | seelebalance:0.0
15 | },
16 |
17 | subscriptions: {
18 | setup({ dispatch, history }) { // eslint-disable-line
19 | //dispatch({type:'reloadInfo'});
20 | },
21 | },
22 |
23 | effects: {
24 | *approve({ payload:{value} }, { call, put }) { // eslint-disable-line
25 | const result = yield call(examples.allocateSeele,{value});
26 | yield put(
27 | { type: 'save'}
28 | );
29 | },
30 |
31 | *buykey({ payload:{value} }, { call, put }) { // eslint-disable-line
32 | const result = yield call(examples.buyKeyFromSeele,{value});
33 | const keys = yield call(examples.currentPlayer,{});
34 | yield put({ type: 'save',
35 | payload:{
36 | gamekeys:+keys
37 | }
38 | });
39 | },
40 |
41 | *buyseele({ payload:{value} }, { call, put }) { // eslint-disable-line
42 | const result = yield call(examples.buyKeyFromSeele,{value});
43 | const keys = yield call(examples.currentPlayer,{});
44 | yield put({ type: 'save',
45 | payload:{
46 | gamekeys:+keys
47 | }
48 | });
49 | },
50 |
51 | *reloadinfo({ payload }, { call, put }) { // eslint-disable-line
52 | const coinbase = yield call(examples.getCoinbase,{});
53 | const balance = yield call(examples.getBalance,{coinbase});
54 | const allowance = yield call(examples.getLeftAuthSeele,{});
55 | const keys = yield call(examples.currentPlayer,{});
56 | const seelebalance = yield call(examples.seeleBalance,{});
57 |
58 | yield put(
59 | { type: 'save' ,
60 | payload:{
61 | address:coinbase,
62 | balance:balance,
63 | allowance:+allowance,
64 | gamekeys:+keys,
65 | seelebalance:+seelebalance
66 | }
67 | });
68 | },
69 |
70 | *fetch({ payload }, { call, put }) { // eslint-disable-line
71 | yield put({ type: 'save' });
72 | },
73 | },
74 |
75 | reducers: {
76 | save(state, action) {
77 | return { ...state, ...action.payload };
78 | },
79 | },
80 |
81 | };
82 |
--------------------------------------------------------------------------------
/src/models/common.js:
--------------------------------------------------------------------------------
1 | import * as com from '../services/common';
2 |
3 | export default {
4 | namespace: 'common',
5 | state: {
6 | address:"0x",
7 | balance:0,
8 | contract:{},
9 | abi:[],
10 | result:{},
11 | network:"api"
12 | },
13 |
14 | subscriptions: {
15 | setup({ dispatch, history }) { // eslint-disable-line
16 | //dispatch({type:'reloadInfo'});
17 | },
18 | },
19 |
20 | effects: {
21 |
22 | //================common function============
23 | * callingfunc({payload: {ctr,func,value,pay}}, {call, put}) { // eslint-disable-line
24 | console.log("ctr:",ctr,'func',func,"value:",...value,"| pay:",pay);
25 | const result = yield call(com.calling, ctr,func,pay,...value);
26 | if (result.error){
27 | yield put({type: 'save'});
28 | }else{
29 | yield put({
30 | type: 'save',
31 | payload:{
32 | result:result
33 | }
34 | });
35 | }
36 |
37 | },
38 |
39 | *changenetwork({ payload:{network} }, { call, put }) { // eslint-disable-line
40 | const item = yield call(com.ChangeNetwork,{network});
41 | console.log("item",item);
42 | yield put({ type: 'save',
43 | payload:{
44 | network:network
45 | }
46 | });
47 | },
48 |
49 | //================contract
50 | *getCtract({ payload:{address} }, { call, put }) { // eslint-disable-line
51 | const item = yield call(com.NewContract,{address});
52 |
53 | if (item.error){
54 | yield put({type: 'save'});
55 | }else {
56 | yield put({
57 | type: 'save',
58 | payload: {
59 | contract: item.contract,
60 | abi: item.abi
61 | }
62 | });
63 | }
64 | },
65 |
66 | *reloadinfo({ payload }, { call, put }) { // eslint-disable-line
67 | const coinbase = yield call(com.getCoinbase,{});
68 | const balance = yield call(com.getBalance,{coinbase});
69 |
70 | yield put(
71 | { type: 'save' ,
72 | payload:{
73 | address:coinbase,
74 | balance:balance
75 | }
76 | });
77 | },
78 |
79 | *fetch({ payload }, { call, put }) { // eslint-disable-line
80 | yield put({ type: 'save' });
81 | },
82 | },
83 |
84 | reducers: {
85 | save(state, action) {
86 | return { ...state, ...action.payload };
87 | },
88 | },
89 |
90 | };
91 |
--------------------------------------------------------------------------------
/contracts/game.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.24;
2 |
3 | interface SeeleToken {
4 | function totalSupply() external view returns (uint256);
5 | function balanceOf(address _who) external view returns (uint256);
6 | function transfer(address _to, uint256 _value) external returns (bool);
7 | function allowance(address _owner, address _spender) external view returns (uint256);
8 | function transferFrom(address _from, address _to, uint256 _value) external returns (bool);
9 | function approve(address _spender, uint256 _value) external returns (bool);
10 | }
11 |
12 | contract Seelelong {
13 |
14 | SeeleToken constant private Seele = SeeleToken(0xBf10E654146ca9EA3A7B5Bf6c6cB4446688e5476);
15 |
16 | struct Player {
17 | uint256 id;
18 | address addr; // player address
19 | bytes32 name; // player name
20 | uint256 gen; // general vault
21 | uint256 aff; // affiliate vault
22 | uint256 keys;
23 | }
24 |
25 | mapping (uint256 => Player) public plyr_;
26 | mapping (address => uint256) public pIDxAddr_;
27 | uint256 public pID_; // total number of players
28 | uint256 public SeeleTotal_;
29 | uint256 public keyprice = 0.0001 ether;
30 |
31 | constructor (){
32 | pID_ = 0;
33 | }
34 |
35 | function()
36 | public
37 | payable
38 | {
39 | revert();
40 | }
41 |
42 |
43 | event log(uint256,uint256,uint256);
44 | // 用seele买key
45 | function BuyKeyFromSeele(uint256 _value)
46 | public
47 | payable
48 | {
49 | uint id = pIDxAddr_[msg.sender];
50 | if (id == 0) {
51 | pID_++;
52 | id = pID_;
53 | pIDxAddr_[msg.sender] = id;
54 | }
55 |
56 | plyr_[id].addr = msg.sender;
57 |
58 | // 需要先approve才能成功
59 | Seele.transferFrom(msg.sender,this,_value);
60 | SeeleTotal_+=_value;
61 |
62 | plyr_[id].keys += _value / keyprice * 10**18;
63 | plyr_[id].aff += _value / 2;
64 | emit log(_value,keyprice,_value / keyprice * 10**18);
65 | }
66 |
67 | function withdraw()
68 | public
69 | payable
70 | {
71 | uint id = pIDxAddr_[msg.sender];
72 | require( id > 0 );
73 |
74 | Seele.transfer(msg.sender, plyr_[id].aff);
75 | SeeleTotal_ -= plyr_[id].aff;
76 | plyr_[id].aff = 0;
77 | plyr_[id].keys = 0;
78 | }
79 |
80 | //测试分配规则 最后一个人50% 剩下的平分
81 | function endRound()
82 | public
83 | payable
84 | {
85 | require(pID_ > 0);
86 | if (pID_ == 1) {
87 | Seele.transfer(plyr_[pID_].addr, SeeleTotal_);
88 | plyr_[pID_].aff = 0;
89 | return;
90 | }
91 |
92 | address winner = plyr_[pID_].addr;
93 | uint256 winnerReward = SeeleTotal_ / 2;
94 |
95 | Seele.transfer(winner, winnerReward);
96 |
97 | uint256 leftRewardPer = (SeeleTotal_ - winnerReward) / (pID_ - 1);
98 |
99 | for( uint8 i=1; i< pID_; i++ ){
100 | Seele.transfer(plyr_[i].addr, leftRewardPer);
101 | plyr_[i].aff = 0;
102 | }
103 |
104 | SeeleTotal_ = 0;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/services/common.js:
--------------------------------------------------------------------------------
1 | import Eth from 'ethjs-query';
2 | import EthContract from "ethjs-contract";
3 | import request from '../utils/request';
4 | import {BigNumber} from "bignumber.js/bignumber";
5 | var urlprefix = "api";
6 | const {web3} = window;
7 | var eth = new Eth(web3.currentProvider);
8 | var CoinBase = '';
9 | var Contracts = {};
10 |
11 | export function getCoinbase() {
12 | return new Promise(function (resolve, reject) {
13 | web3.eth.getCoinbase((err, coinbase) => {
14 | if (err) {
15 | alert(err);
16 | resolve(err);
17 | } else {
18 | console.log('coinbase', coinbase);
19 | CoinBase = coinbase;
20 | resolve(coinbase);
21 | }
22 | });
23 | })
24 | }
25 |
26 | export async function ChangeNetwork({network}) {
27 | urlprefix = network+"";
28 | return true;
29 | }
30 |
31 | export function getBalance({coinbase}) {
32 | return new Promise(function (resolve, reject) {
33 | web3.eth.getBalance(coinbase, (err, balance) => {
34 | if (err) {
35 | resolve(err);
36 | } else {
37 | resolve(web3.fromWei(balance.toNumber(), "ether"));
38 | }
39 | });
40 | })
41 | }
42 |
43 | export function NewContract({name, address}) {
44 | var url = "http://"+urlprefix+".etherscan.io/api?module=contract&action=getabi&address=" + address;
45 | console.log(url);
46 | return new Promise(function (resolve, reject) {
47 | request(url, {}).then(function (data) {
48 | if (data.data.result =="Contract source code not verified") {
49 | alert('Contract source code not verified')
50 | var res = {};
51 | res.error = "data.data.result";
52 | resolve(res);
53 | return
54 | }
55 | var contract = new EthContract(eth);
56 | var abi = JSON.parse(data.data.result);
57 | //var aaa = "[{\"constant\":false,\"inputs\":[],\"name\":\"aFunc\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"cFunc\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"bFunc\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"log\",\"type\":\"event\"}]"
58 | //var abi = JSON.parse(aaa);
59 | var Ctr = contract(abi);
60 | var item = {};
61 | item.contract = Ctr.at(address);
62 | item.abi = abi;
63 |
64 | Contracts[address] = item.contract;
65 | resolve(item);
66 | }).catch(function (err) {
67 | reject(err);
68 | })
69 | })
70 | }
71 |
72 | function toBigNumber(value) {
73 | if (value == 0) {
74 | return 0
75 | }
76 | return new BigNumber(value).times('1000000000000000000');
77 | }
78 |
79 | export function calling(ctr, fn,pay, ...param) {
80 | return new Promise(function (resolve, reject) {
81 | Contracts[ctr][fn](...param,{from:CoinBase,value:toBigNumber(pay)},
82 | function (error, result) {
83 | if (error) {
84 | console.log(error)
85 | var res = {};
86 | res.error = error;
87 | resolve(res);
88 | return
89 | }
90 |
91 | console.log("result:",result);
92 | resolve(result);
93 | })
94 | })
95 | }
96 |
--------------------------------------------------------------------------------
/src/services/contract/tokenAbi.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"unpause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"pause","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[],"name":"Pause","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpause","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]
2 |
--------------------------------------------------------------------------------
/src/components/MainPanel.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {connect} from "dva/index";
3 | import { Card, Col, Row, InputNumber,Button} from 'antd';
4 |
5 | class MainPanel extends React.Component {
6 | constructor(props) {
7 | super(props)
8 | this.state = {
9 | money : 100,
10 | seele : 0,
11 | buyseele:0
12 | }
13 | }
14 |
15 | componentDidMount () {
16 | this.props.dispatch({
17 | type: 'example/reloadinfo',
18 | });
19 | }
20 |
21 | approve = () => {
22 | console.log("approve:",this.state.money);
23 | this.props.dispatch({
24 | type: 'example/approve',
25 | payload: {value:+this.state.money},
26 | });
27 | };
28 |
29 | buykey = () => {
30 | console.log("buykey:",this.state.seele);
31 | this.props.dispatch({
32 | type: 'example/buykey',
33 | payload: {value:+this.state.seele},
34 | });
35 | };
36 |
37 | onAuthChange = (value) => {
38 | this.setState({
39 | money:value,
40 | })
41 | };
42 |
43 | onBuySeeleChange = (value) => {
44 | this.setState({
45 | buyseele:value,
46 | })
47 | };
48 |
49 | buyseele = () => {
50 | console.log("buyseele:",this.state.buyseele);
51 | this.props.dispatch({
52 | type: 'example/buyseele',
53 | payload: {value:+this.state.buyseele},
54 | });
55 | };
56 |
57 | onSeeleChange = (value) => {
58 | this.setState({
59 | seele:(value * 0.0001).toFixed(5),
60 | })
61 | };
62 |
63 | render() {
64 | /*
65 |
66 | {this.props.seelebalance}
67 |
68 |
69 |
70 |
71 | (seele)
72 |
73 |
74 |
*/
75 | return (
76 |
77 |
78 |
79 | {this.props.address}
80 |
81 |
82 | {this.props.balance}
83 |
84 |
85 | ..
86 |
87 |
88 |
89 | 授权额度:{this.props.allowance} (seele) / 账户总额度:{this.props.seelebalance} (seele)
90 |
91 |
92 |
93 |
94 |
95 | (seele)
96 |
97 |
98 |
99 | ..
100 |
101 |
102 |
103 | 已有:{this.props.gamekeys} (key)
104 |
105 | key = {this.state.seele} seele
106 |
107 |
108 |
109 |
110 | 分红:{this.props.gamekeys} (seele)
111 |
112 |
113 |
114 |
115 |
116 | );
117 | }
118 | };
119 |
120 |
121 | function mapStateToProps(state) {
122 | const { address, balance,allowance, gamekeys, dividend,seelebalance } = state.example;
123 | return {
124 | address, balance,allowance, gamekeys, dividend,seelebalance
125 | };
126 | }
127 |
128 | export default connect(mapStateToProps)(MainPanel);
129 |
--------------------------------------------------------------------------------
/src/components/GameContract.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {connect} from "dva/index";
3 | import MonacoEditor from 'react-monaco-editor';
4 |
5 | class GameContract extends React.Component {
6 | constructor(props) {
7 | super(props)
8 | this.state = {
9 | code:"pragma solidity ^0.4.24;\n" +
10 | "\n" +
11 | "interface SeeleToken {\n" +
12 | " function totalSupply() external view returns (uint256);\n" +
13 | " function balanceOf(address _who) external view returns (uint256);\n" +
14 | " function transfer(address _to, uint256 _value) external returns (bool);\n" +
15 | " function allowance(address _owner, address _spender) external view returns (uint256);\n" +
16 | " function transferFrom(address _from, address _to, uint256 _value) external returns (bool);\n" +
17 | " function approve(address _spender, uint256 _value) external returns (bool);\n" +
18 | "}\n" +
19 | "\n" +
20 | "contract Seelelong {\n" +
21 | " \n" +
22 | " SeeleToken constant private Seele = SeeleToken(0xBf10E654146ca9EA3A7B5Bf6c6cB4446688e5476);\n" +
23 | " \n" +
24 | " struct Player {\n" +
25 | " uint256 id;\n" +
26 | " address addr; // player address\n" +
27 | " bytes32 name; // player name\n" +
28 | " uint256 gen; // general vault\n" +
29 | " uint256 aff; // affiliate vault\n" +
30 | " uint256 keys;\n" +
31 | " }\n" +
32 | " \n" +
33 | " mapping (uint256 => Player) public plyr_;\n" +
34 | " mapping (address => uint256) public pIDxAddr_;\n" +
35 | " uint256 public pID_; // total number of players\n" +
36 | " uint256 public SeeleTotal_;\n" +
37 | " uint256 public keyprice = 0.0001 ether;\n" +
38 | " \n" +
39 | " constructor (){\n" +
40 | " pID_ = 0;\n" +
41 | " }\n" +
42 | " \n" +
43 | " function()\n" +
44 | " public\n" +
45 | " payable\n" +
46 | " {\n" +
47 | " revert();\n" +
48 | " }\n" +
49 | "\n" +
50 | "\n" +
51 | " event log(uint256,uint256,uint256);\n" +
52 | " // 用seele买key\n" +
53 | " function BuyKeyFromSeele(uint256 _value)\n" +
54 | " public\n" +
55 | " payable\n" +
56 | " {\n" +
57 | " uint id = pIDxAddr_[msg.sender];\n" +
58 | " if (id == 0) {\n" +
59 | " pID_++;\n" +
60 | " id = pID_;\n" +
61 | " pIDxAddr_[msg.sender] = id;\n" +
62 | " }\n" +
63 | " \n" +
64 | " plyr_[id].addr = msg.sender;\n" +
65 | " \n" +
66 | " // 需要先approve才能成功\n" +
67 | " Seele.transferFrom(msg.sender,this,_value);\n" +
68 | " SeeleTotal_+=_value;\n" +
69 | "\n" +
70 | " plyr_[id].keys += _value / keyprice * 10**18;\n" +
71 | " plyr_[id].aff += _value / 2;\n" +
72 | " emit log(_value,keyprice,_value / keyprice * 10**18);\n" +
73 | " }\n" +
74 | " \n" +
75 | " function withdraw()\n" +
76 | " public\n" +
77 | " payable\n" +
78 | " {\n" +
79 | " uint id = pIDxAddr_[msg.sender];\n" +
80 | " require( id > 0 );\n" +
81 | " \n" +
82 | " Seele.transfer(msg.sender, plyr_[id].aff);\n" +
83 | " SeeleTotal_ -= plyr_[id].aff;\n" +
84 | " plyr_[id].aff = 0;\n" +
85 | " plyr_[id].keys = 0;\n" +
86 | " }\n" +
87 | " \n" +
88 | " //测试分配规则 最后一个人50% 剩下的平分\n" +
89 | " function endRound()\n" +
90 | " public\n" +
91 | " payable\n" +
92 | " {\n" +
93 | " require(pID_ > 0);\n" +
94 | " if (pID_ == 1) {\n" +
95 | " Seele.transfer(plyr_[pID_].addr, SeeleTotal_);\n" +
96 | " plyr_[pID_].aff = 0;\n" +
97 | " return;\n" +
98 | " }\n" +
99 | " \n" +
100 | " address winner = plyr_[pID_].addr;\n" +
101 | " uint256 winnerReward = SeeleTotal_ / 2;\n" +
102 | " \n" +
103 | " Seele.transfer(winner, winnerReward);\n" +
104 | " \n" +
105 | " uint256 leftRewardPer = (SeeleTotal_ - winnerReward) / (pID_ - 1);\n" +
106 | " \n" +
107 | " for( uint8 i=1; i< pID_; i++ ){\n" +
108 | " Seele.transfer(plyr_[i].addr, leftRewardPer);\n" +
109 | " plyr_[i].aff = 0;\n" +
110 | " }\n" +
111 | " \n" +
112 | " SeeleTotal_ = 0;\n" +
113 | " }\n" +
114 | "}\n"
115 | }
116 | }
117 |
118 | render() {
119 | return (
120 |
127 |
128 | );
129 | }
130 | };
131 |
132 |
133 |
134 | export default connect()(GameContract);
135 |
--------------------------------------------------------------------------------
/src/services/example.js:
--------------------------------------------------------------------------------
1 | import Eth from 'ethjs-query';
2 | import EthContract from 'ethjs-contract';
3 | import tokenAbi from './contract/tokenAbi';
4 | import gameAbi from './contract/gameAbi';
5 | //import hourglassAbi from './contract/hourglassAbi';
6 |
7 | import {BigNumber} from 'bignumber.js'
8 |
9 |
10 | const { web3 } = window;
11 | var eth = new Eth(web3.currentProvider);
12 | var CoinBase = '';
13 | var tokenAddr = '0xBf10E654146ca9EA3A7B5Bf6c6cB4446688e5476';
14 | var gameAddr = '0x0Fc6eb03AC93EdaBA749EDbC87DdaBC2B221C86E';
15 | //var hourglassAddr = '0x3DD0864668C36D27B53a98137764c99F9FD5B7B2';
16 | var TokenContract;
17 | var GameContract;
18 | var hourglassContract;
19 |
20 | if (typeof web3 === 'undefined') {
21 | alert("failed to un");
22 | }
23 |
24 | function NewTokenContract() {
25 | var contract = new EthContract(eth);
26 | var tokenCtr = contract(tokenAbi);
27 | TokenContract = tokenCtr.at(tokenAddr);
28 | console.log(TokenContract);
29 | }
30 |
31 | function NewGameContract() {
32 | var contract = new EthContract(eth);
33 | var tokenCtr = contract(gameAbi);
34 | GameContract = tokenCtr.at(gameAddr);
35 | console.log(GameContract);
36 | }
37 |
38 | // function NewHourglassContract() {
39 | // var contract = new EthContract(eth);
40 | // var tokenCtr = contract(hourglassAbi);
41 | // hourglassContract = tokenCtr.at(hourglassAddr);
42 | // console.log(hourglassContract);
43 | // }
44 |
45 | NewTokenContract();
46 | NewGameContract();
47 | // NewHourglassContract();
48 |
49 | export function getCoinbase() {
50 | return new Promise(function(resolve, reject){
51 | web3.eth.getCoinbase((err, coinbase) => {
52 | if (err) {
53 | reject(err);
54 | } else {
55 | CoinBase = coinbase;
56 | resolve(coinbase);
57 | }
58 | });
59 | })
60 | }
61 |
62 | export function getBalance({coinbase}) {
63 | return new Promise(function(resolve, reject){
64 | web3.eth.getBalance(coinbase,(err, balance) => {
65 | if (err) {
66 | reject(err);
67 | } else {
68 | resolve(web3.fromWei(balance.toNumber(), "ether" ));
69 | }
70 | });
71 | })
72 | }
73 |
74 | function formatBN(bn){
75 | return new BigNumber(bn).div('1000000000000000000').toFormat(18);
76 | }
77 |
78 | export function getLeftAuthSeele() {
79 | return new Promise(function(resolve, reject){
80 | TokenContract.allowance(CoinBase,gameAddr,function(error,result){
81 | if (error) {
82 | console.log(error)
83 | reject(error);
84 | return
85 | }
86 | resolve(new BigNumber(result[0]).div('1000000000000000000').toNumber());
87 | })
88 | })
89 | }
90 |
91 | export function allocateSeele({value}) {
92 | return new Promise(function(resolve, reject){
93 | TokenContract.approve(gameAddr,new BigNumber(value).times('1000000000000000000'),{from:CoinBase},function(error,result){
94 | if (error) {
95 | console.log(error)
96 | reject(error);
97 | return
98 | }
99 | console.log(result)
100 | resolve(true);
101 | })
102 | })
103 | }
104 |
105 | export function buyKeyFromSeele({value}) {
106 | return new Promise(function(resolve, reject){
107 | GameContract.BuyKeyFromSeele(new BigNumber(value).times('1000000000000000000'),{from:CoinBase},function(error,result){
108 | if (error) {
109 | console.log(error)
110 | reject(error);
111 | return
112 | }
113 | console.log(result)
114 | resolve(true);
115 | })
116 | })
117 | }
118 |
119 | export function seeleBalance() {
120 | return new Promise(function(resolve, reject){
121 | TokenContract.balanceOf(CoinBase,function(error,result){
122 | if (error) {
123 | console.log(error)
124 | reject(error);
125 | return
126 | }
127 | resolve(new BigNumber(result[0]).div('1000000000000000000').toString())
128 | })
129 | })
130 | }
131 |
132 | export function buyseele() {
133 |
134 | }
135 |
136 | export function currentPlayer() {
137 | return new Promise(function(resolve, reject){
138 | console.log("coinbase:",CoinBase);
139 | GameContract.pIDxAddr_(CoinBase,function(error,result){
140 | if (error) {
141 | console.log(error)
142 | reject(error);
143 | return
144 | }
145 |
146 | GameContract.plyr_(result[0],function(error2,result2){
147 | if (error2) {
148 | console.log(error2)
149 | reject(error2);
150 | return
151 | }
152 | console.log(result2);
153 | resolve(new BigNumber(result2.keys).div('1000000000000000000').toNumber())
154 | })
155 | })
156 | })
157 | }
158 |
159 |
160 | //===================
161 | export function buyInICO({value}) {
162 | return new Promise(function(resolve, reject){
163 | hourglassContract.buy('0x0000000000000000000000000000000000000000',
164 | {from:CoinBase,value:new BigNumber(value).times('1000000000000000000')},
165 | function(error,result){
166 | if (error) {
167 | console.log(error)
168 | reject(error);
169 | return
170 | }
171 | resolve(result)
172 | })
173 | })
174 | }
175 |
--------------------------------------------------------------------------------
/src/services/contract/hourglassAbi.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[{"name":"_customerAddress","type":"address"}],"name":"dividendsOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"activate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_ethereumToSpend","type":"uint256"}],"name":"calculateTokensReceived","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"okamiMaxPurchase_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"activated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokensToSell","type":"uint256"}],"name":"calculateEthereumReceived","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"sellPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"endICO","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"stakingRequirement","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"okamiMinPurchase_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"tokenBalanceLedger_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"okamiCurrentPurchase_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_includeReferralBonus","type":"bool"}],"name":"myDividends","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalEthereumBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_customerAddress","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"administrators","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_amountOfTokens","type":"uint256"}],"name":"setStakingRequirement","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"buyPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_identifier","type":"address"},{"name":"_status","type":"bool"}],"name":"setAdministrator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"myTokens","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"okamiTotalPurchase_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_toAddress","type":"address"},{"name":"_amountOfTokens","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"okamiFunds_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_symbol","type":"string"}],"name":"setSymbol","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"icoPrice_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"}],"name":"setName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"referralBalance_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"payoutsTo_","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_amountOfTokens","type":"uint256"}],"name":"sell","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"exit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_referredBy","type":"address"}],"name":"buy","outputs":[{"name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"inICO","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"reinvest","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"customerAddress","type":"address"},{"indexed":false,"name":"incomingEthereum","type":"uint256"},{"indexed":false,"name":"tokensMinted","type":"uint256"},{"indexed":true,"name":"referredBy","type":"address"}],"name":"onTokenPurchase","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"customerAddress","type":"address"},{"indexed":false,"name":"tokensBurned","type":"uint256"},{"indexed":false,"name":"ethereumEarned","type":"uint256"}],"name":"onTokenSell","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"customerAddress","type":"address"},{"indexed":false,"name":"ethereumReinvested","type":"uint256"},{"indexed":false,"name":"tokensMinted","type":"uint256"}],"name":"onReinvestment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"customerAddress","type":"address"},{"indexed":false,"name":"ethereumWithdrawn","type":"uint256"}],"name":"onWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Transfer","type":"event"}]
2 |
--------------------------------------------------------------------------------
/src/components/Common.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {connect} from "dva/index";
3 | import {Button, Card, Col, Input, Radio, Row, Select, Switch} from 'antd';
4 | import {BigNumber} from 'bignumber.js'
5 |
6 | const {Option, OptGroup} = Select;
7 |
8 | var web3js = require('web3');
9 | var utils = web3js.utils;
10 |
11 | var {web3} = window;
12 |
13 | class Common extends React.Component {
14 | constructor(props) {
15 | super(props)
16 | this.state = {
17 | address: "0x",
18 | searching: false,
19 | fn: {},
20 | fnname: [],
21 | req: {},
22 | reqvalue: 0,
23 | resultswitch: false
24 | }
25 | }
26 |
27 | componentDidMount() {
28 | this.props.dispatch({
29 | type: 'common/reloadinfo',
30 | });
31 | }
32 |
33 | getContract = () => {
34 | this.props.dispatch({
35 | type: 'common/getCtract',
36 | payload: {address: this.state.address},
37 | });
38 | };
39 |
40 | onAddressChange = (e) => {
41 | this.setState({
42 | address: e.target.value,
43 | })
44 | };
45 |
46 | onRequestChange = (e) => {
47 | var req = this.state.req;
48 | req[e.target.id] = e.target.value;
49 | this.setState({
50 | req: req
51 | })
52 | };
53 |
54 | onRequestValueChange = (e) => {
55 | this.setState({
56 | reqvalue: +e.target.value
57 | })
58 | };
59 |
60 | onSwitchChange = (checked) => {
61 | //console.log(`switch to ${checked}`);
62 | this.setState({
63 | resultswitch: checked
64 | })
65 | }
66 |
67 | parseReq = () => {
68 | var value = [];
69 | for (var index in this.state.fn.inputs) {
70 | var item = this.state.fn.inputs[index];
71 | var it = this.state.req[item.name];
72 |
73 | if (item.name == "") {
74 | it = index + "";
75 | }
76 | if (item.type.indexOf("uint") >= 0) {
77 | value.push(+it || 0);
78 | continue;
79 | }
80 | if (item.type == "bool") {
81 | value.push(it == "true");
82 | continue;
83 | }
84 |
85 | if (item.type == "string") {
86 | value.push(it || "");
87 | continue;
88 | }
89 |
90 | if (item.type == "address") {
91 | var addr = it || "0x0000000000000000000000000000000000000000";
92 | value.push(it);
93 | continue;
94 | }
95 |
96 | if (item.type.indexOf("bytes") >= 0) {
97 | var b = web3.fromAscii(it || "", 32);
98 | value.push(b);
99 | continue;
100 | }
101 |
102 | alert("unknown type ", item.type, it);
103 | }
104 | return value;
105 | }
106 |
107 | getValue = () => {
108 | var value = this.parseReq()
109 | console.log("request:", value);
110 |
111 | var pay = this.state.reqvalue;
112 | if (!this.state.fn.payable) {
113 | pay = 0;
114 | }
115 |
116 | this.props.dispatch({
117 | type: 'common/callingfunc',
118 | payload: {ctr: this.state.address, func: this.state.fn.name, value, pay},
119 | });
120 | };
121 |
122 | handleSelectChange = (value) => {
123 | if (value.length == 0) {
124 | return
125 | }
126 | if (value.length == 1) {
127 | value = value[0];
128 | } else {
129 | value = value[1];
130 | }
131 |
132 | for (var index in this.props.abi) {
133 | if (value == this.props.abi[index].name) {
134 | this.setState({
135 | fn: this.props.abi[index],
136 | fnname: [value],
137 | req: {}
138 | })
139 | }
140 | }
141 | }
142 |
143 | handleNetChange = (e) => {
144 | console.log("value:", e.target.value);
145 |
146 | this.props.dispatch({
147 | type: 'common/changenetwork',
148 | payload: {network:e.target.value},
149 | });
150 | }
151 |
152 | //=======================================
153 | render() {
154 | const children = [];
155 | const requestparam = [];
156 | const resultparam = [];
157 | var tip = "加载中"
158 | for (var index in this.props.contract.abi) {
159 | var item = this.props.contract.abi[index];
160 | if (item.name && item.name != "") {
161 | children.push();
162 | var tip = "加载成功"
163 | }
164 | }
165 | if (children.length == 0) {
166 | tip = "无数据"
167 | }
168 |
169 | var details = "";
170 | if (this.state.fn.name) {
171 | details = "类型" + this.state.fn.stateMutability + " |常量 " + this.state.fn.constant + " | 方法 " + this.state.fn.name + " | payable " + this.state.fn.payable;
172 | }
173 |
174 | for (var index in this.state.fn.inputs) {
175 | var item = this.state.fn.inputs[index];
176 | var title = item.name + ' (' + item.type + ')';
177 | if (item.name == "") {
178 | item.name = index;
179 | }
180 | switch (item.type) {
181 | case "string":
182 | requestparam.push(
183 |
185 | );
186 | break;
187 | case "address":
188 | requestparam.push(
189 |
191 | );
192 | break;
193 | case "bool":
194 | requestparam.push(
195 |
197 | );
198 | break;
199 | default:
200 | if (item.type.indexOf("uint") >= 0) {
201 | requestparam.push(
202 |
204 | );
205 | break;
206 | }
207 | if (item.type.indexOf("bytes") >= 0) {
208 | requestparam.push(
209 |
211 | );
212 | break;
213 | }
214 | requestparam.push(
215 |
217 | );
218 | }
219 | }
220 |
221 | function fromBigNumber(value) {
222 | return new BigNumber(value).div('1000000000000000000').toString()
223 | }
224 |
225 |
226 | for (var index in this.props.result) {
227 | if (!this.state.fn.outputs[index]) {
228 | break;
229 | }
230 | var item = this.state.fn.outputs[index];
231 | var res = this.props.result;
232 | if (item.name == "") {
233 | item.name = index;
234 | }
235 | switch (item.type) {
236 | case "string":
237 | resultparam.push(
238 | {item.name + " : " + res[index]}
239 | );
240 | break;
241 | case "address":
242 | resultparam.push(
243 | {item.name + " : " + res[index]}
244 | );
245 | break;
246 | case "bool":
247 | resultparam.push(
248 | {item.name + " : " + res[index]}
249 | );
250 | break;
251 | default:
252 | if (item.type.indexOf("uint") >= 0) {
253 | if (this.state.resultswitch) {
254 | resultparam.push(
255 | {item.name + " : " + fromBigNumber(res[index])}
256 | );
257 | break;
258 | }
259 | resultparam.push(
260 | {item.name + " : " + new BigNumber(res[index]).toString()}
261 | );
262 | break;
263 | }
264 | if (item.type.indexOf("bytes") >= 0) {
265 | resultparam.push(
266 | {item.name + " : " + web3.toAscii(res[index])}
267 | );
268 | break;
269 | }
270 | resultparam.push(
271 | {item.name + " : " + res[index]}
272 | );
273 | }
274 |
275 | }
276 |
277 |
278 | var showres = [];
279 | showres.push(
280 |
281 | {"结果显示"}
282 |
283 | );
284 |
285 | return (
286 |
287 |
288 |
289 | {this.props.address}
290 |
291 |
292 | {this.props.balance}
293 |
294 |
295 | ..
296 |
297 |
298 |
299 | {'合约地址 network:'}
300 |
301 | Main
302 | Kovan
303 |
304 |
} bordered={false}>
305 |
306 |
307 |
308 |
309 |
310 |
311 | ,
321 |
322 |
323 |
324 | ..
325 |
326 |
327 |
328 | {details}
329 |
330 | {requestparam}
331 |
332 |
334 |
335 |
336 |
337 |
338 |
339 |
340 | {resultparam}
341 |
342 |
343 |
344 |
345 | );
346 | }
347 | };
348 |
349 |
350 | function mapStateToProps(state) {
351 | const {address, balance, contract, abi, result, network} = state.common;
352 | return {
353 | address, balance, contract, abi, result, network
354 | };
355 | }
356 |
357 | export default connect(mapStateToProps)(Common);
358 |
--------------------------------------------------------------------------------
/src/services/contract/pklongAbi.json:
--------------------------------------------------------------------------------
1 | [{"constant":true,"inputs":[],"name":"getBuyPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint8"}],"name":"levelRate_","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_affCode","type":"bytes32"},{"name":"_team","type":"uint256"},{"name":"_eth","type":"uint256"}],"name":"reLoadXname","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"activate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"pIDxAddr_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"airDropTracker_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_pID","type":"uint256"},{"name":"_addr","type":"address"},{"name":"_name","type":"bytes32"},{"name":"_laff","type":"uint256"},{"name":"_level","type":"uint8"}],"name":"receivePlayerInfo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"round_","outputs":[{"name":"plyr","type":"uint256"},{"name":"team","type":"uint256"},{"name":"end","type":"uint256"},{"name":"ended","type":"bool"},{"name":"strt","type":"uint256"},{"name":"keys","type":"uint256"},{"name":"eth","type":"uint256"},{"name":"pot","type":"uint256"},{"name":"mask","type":"uint256"},{"name":"ico","type":"uint256"},{"name":"icoGen","type":"uint256"},{"name":"icoAvg","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"bytes32"}],"name":"plyrNames_","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint8"}],"name":"levelValue_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"fees_","outputs":[{"name":"gen","type":"uint256"},{"name":"opk","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"pIDxName_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"rndTmEth_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rID_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_pID","type":"uint256"}],"name":"getPlayerVaults","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getCurrentRoundInfo","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"address"},{"name":"","type":"bytes32"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_nameString","type":"string"},{"name":"_affCode","type":"bytes32"},{"name":"_all","type":"bool"},{"name":"_level","type":"uint8"}],"name":"registerNameXname","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_pID","type":"uint256"},{"name":"_name","type":"bytes32"}],"name":"receivePlayerNameList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_rID","type":"uint256"}],"name":"isRoundActive","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_fromName","type":"string"}],"name":"validateName","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"plyrRnds_","outputs":[{"name":"eth","type":"uint256"},{"name":"keys","type":"uint256"},{"name":"mask","type":"uint256"},{"name":"ico","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_fromName","type":"string"}],"name":"getBytesName","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"_affCode","type":"bytes32"},{"name":"_team","type":"uint256"}],"name":"buyXname","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_otherOPK","type":"address"}],"name":"setOtherFomo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"potSplit_","outputs":[{"name":"gen","type":"uint256"},{"name":"opk","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getTimeLeft","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_rID","type":"uint256"},{"name":"_eth","type":"uint256"}],"name":"calcKeysReceived","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_keys","type":"uint256"}],"name":"iWantXKeys","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"activated_","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"airDropPot_","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"plyr_","outputs":[{"name":"addr","type":"address"},{"name":"name","type":"bytes32"},{"name":"win","type":"uint256"},{"name":"gen","type":"uint256"},{"name":"aff","type":"uint256"},{"name":"lrnd","type":"uint256"},{"name":"laff","type":"uint256"},{"name":"level","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"potSwap","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"getPlayerInfoByAddress","outputs":[{"name":"","type":"uint256"},{"name":"","type":"bytes32"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint8"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint8"}],"name":"levelRate2_","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"playerID","type":"uint256"},{"indexed":true,"name":"playerAddress","type":"address"},{"indexed":true,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"isNewPlayer","type":"bool"},{"indexed":false,"name":"affiliateID","type":"uint256"},{"indexed":false,"name":"affiliateAddress","type":"address"},{"indexed":false,"name":"affiliateName","type":"bytes32"},{"indexed":false,"name":"amountPaid","type":"uint256"},{"indexed":false,"name":"timeStamp","type":"uint256"}],"name":"onNewName","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"compressedData","type":"uint256"},{"indexed":false,"name":"compressedIDs","type":"uint256"},{"indexed":false,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"playerAddress","type":"address"},{"indexed":false,"name":"ethIn","type":"uint256"},{"indexed":false,"name":"keysBought","type":"uint256"},{"indexed":false,"name":"winnerAddr","type":"address"},{"indexed":false,"name":"winnerName","type":"bytes32"},{"indexed":false,"name":"amountWon","type":"uint256"},{"indexed":false,"name":"newPot","type":"uint256"},{"indexed":false,"name":"OPKAmount","type":"uint256"},{"indexed":false,"name":"genAmount","type":"uint256"},{"indexed":false,"name":"potAmount","type":"uint256"},{"indexed":false,"name":"airDropPot","type":"uint256"}],"name":"onEndTx","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"playerID","type":"uint256"},{"indexed":false,"name":"playerAddress","type":"address"},{"indexed":false,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"ethOut","type":"uint256"},{"indexed":false,"name":"timeStamp","type":"uint256"}],"name":"onWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"playerAddress","type":"address"},{"indexed":false,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"ethOut","type":"uint256"},{"indexed":false,"name":"compressedData","type":"uint256"},{"indexed":false,"name":"compressedIDs","type":"uint256"},{"indexed":false,"name":"winnerAddr","type":"address"},{"indexed":false,"name":"winnerName","type":"bytes32"},{"indexed":false,"name":"amountWon","type":"uint256"},{"indexed":false,"name":"newPot","type":"uint256"},{"indexed":false,"name":"OPKAmount","type":"uint256"},{"indexed":false,"name":"genAmount","type":"uint256"}],"name":"onWithdrawAndDistribute","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"playerAddress","type":"address"},{"indexed":false,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"ethIn","type":"uint256"},{"indexed":false,"name":"compressedData","type":"uint256"},{"indexed":false,"name":"compressedIDs","type":"uint256"},{"indexed":false,"name":"winnerAddr","type":"address"},{"indexed":false,"name":"winnerName","type":"bytes32"},{"indexed":false,"name":"amountWon","type":"uint256"},{"indexed":false,"name":"newPot","type":"uint256"},{"indexed":false,"name":"OPKAmount","type":"uint256"},{"indexed":false,"name":"genAmount","type":"uint256"}],"name":"onBuyAndDistribute","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"playerAddress","type":"address"},{"indexed":false,"name":"playerName","type":"bytes32"},{"indexed":false,"name":"compressedData","type":"uint256"},{"indexed":false,"name":"compressedIDs","type":"uint256"},{"indexed":false,"name":"winnerAddr","type":"address"},{"indexed":false,"name":"winnerName","type":"bytes32"},{"indexed":false,"name":"amountWon","type":"uint256"},{"indexed":false,"name":"newPot","type":"uint256"},{"indexed":false,"name":"OPKAmount","type":"uint256"},{"indexed":false,"name":"genAmount","type":"uint256"}],"name":"onReLoadAndDistribute","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"affiliateID","type":"uint256"},{"indexed":false,"name":"affiliateAddress","type":"address"},{"indexed":false,"name":"affiliateName","type":"bytes32"},{"indexed":true,"name":"roundID","type":"uint256"},{"indexed":true,"name":"buyerID","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"level","type":"uint8"},{"indexed":false,"name":"timeStamp","type":"uint256"}],"name":"onAffiliatePayout","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"from","type":"uint256"},{"indexed":false,"name":"from_addr","type":"address"},{"indexed":false,"name":"to","type":"uint256"},{"indexed":false,"name":"to_addr","type":"address"},{"indexed":false,"name":"level","type":"uint8"},{"indexed":false,"name":"fee","type":"uint256"},{"indexed":false,"name":"timeStamp","type":"uint256"}],"name":"onAffiliateDistribute","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"pID","type":"uint256"},{"indexed":false,"name":"leftfee","type":"uint256"}],"name":"onAffiliateDistributeLeft","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"roundID","type":"uint256"},{"indexed":false,"name":"amountAddedToPot","type":"uint256"}],"name":"onPotSwapDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"affiliateID","type":"uint256"},{"indexed":false,"name":"name","type":"bytes32"},{"indexed":false,"name":"level","type":"uint8"},{"indexed":false,"name":"fee","type":"uint256"},{"indexed":false,"name":"communityFee","type":"uint256"},{"indexed":false,"name":"opkFee","type":"uint256"},{"indexed":false,"name":"refererFee","type":"uint256"},{"indexed":false,"name":"referPotFee","type":"uint256"}],"name":"onDistributeRegisterFee","type":"event"}]
--------------------------------------------------------------------------------
/contracts/token.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.24;
2 |
3 | // File: contracts/zeppelin-solidity/contracts/ownership/Ownable.sol
4 |
5 | /**
6 | * @title Ownable
7 | * @dev The Ownable contract has an owner address, and provides basic authorization control
8 | * functions, this simplifies the implementation of "user permissions".
9 | */
10 | contract Ownable {
11 | address public owner;
12 |
13 |
14 | event OwnershipRenounced(address indexed previousOwner);
15 | event OwnershipTransferred(
16 | address indexed previousOwner,
17 | address indexed newOwner
18 | );
19 |
20 |
21 | /**
22 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender
23 | * account.
24 | */
25 | constructor() public {
26 | owner = msg.sender;
27 | }
28 |
29 | /**
30 | * @dev Throws if called by any account other than the owner.
31 | */
32 | modifier onlyOwner() {
33 | require(msg.sender == owner);
34 | _;
35 | }
36 |
37 | /**
38 | * @dev Allows the current owner to relinquish control of the contract.
39 | * @notice Renouncing to ownership will leave the contract without an owner.
40 | * It will not be possible to call the functions with the `onlyOwner`
41 | * modifier anymore.
42 | */
43 | function renounceOwnership() public onlyOwner {
44 | emit OwnershipRenounced(owner);
45 | owner = address(0);
46 | }
47 |
48 | /**
49 | * @dev Allows the current owner to transfer control of the contract to a newOwner.
50 | * @param _newOwner The address to transfer ownership to.
51 | */
52 | function transferOwnership(address _newOwner) public onlyOwner {
53 | _transferOwnership(_newOwner);
54 | }
55 |
56 | /**
57 | * @dev Transfers control of the contract to a newOwner.
58 | * @param _newOwner The address to transfer ownership to.
59 | */
60 | function _transferOwnership(address _newOwner) internal {
61 | require(_newOwner != address(0));
62 | emit OwnershipTransferred(owner, _newOwner);
63 | owner = _newOwner;
64 | }
65 | }
66 |
67 | // File: contracts/zeppelin-solidity/contracts/lifecycle/Pausable.sol
68 |
69 | /**
70 | * @title Pausable
71 | * @dev Base contract which allows children to implement an emergency stop mechanism.
72 | */
73 | contract Pausable is Ownable {
74 | event Pause();
75 | event Unpause();
76 |
77 | bool public paused = false;
78 |
79 |
80 | /**
81 | * @dev Modifier to make a function callable only when the contract is not paused.
82 | */
83 | modifier whenNotPaused() {
84 | require(!paused);
85 | _;
86 | }
87 |
88 | /**
89 | * @dev Modifier to make a function callable only when the contract is paused.
90 | */
91 | modifier whenPaused() {
92 | require(paused);
93 | _;
94 | }
95 |
96 | /**
97 | * @dev called by the owner to pause, triggers stopped state
98 | */
99 | function pause() public onlyOwner whenNotPaused {
100 | paused = true;
101 | emit Pause();
102 | }
103 |
104 | /**
105 | * @dev called by the owner to unpause, returns to normal state
106 | */
107 | function unpause() public onlyOwner whenPaused {
108 | paused = false;
109 | emit Unpause();
110 | }
111 | }
112 |
113 | // File: contracts/zeppelin-solidity/contracts/math/SafeMath.sol
114 |
115 | /**
116 | * @title SafeMath
117 | * @dev Math operations with safety checks that throw on error
118 | */
119 | library SafeMath {
120 |
121 | /**
122 | * @dev Multiplies two numbers, throws on overflow.
123 | */
124 | function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
125 | // Gas optimization: this is cheaper than asserting 'a' not being zero, but the
126 | // benefit is lost if 'b' is also tested.
127 | // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
128 | if (_a == 0) {
129 | return 0;
130 | }
131 |
132 | c = _a * _b;
133 | assert(c / _a == _b);
134 | return c;
135 | }
136 |
137 | /**
138 | * @dev Integer division of two numbers, truncating the quotient.
139 | */
140 | function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
141 | // assert(_b > 0); // Solidity automatically throws when dividing by 0
142 | // uint256 c = _a / _b;
143 | // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
144 | return _a / _b;
145 | }
146 |
147 | /**
148 | * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
149 | */
150 | function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
151 | assert(_b <= _a);
152 | return _a - _b;
153 | }
154 |
155 | /**
156 | * @dev Adds two numbers, throws on overflow.
157 | */
158 | function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
159 | c = _a + _b;
160 | assert(c >= _a);
161 | return c;
162 | }
163 | }
164 |
165 | // File: contracts/zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
166 |
167 | /**
168 | * @title ERC20Basic
169 | * @dev Simpler version of ERC20 interface
170 | * See https://github.com/ethereum/EIPs/issues/179
171 | */
172 | contract ERC20Basic {
173 | function totalSupply() public view returns (uint256);
174 | function balanceOf(address _who) public view returns (uint256);
175 | function transfer(address _to, uint256 _value) public returns (bool);
176 | event Transfer(address indexed from, address indexed to, uint256 value);
177 | }
178 |
179 | // File: contracts/zeppelin-solidity/contracts/token/ERC20/BasicToken.sol
180 |
181 | /**
182 | * @title Basic token
183 | * @dev Basic version of StandardToken, with no allowances.
184 | */
185 | contract BasicToken is ERC20Basic {
186 | using SafeMath for uint256;
187 |
188 | mapping(address => uint256) internal balances;
189 |
190 | uint256 internal totalSupply_;
191 |
192 | /**
193 | * @dev Total number of tokens in existence
194 | */
195 | function totalSupply() public view returns (uint256) {
196 | return totalSupply_;
197 | }
198 |
199 | /**
200 | * @dev Transfer token for a specified address
201 | * @param _to The address to transfer to.
202 | * @param _value The amount to be transferred.
203 | */
204 | function transfer(address _to, uint256 _value) public returns (bool) {
205 | require(_value <= balances[msg.sender]);
206 | require(_to != address(0));
207 |
208 | balances[msg.sender] = balances[msg.sender].sub(_value);
209 | balances[_to] = balances[_to].add(_value);
210 | emit Transfer(msg.sender, _to, _value);
211 | return true;
212 | }
213 |
214 | /**
215 | * @dev Gets the balance of the specified address.
216 | * @param _owner The address to query the the balance of.
217 | * @return An uint256 representing the amount owned by the passed address.
218 | */
219 | function balanceOf(address _owner) public view returns (uint256) {
220 | return balances[_owner];
221 | }
222 |
223 | }
224 |
225 | // File: contracts/zeppelin-solidity/contracts/token/ERC20/ERC20.sol
226 |
227 | /**
228 | * @title ERC20 interface
229 | * @dev see https://github.com/ethereum/EIPs/issues/20
230 | */
231 | contract ERC20 is ERC20Basic {
232 | function allowance(address _owner, address _spender)
233 | public view returns (uint256);
234 |
235 | function transferFrom(address _from, address _to, uint256 _value)
236 | public returns (bool);
237 |
238 | function approve(address _spender, uint256 _value) public returns (bool);
239 | event Approval(
240 | address indexed owner,
241 | address indexed spender,
242 | uint256 value
243 | );
244 | }
245 |
246 | // File: contracts/zeppelin-solidity/contracts/token/ERC20/StandardToken.sol
247 |
248 | /**
249 | * @title Standard ERC20 token
250 | *
251 | * @dev Implementation of the basic standard token.
252 | * https://github.com/ethereum/EIPs/issues/20
253 | * Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
254 | */
255 | contract StandardToken is ERC20, BasicToken {
256 |
257 | mapping (address => mapping (address => uint256)) internal allowed;
258 |
259 |
260 | /**
261 | * @dev Transfer tokens from one address to another
262 | * @param _from address The address which you want to send tokens from
263 | * @param _to address The address which you want to transfer to
264 | * @param _value uint256 the amount of tokens to be transferred
265 | */
266 | function transferFrom(
267 | address _from,
268 | address _to,
269 | uint256 _value
270 | )
271 | public
272 | returns (bool)
273 | {
274 | require(_value <= balances[_from]);
275 | require(_value <= allowed[_from][msg.sender]);
276 | require(_to != address(0));
277 |
278 | balances[_from] = balances[_from].sub(_value);
279 | balances[_to] = balances[_to].add(_value);
280 | allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
281 | emit Transfer(_from, _to, _value);
282 | return true;
283 | }
284 |
285 | /**
286 | * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
287 | * Beware that changing an allowance with this method brings the risk that someone may use both the old
288 | * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
289 | * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
290 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
291 | * @param _spender The address which will spend the funds.
292 | * @param _value The amount of tokens to be spent.
293 | */
294 | function approve(address _spender, uint256 _value) public returns (bool) {
295 | allowed[msg.sender][_spender] = _value;
296 | emit Approval(msg.sender, _spender, _value);
297 | return true;
298 | }
299 |
300 | /**
301 | * @dev Function to check the amount of tokens that an owner allowed to a spender.
302 | * @param _owner address The address which owns the funds.
303 | * @param _spender address The address which will spend the funds.
304 | * @return A uint256 specifying the amount of tokens still available for the spender.
305 | */
306 | function allowance(
307 | address _owner,
308 | address _spender
309 | )
310 | public
311 | view
312 | returns (uint256)
313 | {
314 | return allowed[_owner][_spender];
315 | }
316 |
317 | /**
318 | * @dev Increase the amount of tokens that an owner allowed to a spender.
319 | * approve should be called when allowed[_spender] == 0. To increment
320 | * allowed value is better to use this function to avoid 2 calls (and wait until
321 | * the first transaction is mined)
322 | * From MonolithDAO Token.sol
323 | * @param _spender The address which will spend the funds.
324 | * @param _addedValue The amount of tokens to increase the allowance by.
325 | */
326 | function increaseApproval(
327 | address _spender,
328 | uint256 _addedValue
329 | )
330 | public
331 | returns (bool)
332 | {
333 | allowed[msg.sender][_spender] = (
334 | allowed[msg.sender][_spender].add(_addedValue));
335 | emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
336 | return true;
337 | }
338 |
339 | /**
340 | * @dev Decrease the amount of tokens that an owner allowed to a spender.
341 | * approve should be called when allowed[_spender] == 0. To decrement
342 | * allowed value is better to use this function to avoid 2 calls (and wait until
343 | * the first transaction is mined)
344 | * From MonolithDAO Token.sol
345 | * @param _spender The address which will spend the funds.
346 | * @param _subtractedValue The amount of tokens to decrease the allowance by.
347 | */
348 | function decreaseApproval(
349 | address _spender,
350 | uint256 _subtractedValue
351 | )
352 | public
353 | returns (bool)
354 | {
355 | uint256 oldValue = allowed[msg.sender][_spender];
356 | if (_subtractedValue >= oldValue) {
357 | allowed[msg.sender][_spender] = 0;
358 | } else {
359 | allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
360 | }
361 | emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
362 | return true;
363 | }
364 |
365 | }
366 |
367 | // File: contracts/zeppelin-solidity/contracts/token/ERC20/PausableToken.sol
368 |
369 | /**
370 | * @title Pausable token
371 | * @dev StandardToken modified with pausable transfers.
372 | **/
373 | contract PausableToken is StandardToken, Pausable {
374 |
375 | function transfer(
376 | address _to,
377 | uint256 _value
378 | )
379 | public
380 | whenNotPaused
381 | returns (bool)
382 | {
383 | return super.transfer(_to, _value);
384 | }
385 |
386 | function transferFrom(
387 | address _from,
388 | address _to,
389 | uint256 _value
390 | )
391 | public
392 | whenNotPaused
393 | returns (bool)
394 | {
395 | return super.transferFrom(_from, _to, _value);
396 | }
397 |
398 | function approve(
399 | address _spender,
400 | uint256 _value
401 | )
402 | public
403 | whenNotPaused
404 | returns (bool)
405 | {
406 | return super.approve(_spender, _value);
407 | }
408 |
409 | function increaseApproval(
410 | address _spender,
411 | uint _addedValue
412 | )
413 | public
414 | whenNotPaused
415 | returns (bool success)
416 | {
417 | return super.increaseApproval(_spender, _addedValue);
418 | }
419 |
420 | function decreaseApproval(
421 | address _spender,
422 | uint _subtractedValue
423 | )
424 | public
425 | whenNotPaused
426 | returns (bool success)
427 | {
428 | return super.decreaseApproval(_spender, _subtractedValue);
429 | }
430 | }
431 |
432 | // File: contracts/TestToken.sol
433 |
434 | /// @author reedhong
435 | contract TestToken is PausableToken {
436 | using SafeMath for uint;
437 |
438 | /// Constant token specific fields
439 | string public constant name = "TestToken";
440 | string public constant symbol = "Cows";
441 | uint public constant decimals = 18;
442 |
443 | constructor()
444 | public
445 | {
446 | totalSupply_ = 100000000 ether;
447 | paused = false;
448 | balances[0xc0be69a5a0c1dce0d98649532f27cd3824f6061f] = totalSupply_;
449 | }
450 | }
451 |
--------------------------------------------------------------------------------
/src/components/TokenContract.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {connect} from "dva/index";
3 | import MonacoEditor from 'react-monaco-editor';
4 |
5 | class TokenContract extends React.Component {
6 | constructor(props) {
7 | super(props)
8 | this.state = {
9 | code:"pragma solidity ^0.4.24;\n" +
10 | "\n" +
11 | "// File: contracts/zeppelin-solidity/contracts/ownership/Ownable.sol\n" +
12 | "\n" +
13 | "/**\n" +
14 | " * @title Ownable\n" +
15 | " * @dev The Ownable contract has an owner address, and provides basic authorization control\n" +
16 | " * functions, this simplifies the implementation of \"user permissions\".\n" +
17 | " */\n" +
18 | "contract Ownable {\n" +
19 | " address public owner;\n" +
20 | "\n" +
21 | "\n" +
22 | " event OwnershipRenounced(address indexed previousOwner);\n" +
23 | " event OwnershipTransferred(\n" +
24 | " address indexed previousOwner,\n" +
25 | " address indexed newOwner\n" +
26 | " );\n" +
27 | "\n" +
28 | "\n" +
29 | " /**\n" +
30 | " * @dev The Ownable constructor sets the original `owner` of the contract to the sender\n" +
31 | " * account.\n" +
32 | " */\n" +
33 | " constructor() public {\n" +
34 | " owner = msg.sender;\n" +
35 | " }\n" +
36 | "\n" +
37 | " /**\n" +
38 | " * @dev Throws if called by any account other than the owner.\n" +
39 | " */\n" +
40 | " modifier onlyOwner() {\n" +
41 | " require(msg.sender == owner);\n" +
42 | " _;\n" +
43 | " }\n" +
44 | "\n" +
45 | " /**\n" +
46 | " * @dev Allows the current owner to relinquish control of the contract.\n" +
47 | " * @notice Renouncing to ownership will leave the contract without an owner.\n" +
48 | " * It will not be possible to call the functions with the `onlyOwner`\n" +
49 | " * modifier anymore.\n" +
50 | " */\n" +
51 | " function renounceOwnership() public onlyOwner {\n" +
52 | " emit OwnershipRenounced(owner);\n" +
53 | " owner = address(0);\n" +
54 | " }\n" +
55 | "\n" +
56 | " /**\n" +
57 | " * @dev Allows the current owner to transfer control of the contract to a newOwner.\n" +
58 | " * @param _newOwner The address to transfer ownership to.\n" +
59 | " */\n" +
60 | " function transferOwnership(address _newOwner) public onlyOwner {\n" +
61 | " _transferOwnership(_newOwner);\n" +
62 | " }\n" +
63 | "\n" +
64 | " /**\n" +
65 | " * @dev Transfers control of the contract to a newOwner.\n" +
66 | " * @param _newOwner The address to transfer ownership to.\n" +
67 | " */\n" +
68 | " function _transferOwnership(address _newOwner) internal {\n" +
69 | " require(_newOwner != address(0));\n" +
70 | " emit OwnershipTransferred(owner, _newOwner);\n" +
71 | " owner = _newOwner;\n" +
72 | " }\n" +
73 | "}\n" +
74 | "\n" +
75 | "// File: contracts/zeppelin-solidity/contracts/lifecycle/Pausable.sol\n" +
76 | "\n" +
77 | "/**\n" +
78 | " * @title Pausable\n" +
79 | " * @dev Base contract which allows children to implement an emergency stop mechanism.\n" +
80 | " */\n" +
81 | "contract Pausable is Ownable {\n" +
82 | " event Pause();\n" +
83 | " event Unpause();\n" +
84 | "\n" +
85 | " bool public paused = false;\n" +
86 | "\n" +
87 | "\n" +
88 | " /**\n" +
89 | " * @dev Modifier to make a function callable only when the contract is not paused.\n" +
90 | " */\n" +
91 | " modifier whenNotPaused() {\n" +
92 | " require(!paused);\n" +
93 | " _;\n" +
94 | " }\n" +
95 | "\n" +
96 | " /**\n" +
97 | " * @dev Modifier to make a function callable only when the contract is paused.\n" +
98 | " */\n" +
99 | " modifier whenPaused() {\n" +
100 | " require(paused);\n" +
101 | " _;\n" +
102 | " }\n" +
103 | "\n" +
104 | " /**\n" +
105 | " * @dev called by the owner to pause, triggers stopped state\n" +
106 | " */\n" +
107 | " function pause() public onlyOwner whenNotPaused {\n" +
108 | " paused = true;\n" +
109 | " emit Pause();\n" +
110 | " }\n" +
111 | "\n" +
112 | " /**\n" +
113 | " * @dev called by the owner to unpause, returns to normal state\n" +
114 | " */\n" +
115 | " function unpause() public onlyOwner whenPaused {\n" +
116 | " paused = false;\n" +
117 | " emit Unpause();\n" +
118 | " }\n" +
119 | "}\n" +
120 | "\n" +
121 | "// File: contracts/zeppelin-solidity/contracts/math/SafeMath.sol\n" +
122 | "\n" +
123 | "/**\n" +
124 | " * @title SafeMath\n" +
125 | " * @dev Math operations with safety checks that throw on error\n" +
126 | " */\n" +
127 | "library SafeMath {\n" +
128 | "\n" +
129 | " /**\n" +
130 | " * @dev Multiplies two numbers, throws on overflow.\n" +
131 | " */\n" +
132 | " function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n" +
133 | " // Gas optimization: this is cheaper than asserting 'a' not being zero, but the\n" +
134 | " // benefit is lost if 'b' is also tested.\n" +
135 | " // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n" +
136 | " if (_a == 0) {\n" +
137 | " return 0;\n" +
138 | " }\n" +
139 | "\n" +
140 | " c = _a * _b;\n" +
141 | " assert(c / _a == _b);\n" +
142 | " return c;\n" +
143 | " }\n" +
144 | "\n" +
145 | " /**\n" +
146 | " * @dev Integer division of two numbers, truncating the quotient.\n" +
147 | " */\n" +
148 | " function div(uint256 _a, uint256 _b) internal pure returns (uint256) {\n" +
149 | " // assert(_b > 0); // Solidity automatically throws when dividing by 0\n" +
150 | " // uint256 c = _a / _b;\n" +
151 | " // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold\n" +
152 | " return _a / _b;\n" +
153 | " }\n" +
154 | "\n" +
155 | " /**\n" +
156 | " * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).\n" +
157 | " */\n" +
158 | " function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {\n" +
159 | " assert(_b <= _a);\n" +
160 | " return _a - _b;\n" +
161 | " }\n" +
162 | "\n" +
163 | " /**\n" +
164 | " * @dev Adds two numbers, throws on overflow.\n" +
165 | " */\n" +
166 | " function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {\n" +
167 | " c = _a + _b;\n" +
168 | " assert(c >= _a);\n" +
169 | " return c;\n" +
170 | " }\n" +
171 | "}\n" +
172 | "\n" +
173 | "// File: contracts/zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol\n" +
174 | "\n" +
175 | "/**\n" +
176 | " * @title ERC20Basic\n" +
177 | " * @dev Simpler version of ERC20 interface\n" +
178 | " * See https://github.com/ethereum/EIPs/issues/179\n" +
179 | " */\n" +
180 | "contract ERC20Basic {\n" +
181 | " function totalSupply() public view returns (uint256);\n" +
182 | " function balanceOf(address _who) public view returns (uint256);\n" +
183 | " function transfer(address _to, uint256 _value) public returns (bool);\n" +
184 | " event Transfer(address indexed from, address indexed to, uint256 value);\n" +
185 | "}\n" +
186 | "\n" +
187 | "// File: contracts/zeppelin-solidity/contracts/token/ERC20/BasicToken.sol\n" +
188 | "\n" +
189 | "/**\n" +
190 | " * @title Basic token\n" +
191 | " * @dev Basic version of StandardToken, with no allowances.\n" +
192 | " */\n" +
193 | "contract BasicToken is ERC20Basic {\n" +
194 | " using SafeMath for uint256;\n" +
195 | "\n" +
196 | " mapping(address => uint256) internal balances;\n" +
197 | "\n" +
198 | " uint256 internal totalSupply_;\n" +
199 | "\n" +
200 | " /**\n" +
201 | " * @dev Total number of tokens in existence\n" +
202 | " */\n" +
203 | " function totalSupply() public view returns (uint256) {\n" +
204 | " return totalSupply_;\n" +
205 | " }\n" +
206 | "\n" +
207 | " /**\n" +
208 | " * @dev Transfer token for a specified address\n" +
209 | " * @param _to The address to transfer to.\n" +
210 | " * @param _value The amount to be transferred.\n" +
211 | " */\n" +
212 | " function transfer(address _to, uint256 _value) public returns (bool) {\n" +
213 | " require(_value <= balances[msg.sender]);\n" +
214 | " require(_to != address(0));\n" +
215 | "\n" +
216 | " balances[msg.sender] = balances[msg.sender].sub(_value);\n" +
217 | " balances[_to] = balances[_to].add(_value);\n" +
218 | " emit Transfer(msg.sender, _to, _value);\n" +
219 | " return true;\n" +
220 | " }\n" +
221 | "\n" +
222 | " /**\n" +
223 | " * @dev Gets the balance of the specified address.\n" +
224 | " * @param _owner The address to query the the balance of.\n" +
225 | " * @return An uint256 representing the amount owned by the passed address.\n" +
226 | " */\n" +
227 | " function balanceOf(address _owner) public view returns (uint256) {\n" +
228 | " return balances[_owner];\n" +
229 | " }\n" +
230 | "\n" +
231 | "}\n" +
232 | "\n" +
233 | "// File: contracts/zeppelin-solidity/contracts/token/ERC20/ERC20.sol\n" +
234 | "\n" +
235 | "/**\n" +
236 | " * @title ERC20 interface\n" +
237 | " * @dev see https://github.com/ethereum/EIPs/issues/20\n" +
238 | " */\n" +
239 | "contract ERC20 is ERC20Basic {\n" +
240 | " function allowance(address _owner, address _spender)\n" +
241 | " public view returns (uint256);\n" +
242 | "\n" +
243 | " function transferFrom(address _from, address _to, uint256 _value)\n" +
244 | " public returns (bool);\n" +
245 | "\n" +
246 | " function approve(address _spender, uint256 _value) public returns (bool);\n" +
247 | " event Approval(\n" +
248 | " address indexed owner,\n" +
249 | " address indexed spender,\n" +
250 | " uint256 value\n" +
251 | " );\n" +
252 | "}\n" +
253 | "\n" +
254 | "// File: contracts/zeppelin-solidity/contracts/token/ERC20/StandardToken.sol\n" +
255 | "\n" +
256 | "/**\n" +
257 | " * @title Standard ERC20 token\n" +
258 | " *\n" +
259 | " * @dev Implementation of the basic standard token.\n" +
260 | " * https://github.com/ethereum/EIPs/issues/20\n" +
261 | " * Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol\n" +
262 | " */\n" +
263 | "contract StandardToken is ERC20, BasicToken {\n" +
264 | "\n" +
265 | " mapping (address => mapping (address => uint256)) internal allowed;\n" +
266 | "\n" +
267 | "\n" +
268 | " /**\n" +
269 | " * @dev Transfer tokens from one address to another\n" +
270 | " * @param _from address The address which you want to send tokens from\n" +
271 | " * @param _to address The address which you want to transfer to\n" +
272 | " * @param _value uint256 the amount of tokens to be transferred\n" +
273 | " */\n" +
274 | " function transferFrom(\n" +
275 | " address _from,\n" +
276 | " address _to,\n" +
277 | " uint256 _value\n" +
278 | " )\n" +
279 | " public\n" +
280 | " returns (bool)\n" +
281 | " {\n" +
282 | " require(_value <= balances[_from]);\n" +
283 | " require(_value <= allowed[_from][msg.sender]);\n" +
284 | " require(_to != address(0));\n" +
285 | "\n" +
286 | " balances[_from] = balances[_from].sub(_value);\n" +
287 | " balances[_to] = balances[_to].add(_value);\n" +
288 | " allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);\n" +
289 | " emit Transfer(_from, _to, _value);\n" +
290 | " return true;\n" +
291 | " }\n" +
292 | "\n" +
293 | " /**\n" +
294 | " * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.\n" +
295 | " * Beware that changing an allowance with this method brings the risk that someone may use both the old\n" +
296 | " * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this\n" +
297 | " * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:\n" +
298 | " * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n" +
299 | " * @param _spender The address which will spend the funds.\n" +
300 | " * @param _value The amount of tokens to be spent.\n" +
301 | " */\n" +
302 | " function approve(address _spender, uint256 _value) public returns (bool) {\n" +
303 | " allowed[msg.sender][_spender] = _value;\n" +
304 | " emit Approval(msg.sender, _spender, _value);\n" +
305 | " return true;\n" +
306 | " }\n" +
307 | "\n" +
308 | " /**\n" +
309 | " * @dev Function to check the amount of tokens that an owner allowed to a spender.\n" +
310 | " * @param _owner address The address which owns the funds.\n" +
311 | " * @param _spender address The address which will spend the funds.\n" +
312 | " * @return A uint256 specifying the amount of tokens still available for the spender.\n" +
313 | " */\n" +
314 | " function allowance(\n" +
315 | " address _owner,\n" +
316 | " address _spender\n" +
317 | " )\n" +
318 | " public\n" +
319 | " view\n" +
320 | " returns (uint256)\n" +
321 | " {\n" +
322 | " return allowed[_owner][_spender];\n" +
323 | " }\n" +
324 | "\n" +
325 | " /**\n" +
326 | " * @dev Increase the amount of tokens that an owner allowed to a spender.\n" +
327 | " * approve should be called when allowed[_spender] == 0. To increment\n" +
328 | " * allowed value is better to use this function to avoid 2 calls (and wait until\n" +
329 | " * the first transaction is mined)\n" +
330 | " * From MonolithDAO Token.sol\n" +
331 | " * @param _spender The address which will spend the funds.\n" +
332 | " * @param _addedValue The amount of tokens to increase the allowance by.\n" +
333 | " */\n" +
334 | " function increaseApproval(\n" +
335 | " address _spender,\n" +
336 | " uint256 _addedValue\n" +
337 | " )\n" +
338 | " public\n" +
339 | " returns (bool)\n" +
340 | " {\n" +
341 | " allowed[msg.sender][_spender] = (\n" +
342 | " allowed[msg.sender][_spender].add(_addedValue));\n" +
343 | " emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);\n" +
344 | " return true;\n" +
345 | " }\n" +
346 | "\n" +
347 | " /**\n" +
348 | " * @dev Decrease the amount of tokens that an owner allowed to a spender.\n" +
349 | " * approve should be called when allowed[_spender] == 0. To decrement\n" +
350 | " * allowed value is better to use this function to avoid 2 calls (and wait until\n" +
351 | " * the first transaction is mined)\n" +
352 | " * From MonolithDAO Token.sol\n" +
353 | " * @param _spender The address which will spend the funds.\n" +
354 | " * @param _subtractedValue The amount of tokens to decrease the allowance by.\n" +
355 | " */\n" +
356 | " function decreaseApproval(\n" +
357 | " address _spender,\n" +
358 | " uint256 _subtractedValue\n" +
359 | " )\n" +
360 | " public\n" +
361 | " returns (bool)\n" +
362 | " {\n" +
363 | " uint256 oldValue = allowed[msg.sender][_spender];\n" +
364 | " if (_subtractedValue >= oldValue) {\n" +
365 | " allowed[msg.sender][_spender] = 0;\n" +
366 | " } else {\n" +
367 | " allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);\n" +
368 | " }\n" +
369 | " emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);\n" +
370 | " return true;\n" +
371 | " }\n" +
372 | "\n" +
373 | "}\n" +
374 | "\n" +
375 | "// File: contracts/zeppelin-solidity/contracts/token/ERC20/PausableToken.sol\n" +
376 | "\n" +
377 | "/**\n" +
378 | " * @title Pausable token\n" +
379 | " * @dev StandardToken modified with pausable transfers.\n" +
380 | " **/\n" +
381 | "contract PausableToken is StandardToken, Pausable {\n" +
382 | "\n" +
383 | " function transfer(\n" +
384 | " address _to,\n" +
385 | " uint256 _value\n" +
386 | " )\n" +
387 | " public\n" +
388 | " whenNotPaused\n" +
389 | " returns (bool)\n" +
390 | " {\n" +
391 | " return super.transfer(_to, _value);\n" +
392 | " }\n" +
393 | "\n" +
394 | " function transferFrom(\n" +
395 | " address _from,\n" +
396 | " address _to,\n" +
397 | " uint256 _value\n" +
398 | " )\n" +
399 | " public\n" +
400 | " whenNotPaused\n" +
401 | " returns (bool)\n" +
402 | " {\n" +
403 | " return super.transferFrom(_from, _to, _value);\n" +
404 | " }\n" +
405 | "\n" +
406 | " function approve(\n" +
407 | " address _spender,\n" +
408 | " uint256 _value\n" +
409 | " )\n" +
410 | " public\n" +
411 | " whenNotPaused\n" +
412 | " returns (bool)\n" +
413 | " {\n" +
414 | " return super.approve(_spender, _value);\n" +
415 | " }\n" +
416 | "\n" +
417 | " function increaseApproval(\n" +
418 | " address _spender,\n" +
419 | " uint _addedValue\n" +
420 | " )\n" +
421 | " public\n" +
422 | " whenNotPaused\n" +
423 | " returns (bool success)\n" +
424 | " {\n" +
425 | " return super.increaseApproval(_spender, _addedValue);\n" +
426 | " }\n" +
427 | "\n" +
428 | " function decreaseApproval(\n" +
429 | " address _spender,\n" +
430 | " uint _subtractedValue\n" +
431 | " )\n" +
432 | " public\n" +
433 | " whenNotPaused\n" +
434 | " returns (bool success)\n" +
435 | " {\n" +
436 | " return super.decreaseApproval(_spender, _subtractedValue);\n" +
437 | " }\n" +
438 | "}\n" +
439 | "\n" +
440 | "// File: contracts/TestToken.sol\n" +
441 | "\n" +
442 | "/// @author reedhong\n" +
443 | "contract TestToken is PausableToken {\n" +
444 | " using SafeMath for uint;\n" +
445 | " \n" +
446 | " /// Constant token specific fields\n" +
447 | " string public constant name = \"TestToken\";\n" +
448 | " string public constant symbol = \"Cows\";\n" +
449 | " uint public constant decimals = 18;\n" +
450 | " \n" +
451 | " constructor()\n" +
452 | " public\n" +
453 | " {\n" +
454 | " totalSupply_ = 100000000 ether;\n" +
455 | " paused = false;\n" +
456 | " balances[0xc0be69a5a0c1dce0d98649532f27cd3824f6061f] = totalSupply_;\n" +
457 | " }\n" +
458 | "}\n"
459 | }
460 | }
461 |
462 | render() {
463 | const options = {
464 | selectOnLineNumbers: true
465 | };
466 |
467 | return (
468 |
475 |
476 | );
477 | }
478 | };
479 |
480 |
481 |
482 | export default connect()(TokenContract);
483 |
--------------------------------------------------------------------------------