From 62b27a418c6048ff0ee9b679233b3f9628b89367 Mon Sep 17 00:00:00 2001 From: Shuai Date: Wed, 21 Sep 2022 16:27:06 +0800 Subject: [PATCH 1/2] refac js --- neo3-gui/neo3-gui/ClientApp/gui-config.json | 2 +- neo3-gui/neo3-gui/ClientApp/package-lock.json | 4 +- neo3-gui/neo3-gui/ClientApp/package.json | 2 +- .../src/components/Advanced/candidate.js | 137 +++----- .../src/components/Advanced/designrole.js | 104 +++--- .../src/components/Advanced/noderole.js | 105 +++--- .../ClientApp/src/components/Chain/chain.js | 42 +-- .../src/components/Chain/hashdetail.js | 166 +++++----- .../src/components/Chain/searcharea.js | 36 +- .../src/components/Common/menudown.js | 37 +-- .../src/components/Common/searcharea.js | 34 +- .../src/components/Contract/contract.js | 39 +-- .../src/components/Contract/deploy.js | 77 ++--- .../src/components/Contract/searcharea.js | 33 +- .../src/components/Contract/upgrade.js | 7 +- .../src/components/Transaction/searcharea.js | 36 +- .../src/components/Transaction/transaction.js | 86 ++--- .../src/components/Transaction/transfer.js | 83 ++--- .../src/components/Wallet/walletdetail.js | 154 +++------ .../src/components/Wallet/walletlist.js | 313 +++++++----------- .../src/components/WebSocket/neoWebSocket.js | 3 +- neo3-gui/neo3-gui/ClientApp/src/config.js | 4 +- .../neo3-gui/ClientApp/src/core/request.js | 18 +- .../neo3-gui/ClientApp/src/store/pathStore.js | 9 - .../neo3-gui/ClientApp/src/store/stores.js | 5 +- .../Common/Analyzers/BlockAnalyzer.cs | 17 +- .../Common/Scanners/ExecuteResultScanner.cs | 14 +- .../LevelDBModules/TransferStorageItem.cs | 1 + .../Storage/SQLiteModules/SQLiteContext.cs | 12 +- .../SQLiteModules/TransactionEntity.cs | 2 +- ...ep5TransferEntity.cs => TransferEntity.cs} | 8 +- neo3-gui/neo3-gui/Common/Storage/TrackDB.cs | 28 +- neo3-gui/neo3-gui/Helpers.cs | 44 +-- .../neo3-gui/Models/TransferNotifyItem.cs | 5 + .../ApiServices/ContractApiService.cs | 2 +- neo3-gui/neo3-gui/config.private.json | 2 +- 36 files changed, 645 insertions(+), 1026 deletions(-) delete mode 100644 neo3-gui/neo3-gui/ClientApp/src/store/pathStore.js rename neo3-gui/neo3-gui/Common/Storage/SQLiteModules/{Nep5TransferEntity.cs => TransferEntity.cs} (89%) diff --git a/neo3-gui/neo3-gui/ClientApp/gui-config.json b/neo3-gui/neo3-gui/ClientApp/gui-config.json index b20d5336..d10c9b5a 100644 --- a/neo3-gui/neo3-gui/ClientApp/gui-config.json +++ b/neo3-gui/neo3-gui/ClientApp/gui-config.json @@ -1,6 +1,6 @@ { + "Host": "localhost", "Port": 8081, - "RPCURL": "http://localhost:8081", "Language": "", "Network": "mainnet" } \ No newline at end of file diff --git a/neo3-gui/neo3-gui/ClientApp/package-lock.json b/neo3-gui/neo3-gui/ClientApp/package-lock.json index 18686856..b4886e9d 100644 --- a/neo3-gui/neo3-gui/ClientApp/package-lock.json +++ b/neo3-gui/neo3-gui/ClientApp/package-lock.json @@ -1,12 +1,12 @@ { "name": "neo-gui", - "version": "1.4.3", + "version": "1.4.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "neo-gui", - "version": "1.4.3", + "version": "1.4.4", "dependencies": { "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.3.2", diff --git a/neo3-gui/neo3-gui/ClientApp/package.json b/neo3-gui/neo3-gui/ClientApp/package.json index 39701365..507552ce 100644 --- a/neo3-gui/neo3-gui/ClientApp/package.json +++ b/neo3-gui/neo3-gui/ClientApp/package.json @@ -1,6 +1,6 @@ { "name": "neo-gui", - "version": "1.4.3", + "version": "1.4.4", "private": true, "main": "main.js", "homepage": "./", diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/candidate.js b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/candidate.js index 2f1aa64b..93d6a0d5 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/candidate.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/candidate.js @@ -1,7 +1,6 @@ /* eslint-disable */ import React from "react"; import "antd/dist/antd.css"; -import axios from "axios"; import { Checkbox, PageHeader, @@ -20,6 +19,7 @@ import { observer, inject } from "mobx-react"; import { withRouter } from "react-router-dom"; import { withTranslation } from "react-i18next"; import "../../static/css/advanced.css"; +import { postAsync } from "../../core/request"; const { Option } = Select; @@ -45,92 +45,65 @@ class Advancedcandidate extends React.Component { }); }); } - listPublicKey = (callback) => { + listPublicKey = async (callback) => { const { t } = this.props; - axios - .post("http://localhost:8081", { - id: "1", - method: "ListCandidatePublicKey", - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - if (_data.msgType === -1) { - let res = _data.error; - Modal.error({ - title: t("contract.fail title"), - width: 400, - content: ( -
-

- {t("error code")}: {res.code} -

-

- {t("error msg")}: {res.message} -

-
- ), - okText: t("button.ok"), - }); - return; - } else if (_data.msgType === 3) { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("ListCandidatePublicKey"); + if (response.msgType === -1) { + let res = response.error; + Modal.error({ + title: t("contract.fail title"), + width: 400, + content: ( +
+

+ {t("error code")}: {res.code} +

+

+ {t("error msg")}: {res.message} +

+
+ ), + okText: t("button.ok"), }); + return; + } + callback(response); }; - onCandidate = (fieldsValue) => { + onCandidate = async (fieldsValue) => { const { t } = this.props; - axios - .post("http://localhost:8081", { - id: "1", - method: "ApplyForValidator", - params: { - pubkey: fieldsValue.pubkey, - }, - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - if (_data.msgType === -1) { - let res = _data.error; - Modal.error({ - title: t("advanced.candidate fail"), - width: 400, - content: ( -
-

- {t("error code")}: {res.code} -

-

- {t("error msg")}: {res.message} -

-
- ), - okText: t("button.ok"), - }); - return; - } else if (_data.msgType === 3) { - Modal.success({ - title: t("advanced.candidate success"), - width: 400, - content: ( -
-

TxID : {_data.result.txId ? _data.result.txId : "--"}

-
- ), - okText: t("button.ok"), - }); - return; - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("ApplyForValidator", { + pubkey: fieldsValue.pubkey, + }); + if (response.msgType === -1) { + let res = response.error; + Modal.error({ + title: t("advanced.candidate fail"), + width: 400, + content: ( +
+

+ {t("error code")}: {res.code} +

+

+ {t("error msg")}: {res.message} +

+
+ ), + okText: t("button.ok"), }); + return; + } + + Modal.success({ + title: t("advanced.candidate success"), + width: 400, + content: ( +
+

TxID : {response.result.txId ? response.result.txId : "--"}

+
+ ), + okText: t("button.ok"), + }); }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/designrole.js b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/designrole.js index ce41f44a..36c8588a 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/designrole.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/designrole.js @@ -11,14 +11,16 @@ import { Col, Form, Select, - Button, - message} from 'antd'; + Button, + message +} from 'antd'; import { Layout } from 'antd'; import Sync from '../sync'; import { observer, inject } from "mobx-react"; import { withRouter } from "react-router-dom"; import { withTranslation } from "react-i18next"; import "../../static/css/advanced.css"; +import { postAsync } from '../../core/request'; const { Option } = Select; const { Content } = Layout; @@ -31,27 +33,15 @@ class Advanceddesignrole extends React.Component { super(props); this.state = { size: 'default', - rolelist: [{type:4,role:"StateValidator"},{type:8,role:"Oracle"}], + rolelist: [{ type: 4, role: "StateValidator" }, { type: 8, role: "Oracle" }], }; } - onRole = fieldsValue =>{ + onRole = async (fieldsValue) => { const { t } = this.props; - axios.post('http://localhost:8081', { - "id": "1", - "method": "GetNodesByRole", - "params":{ - "role":fieldsValue.role - } - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - return; - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("GetNodesByRole", { + "role": fieldsValue.role }); + console.log(response); } render = () => { const { t } = this.props; @@ -62,44 +52,44 @@ class Advanceddesignrole extends React.Component { - - -
- -
-

{t('advanced.be candidate')}

- - - -

- -

-
+ + +
+ +
+

{t('advanced.be candidate')}

+ + + +

+ +

+
diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/noderole.js b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/noderole.js index 4273123d..e31d38be 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/noderole.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Advanced/noderole.js @@ -1,7 +1,6 @@ /* eslint-disable */ import React from 'react'; import 'antd/dist/antd.css'; -import axios from 'axios'; import { Checkbox, PageHeader, @@ -11,14 +10,16 @@ import { Col, Form, Select, - Button, - message} from 'antd'; + Button, + message +} from 'antd'; import { Layout } from 'antd'; import Sync from '../sync'; import { observer, inject } from "mobx-react"; import { withRouter } from "react-router-dom"; import { withTranslation } from "react-i18next"; import "../../static/css/advanced.css"; +import { postAsync } from '../../core/request'; const { Option } = Select; const { Content } = Layout; @@ -31,29 +32,17 @@ class Advancednoderole extends React.Component { super(props); this.state = { size: 'default', - rolelist: [{type:4,role:"StateValidator"},{type:8,role:"Oracle"}], + rolelist: [{ type: 4, role: "StateValidator" }, { type: 8, role: "Oracle" }], }; } - onRole = fieldsValue =>{ + onRole = async (fieldsValue) => { const { t } = this.props; - console.log(fieldsValue); + console.log(fieldsValue); - axios.post('http://localhost:8081', { - "id": "1", - "method": "GetNodesByRole", - "params":{ - "role":parseInt(fieldsValue.role) - } - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - return; - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("GetNodesByRole", { + "role": parseInt(fieldsValue.role) }); + console.log(response); } render = () => { const { t } = this.props; @@ -64,43 +53,43 @@ class Advancednoderole extends React.Component { - - -
- -
-

{t('节点角色类型')}

- - - -

- -

-
+ + +
+ +
+

{t('节点角色类型')}

+ + + +

+ +

+
diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js index 249a7e28..b356ad7a 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js @@ -12,12 +12,12 @@ import { Button, PageHeader, } from "antd"; -import axios from "axios"; import Chainsearch from "./searcharea"; import Sync from "../sync"; import { withTranslation } from "react-i18next"; import "../../static/css/contract.css"; +import { postAsync } from "../../core/request"; const { Content } = Layout; @@ -44,40 +44,26 @@ class Chain extends React.Component { blocklist: res.result, lastblock: res.result[res.result.length - 1].blockHeight - 1, }, - () => {} + () => { } ); }); } - getBlock = (callback) => { + getBlock = async (callback) => { console.log(this.state.lastblock); let _params = this.state.lastblock ? { - limit: 50, - height: this.state.lastblock, - } + limit: 50, + height: this.state.lastblock, + } : { - limit: 50, - }; - axios - .post("http://localhost:8081", { - id: "51", - method: "GetLastBlocks", - params: _params, - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - if (_data.msgType === -1) { - message.error("查询失败"); - return; - } else { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + limit: 50, + }; + let response = await postAsync("GetLastBlocks", _params); + if (response.msgType < 0) { + message.error("Query fail!"); + return; + } + callback(response) }; loadMore = () => { this.setState({ diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js index 2efed744..8e53eb19 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js @@ -1,129 +1,115 @@ -/* eslint-disable */ +/* eslint-disable */ //just test replace wallet// import React from 'react'; -import {Link} from 'react-router-dom'; -import { Layout, Row, Col, message,List,Typography,PageHeader } from 'antd'; -import axios from 'axios'; -import Intitle from '../Common/intitle'; +import { Link } from 'react-router-dom'; +import { Layout, Row, Col, message, List, Typography, PageHeader } from 'antd'; import Sync from '../sync'; +import { postAsync } from '../../core/request'; const { Content } = Layout; -class Blockdetail extends React.Component{ - constructor(props){ +class Blockdetail extends React.Component { + constructor(props) { super(props); this.state = { blockdetail: {}, - hash:"", - witness:"", - nonce:0, + hash: "", + witness: "", + nonce: 0, }; } - componentDidMount(){ + componentDidMount() { let _h = location.pathname.split(":").pop(); this.setHash(_h)(); this.setState({ - local:location.pathname + local: location.pathname }) } - getAllblock = () =>{ - var _this = this; + getAllblock = async () => { let _hash = this.state.hash; - axios.post('http://localhost:8081', { - "id":"1111", - "method": "GetBlockByHash", - "params": { - "hash": _hash - } - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - if(_data.msgType === -1){ - message.error("查询失败,该hash错误"); - return; - } - _this.setState({ - blockdetail:_data.result, - witness:_data.result.witness.scriptHash, - nonce:_data.result.consensusData.nonce, - translist:_data.result.transactions - }) - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("GetBlockByHash", { + "hash": _hash + }); + if (response.msgType === -1) { + message.error("查询失败,该hash错误"); + return; + } + this.setState({ + blockdetail: response.result, + witness: response.result.witness.scriptHash, + nonce: response.result.consensusData.nonce, + translist: response.result.transactions }); } setHash = (h) => { - return () =>{ - this.setState({ - hash: h - },() => this.getAllblock()); - } - } - render(){ - const {blockdetail,witness,nonce,translist,local} = this.state; - return ( - - - + return () => { + this.setState({ + hash: h + }, () => this.getAllblock()); + } + } + render() { + const { blockdetail, witness, nonce, translist, local } = this.state; + return ( + + +
Hash:    {blockdetail.blockHash}
- -
    -
  • 高度:{blockdetail.blockHeight}
  • -
  • 时间戳:{blockdetail.blockTime}
  • -
  • 网络费:{blockdetail.networkFee?blockdetail.networkFee:'--'}
  • -
  • 确认数:{blockdetail.confirmations}
  • -
- - -
    -
  • 大小:{blockdetail.blockHeight}
  • -
  • 随机数:{nonce}
  • -
  • 系统费:{blockdetail.networkFee?blockdetail.networkFee:'--'}
  • -
  • 见证人:{witness}
  • -
- + +
    +
  • 高度:{blockdetail.blockHeight}
  • +
  • 时间戳:{blockdetail.blockTime}
  • +
  • 网络费:{blockdetail.networkFee ? blockdetail.networkFee : '--'}
  • +
  • 确认数:{blockdetail.confirmations}
  • +
+ + +
    +
  • 大小:{blockdetail.blockHeight}
  • +
  • 随机数:{nonce}
  • +
  • 系统费:{blockdetail.networkFee ? blockdetail.networkFee : '--'}
  • +
  • 见证人:{witness}
  • +
+
- + - - 交易hash数量时间
} - footer={} - itemLayout="horizontal" - dataSource={translist} - className="font-s" - renderItem={item => ( - - {item.txId}} - description={ -
- From:{item.transfers[0].fromAddress?item.transfers[0].fromAddress:"--"}

- To:{item.transfers[0].toAddress?item.transfers[0].toAddress:"--"} -
} - /> - {item.blockTime} - {item.transfers[0].amount}{item.transfers[0].symbol} -
- )} - /> + + 交易hash数量时间
} + footer={} + itemLayout="horizontal" + dataSource={translist} + className="font-s" + renderItem={item => ( + + {item.txId}} + description={ +
+ From:{item.transfers[0].fromAddress ? item.transfers[0].fromAddress : "--"}

+ To:{item.transfers[0].toAddress ? item.transfers[0].toAddress : "--"} +
} + /> + {item.blockTime} + {item.transfers[0].amount}{item.transfers[0].symbol} +
+ )} + />
); } -} +} export default Blockdetail; \ No newline at end of file diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js index 359a7ace..aa36060e 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js @@ -6,6 +6,7 @@ import { Input, message } from "antd"; import Topath from "../Common/topath"; import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; import { withTranslation } from "react-i18next"; +import { postAsync } from "../../core/request"; @withTranslation() class Chainsearch extends React.Component { @@ -46,38 +47,21 @@ class Chainsearch extends React.Component { stopPropagation(e) { e.nativeEvent.stopImmediatePropagation(); } - searchChain = () => { + searchChain = async () => { const { t } = this.props; - let _this = this; - let _height = Number(this.refs.sinput.input.value.trim()); if (!_height && _height != 0) { message.info(t("search.check again")); return; } - - axios - .post("http://localhost:8081", { - id: "1111", - method: "GetBlock", - params: { - index: _height, - }, - }) - .then(function (response) { - var _data = response.data; - console.log(_data); - if (_data.msgType === -1) { - message.info(t("blockchain.height unexist")); - return; - } else { - _this.setState({ topath: "/chain/detail:" + _height }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let response = await postAsync("GetBlock", { + index: _height, + }); + if (response.msgType === -1) { + message.info(t("blockchain.height unexist")); + return; + } + this.setState({ topath: "/chain/detail:" + _height }); }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js index 6b072f7e..81118f98 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js @@ -16,7 +16,7 @@ import { withTranslation, Trans } from "react-i18next"; import { shell } from "electron"; import Config from "../../config"; import neonode from "../../neonode"; -import { post } from "../../core/request"; +import { post, postAsync } from "../../core/request"; import { walletStore } from "../../store/stores"; @withTranslation() @@ -52,45 +52,26 @@ class menuDown extends React.Component { console.log("error"); }); }; - logout = () => { + logout = async () => { const { t } = this.props; - axios - .post("http://localhost:8081", { - id: "1234", - method: "CloseWallet", - }) - .then(() => { - message.success(t("wallet.close wallet"), 2); - this.props.walletStore.logout(); - this.props.history.push("/"); - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let response = await postAsync("CloseWallet"); + message.success(t("wallet.close wallet"), 2); + this.props.walletStore.logout(); + this.props.history.push("/"); }; showModal = () => { this.setState({ visible: true, }); }; - hideModal = () => { + hideModal = async () => { this.setState({ visible: false, }); if (this.state.change) { neonode.switchNode(this.state.network); - axios - .post("http://localhost:8081", { - id: "1234", - method: "CloseWallet", - }) - .then(() => { - this.props.walletStore.logout(); - }) - .catch(function (error) { - console.log(error); - }); + let response = await postAsync("CloseWallet"); + this.props.walletStore.logout(); this.props.blockSyncStore.setHeight({ syncHeight: -1, headerHeight: -1 }); this.props.walletStore.logout(); this.props.history.push("/"); diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js index 178acde7..18e47e68 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js @@ -5,7 +5,7 @@ import { useHistory } from "react-router-dom"; import axios from "axios"; import { Input, message } from "antd"; import Topath from "../Common/topath"; -import { post } from "../../core/request"; +import { post, postAsync } from "../../core/request"; import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; import { withTranslation, useTranslation } from "react-i18next"; @@ -48,35 +48,21 @@ class Searcharea extends React.Component { stopPropagation(e) { e.nativeEvent.stopImmediatePropagation(); } - searchContract = () => { + searchContract = async () => { const { t } = this.props; let _hash = this.refs.sinput.input.value.trim(); if (!_hash) { message.info(t("search.check again")); return; } - var _this = this; - axios - .post("http://localhost:8081", { - id: "1111", - method: "GetContract", - params: { - contractHash: _hash, - }, - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.info(t("search.hash unexist")); - return; - } else if (_data.msgType === 3) { - _this.setState({ topath: "/contract/detail:" + _hash }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let response = await postAsync("GetContract", { + contractHash: _hash, + }); + if (response.msgType === -1) { + message.info(t("search.hash unexist")); + return; + } + this.setState({ topath: "/contract/detail:" + _hash }); }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/contract.js b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/contract.js index 04549e9b..3b81590f 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/contract.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/contract.js @@ -4,12 +4,13 @@ import { withRouter, Link } from 'react-router-dom'; import 'antd/dist/antd.css'; import '../../static/css/menu.css' import '../../static/css/contract.css' -import { Layout, Menu, List, Row, Col, PageHeader, Typography,Avatar } from 'antd'; +import { Layout, Menu, List, Row, Col, PageHeader, Typography, Avatar } from 'antd'; import axios from 'axios'; import Sync from '../sync'; import Searcharea from './searcharea' import { withTranslation } from "react-i18next"; import { Copy } from '../copy'; +import { postAsync } from '../../core/request'; const { Content } = Layout; @@ -21,38 +22,26 @@ class Contract extends React.Component { size: 'default', visible: false, show: false, - assetlist:[] + assetlist: [] }; } componentDidMount() { this.getAllContracts(); } - visi = () =>{ + visi = () => { this.setState({ show: !this.state.show, }); } - getAllContracts = (info) => { - var _this = this; - axios.post('http://localhost:8081', { - "id": "1111", - "method": "GetAllContracts", - "params": {} - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.error("查询失败"); - return; - } - _this.setState({ - assetlist: _data.result - }) + getAllContracts = async (info) => { + let response = await postAsync("GetAllContracts"); + if (response.msgType === -1) { + message.error("查询失败"); + return; + } + this.setState({ + assetlist: response.result }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); } render = () => { const { t } = this.props; @@ -72,7 +61,7 @@ class Contract extends React.Component { + } title={{item.name}} /> @@ -82,7 +71,7 @@ class Contract extends React.Component { /> - + diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/deploy.js b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/deploy.js index b5902067..a2875af5 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/deploy.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/deploy.js @@ -24,10 +24,12 @@ import { observer, inject } from "mobx-react"; import { withRouter } from "react-router-dom"; import { withTranslation } from "react-i18next"; import { remote } from "electron"; +import fs from "fs"; +import { postAsync } from "../../core/request"; + const { Content } = Layout; const { dialog } = remote; - const { TextArea } = Input; @withTranslation() @@ -39,50 +41,36 @@ class Contractdeploy extends React.Component { super(props); this.state = { size: "default", - mapath: "", - expath: "", + nefpath: "", + manipath: "", disabled: true, visible: false, - func: "", cost: -1, isOpenDialog: false, }; } - selectNef = () => { - this.opendialog("nef", (res) => { - console.log(res) - this.setState( - { - expath: res.filePaths[0], - isOpenDialog: false, - }, - () => { - this.onFill(); + selectNef = async () => { + this.opendialog("nef", async (res) => { + let nef = res.filePaths[0]; + if (nef) { + let manifest = nef.substring(0, nef.length - 3) + "manifest.json"; + if (fs.existsSync(manifest)) { + await this.setState({ manipath: manifest }); } - ); + await this.setState({ nefpath: nef, isOpenDialog: false }); + this.onFill() + } }); }; - selectMani = () => { - this.opendialog("json", (res) => { - console.log(res) - this.setState( - { - mapath: res.filePaths[0], - isOpenDialog: false, - }, - () => { - this.onFill(); - } - ); + selectMani = async () => { + this.opendialog("json", async (res) => { + await this.setState({ manipath: res.filePaths[0], isOpenDialog: false }); + this.onFill(); }); }; browseDialog = () => { const { isOpenDialog } = this.state; - if (isOpenDialog === false) { - return false; - } else { - return true; - } + return isOpenDialog; }; opendialog = (str, callback) => { if (this.browseDialog()) return; @@ -109,8 +97,8 @@ class Contractdeploy extends React.Component { }; onFill = () => { this.refs.formRef.setFieldsValue({ - nefPath: this.state.expath, - manifestPath: this.state.mapath, + nefPath: this.state.nefpath, + manifestPath: this.state.manipath, tresult: this.state.tresult, }); }; @@ -165,16 +153,10 @@ class Contractdeploy extends React.Component { }; deployContract = (params, callback) => { const { t } = this.props; - axios - .post("http://localhost:8081", { - id: "1", - method: "DeployContract", - params: params, - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - let res = _data.error; + postAsync("DeployContract", params) + .then((data) => { + if (data.msgType === -1) { + let res = data.error; Modal.error({ title: t("contract.fail title"), width: 400, @@ -191,13 +173,12 @@ class Contractdeploy extends React.Component { okText: t("button.ok"), }); return; - } else if (_data.msgType === 3) { - callback(_data); + } else if (data.msgType === 3) { + callback(data); } }) .catch(function (error) { - console.log(error); - console.log("error"); + // console.log(error); }); }; render = () => { diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/searcharea.js index 6e922866..d206af2e 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/searcharea.js @@ -6,6 +6,7 @@ import { Input, message } from "antd"; import Topath from "../Common/topath"; import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; import { withTranslation } from "react-i18next"; +import { postAsync } from "../../core/request"; @withTranslation() class Searcharea extends React.Component { @@ -46,35 +47,21 @@ class Searcharea extends React.Component { stopPropagation(e) { e.nativeEvent.stopImmediatePropagation(); } - searchContract = () => { + searchContract = async () => { const { t } = this.props; let _hash = this.refs.sinput.input.value.trim(); if (!_hash) { message.info(t("search.check again")); return; } - var _this = this; - axios - .post("http://localhost:8081", { - id: "1111", - method: "GetContract", - params: { - contractHash: _hash, - }, - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.info(t("search.hash unexist")); - return; - } else if (_data.msgType === 3) { - _this.setState({ topath: "/contract/detail:" + _hash }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let response = await postAsync("GetContract", { + contractHash: _hash, + }); + if (response.msgType === -1) { + message.info(t("search.hash unexist")); + return; + } + this.setState({ topath: "/contract/detail:" + _hash }); }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/upgrade.js b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/upgrade.js index a1f911bb..266f3d97 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/upgrade.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/upgrade.js @@ -62,18 +62,13 @@ class ContractUpgrade extends React.Component { }; selectMani = async () => { this.opendialog("json", async (res) => { - console.log(res) await this.setState({ manipath: res.filePaths[0], isOpenDialog: false }); this.onFill(); }); }; browseDialog = () => { const { isOpenDialog } = this.state; - if (isOpenDialog === false) { - return false; - } else { - return true; - } + return isOpenDialog; }; opendialog = (str, callback) => { if (this.browseDialog()) return; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/searcharea.js index c72554bf..9a9c9461 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/searcharea.js @@ -6,6 +6,7 @@ import { Input, message } from "antd"; import Topath from "../Common/topath"; import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; import { withTranslation } from "react-i18next"; +import { postAsync } from "../../core/request"; @withTranslation() class Searcharea extends React.Component { @@ -46,35 +47,24 @@ class Searcharea extends React.Component { stopPropagation(e) { e.nativeEvent.stopImmediatePropagation(); } - searchContract = () => { + searchContract = async () => { const { t } = this.props; let _hash = this.refs.sinput.input.value.trim(); if (!_hash) { message.info(t("search.check again")); return; } - var _this = this; - axios - .post("http://localhost:8081", { - id: "1111", - method: "GetTransaction", - params: { - txId: _hash, - }, - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.info(t("search.check again")); - return; - } else if (_data.msgType === 3) { - _this.setState({ topath: "transaction:" + _hash }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + + let response = await postAsync("GetTransaction", { + txId: _hash, + }); + if (response.msgType === -1) { + message.info(t("search.check again")); + return; + } + if (response.msgType === 3) { + this.setState({ topath: "transaction:" + _hash }); + } }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transaction.js b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transaction.js index 9e714bfa..1a7ee48a 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transaction.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transaction.js @@ -3,11 +3,11 @@ import React from 'react'; import { observer, inject } from "mobx-react"; import { withRouter, Link } from 'react-router-dom'; -import axios from 'axios'; import { Layout, Row, Col, List, Button, PageHeader, message } from 'antd'; import { withTranslation } from "react-i18next"; import Searcharea from './searcharea' import { SwapRightOutlined } from '@ant-design/icons'; +import { postAsync } from "../../core/request" const { Content } = Layout; @withTranslation() @@ -115,66 +115,34 @@ class Transaction extends React.Component { }); }) } - getMytrans = (params, callback) => { - axios.post('http://localhost:8081', { - "id": "51", - "method": "GetMyTransactions", - "params": params - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.error("查询失败"); - return; - } else { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + getMytrans = async (params, callback) => { + let response = await postAsync("GetMyTransactions", params); + if (response.msgType === -1) { + message.error("查询失败"); + return; + } else { + callback(response); + } } - getAlltrans = (params, callback) => { - axios.post('http://localhost:8081', { - "id": "51", - "method": "QueryTransactions", - "params": params - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - console.log(_data) - message.error("查询失败"); - return; - } else { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + getAlltrans = async (params, callback) => { + let response = await postAsync("QueryTransactions", params); + if (response.msgType === -1) { + console.log(response) + message.error("查询失败"); + return; + } else { + callback(response); + } }; - getNeptrans = (params, callback) => { - axios.post('http://localhost:8081', { - "id": "51", - "method": "QueryNep5Transactions", - "params": params - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.error("查询失败"); - return; - } else { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + getNeptrans = async (params, callback) => { + let response = await postAsync("QueryNep5Transactions", params); + if (response.msgType === -1) { + console.log(response) + message.error("查询失败"); + return; + } else { + callback(response); + } }; loadMore = () => { this.setState({ diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transfer.js b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transfer.js index ca821958..d245e251 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transfer.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Transaction/transfer.js @@ -19,7 +19,7 @@ import '../../static/css/wallet.css' import { Form, DatePicker, TimePicker } from 'antd'; import Sync from '../sync'; import { withTranslation } from "react-i18next"; -import { post } from "../../core/request"; +import { post, postAsync } from "../../core/request"; const { Option } = Select; const { Content } = Layout; @@ -41,7 +41,7 @@ class Transfer extends React.Component { } componentDidMount() { var _this = this; - post("GetMyBalances",{}).then(res =>{ + post("GetMyBalances", {}).then(res => { var _data = response.data; if (_data.msgType === -1) { message.error(t("wallet.open wallet first")); @@ -64,57 +64,42 @@ class Transfer extends React.Component { neo: _data.result.accounts }) } - transfer = fieldsValue => { + transfer = async (fieldsValue) => { let _sender = this.state.addresslist[fieldsValue.sender].address; - let _this = this; - const{t}=this.props; + const { t } = this.props; this.setState({ iconLoading: true }) - axios.post('http://localhost:8081', { - "id": "5", - "method": "SendToAddress", - "params": { - "sender": _sender, - "receiver": fieldsValue.receiver.trim(), - "amount": fieldsValue.amount, - "asset": fieldsValue.asset - } - }) - .then(function (response) { - var _data = response.data; - _this.setState({ iconLoading: false }); - - if(_data.msgType === -1){ - let res = _data.error; - Modal.error({ - title: t('wallet.transfer send error'), - width: 400, - content: errorContent, - okText:"确认" - }); - return; - }else{ - Modal.success({ - title: t('wallet.transfer send success'), - content: ( -
-

{t("blockchain.transaction hash")}:

-

{_data.result.txId}

-
- ), - okText:"确认" - }); - _this.refs.formRef.resetFields() - _this.setState({ - selectadd:[] - }) - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); + let response = await postAsync("SendToAddress", { + "sender": _sender, + "receiver": fieldsValue.receiver.trim(), + "amount": fieldsValue.amount, + "asset": fieldsValue.asset + }); + this.setState({ iconLoading: false }); + if (response.msgType === -1) { + Modal.error({ + title: t('wallet.transfer send error'), + width: 400, + content: errorContent, + okText: "确认" + }); + return; + } + Modal.success({ + title: t('wallet.transfer send success'), + content: ( +
+

{t("blockchain.transaction hash")}:

+

{response.result.txId}

+
+ ), + okText: "确认" }); + this.refs.formRef.resetFields() + this.setState({ + selectadd: [] + }) } render() { const { t } = this.props; @@ -205,7 +190,7 @@ class Transfer extends React.Component { + { - let _add = location.pathname.split(":").pop(); - this.setState({ address: _add }) + let address = location.pathname.split(":").pop(); + this.setState({ address: address }) } - getBalances = () => { - var _this = this; - let _add = location.pathname.split(":").pop(); - let { t } = this.props; - axios.post('http://localhost:8081', { - "id": "51", - "method": "GetMyBalances", - "params": { - "address": _add - } - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - return; - } else { - if (_data.result.length > 0) { - _this.setState({ - assetlist: _data.result[0] - }) - } - } + getBalances = async () => { + let address = location.pathname.split(":").pop(); + let data = await postAsync("GetMyBalances", { + "address": address }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); - } - getGas = () => { - var _this = this; - let { t } = this.props; - axios.post('http://localhost:8081', { - "id": 51, - "method": "ShowGas" - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) return; - _this.setState({ - gas: _data.result.unclaimedGas + if (data.msgType === -1) { + return; + } + if (data.result.length > 0) { + this.setState({ + assetlist: data.result[0] }) - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + } } + // getGas = async () => { + // let data = await postAsync("ShowGas"); + // if (data.msgType === -1) return; + // this.setState({ + // gas: data.result.unclaimedGas + // }) + // } deleteConfirm = () => { let _this = this; let { t } = this.props; @@ -100,62 +75,37 @@ class Walletdetail extends React.Component { }, }); } - delAddress = () => { - var _this = this; + delAddress = async () => { const { t } = this.props; - axios.post('http://localhost:8081', { - "id": "1", - "method": "DeleteAddress", - "params": [_this.state.address] - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - return; - } else { - message.success(t("wallet.delete success"), 2) - _this.setState({ topath: "/wallet/walletlist" }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let data = await postAsync("DeleteAddress", [this.state.address]); + if (data.msgType === -1) { + return; + } + message.success(t("wallet.delete success"), 2) + this.setState({ topath: "/wallet/walletlist" }); } - showPrivate = () => { - var _this = this; + showPrivate = async () => { let { t } = this.props; - axios.post('http://localhost:8081', { - "id": "123456", - "method": "ShowPrivateKey", - "params": { - "address": _this.state.address - } - }) - .then(function (response) { - var _data = response.data.result; - if (_data.msgType === -1) { - console.log(t('wallet.require open')); - return; - } else { - Modal.info({ - title: t("wallet.private key warning"), - width: 650, - content: ( -
-

{t("wallet.private key")}: {_data.privateKey}

-

WIF: {_data.wif}

-

{t("wallet.public key")}:{_data.publicKey}

-
- ), - okText: t("button.ok") - }); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let repsonse = await postAsync("ShowPrivateKey", { + "address": this.state.address + }); + if (repsonse.msgType === -1) { + console.log(t('wallet.require open')); + return; + } + let data = repsonse.result; + Modal.info({ + title: t("wallet.private key warning"), + width: 650, + content: ( +
+

{t("wallet.private key")}: {data.privateKey}

+

WIF: {data.wif}

+

{t("wallet.public key")}:{data.publicKey}

+
+ ), + okText: t("button.ok") + }); } render = () => { const { assetlist, address } = this.state; @@ -191,11 +141,11 @@ class Walletdetail extends React.Component { - + - + diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Wallet/walletlist.js b/neo3-gui/neo3-gui/ClientApp/src/components/Wallet/walletlist.js index bcf9603c..cc563648 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Wallet/walletlist.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Wallet/walletlist.js @@ -3,11 +3,11 @@ import React, { useState } from 'react'; import { Link } from 'react-router-dom'; import { observer, inject } from "mobx-react"; import axios from 'axios'; -import { Layout, message, Row, Col, List, Avatar, Button, Typography,PageHeader,Modal,Input,Select,Form,InputNumber } from 'antd'; +import { Layout, message, Row, Col, List, Avatar, Button, Typography, PageHeader, Modal, Input, Select, Form, InputNumber } from 'antd'; import '../../static/css/wallet.css' import Sync from '../sync'; -import { withTranslation,useTranslation,Trans } from "react-i18next"; -import { post } from "../../core/request"; +import { withTranslation, useTranslation, Trans } from "react-i18next"; +import { post, postAsync } from "../../core/request"; import { Copy } from '../copy'; import { @@ -35,127 +35,70 @@ class Walletlist extends React.Component { this.getAllasset(); this.getGas(); } - getAllasset = () => { - var _this = this; - axios.post('http://localhost:8081', { - "id": "12", - "method": "GetMyTotalBalance", - "params": {} - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - console.log("GetMyTotalBalance Error"); - console.log(_data); - return; - } - _this.setState({ - assetlist: _data.result - }) - }) - .catch(function (error) { - console.log(error); - console.log("error"); + getAllasset = async () => { + let data = await postAsync("GetMyTotalBalance", {}); + if (data.msgType === -1) { + console.log("GetMyTotalBalance Error"); + console.log(data); + return; + } + this.setState({ + assetlist: data.result }); } - getAddress = () => { - var _this = this; - axios.post('http://localhost:8081', { - "id": "1234", - "method": "ListAddress", - "params": { - "count": 10 - } - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - console.log("ListAddress Error"); - console.log(_data); - return; - } - _this.props.walletStore.setAccounts(_data.result.accounts); - }) - .catch(function (error) { - console.log(error); - console.log("error"); + getAddress = async () => { + let data = await postAsync("ListAddress", { + "count": 10 }); + if (data.msgType === -1) { + console.log("ListAddress Error"); + console.log(data); + return; + } + this.props.walletStore.setAccounts(data.result.accounts); } - getGas = () => { - var _this = this; - axios.post('http://localhost:8081', { - "id": 51, - "method": "ShowGas" - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType == -1) { - console.log("ShowGas Error"); - console.log(_data); - return; - } - - _this.props.walletStore.setUnclaimedGas(_data.result.unclaimedGas); - - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + getGas = async () => { + let data = await postAsync("ShowGas"); + if (data.msgType == -1) { + console.log("ShowGas Error"); + console.log(data); + return; + } + this.props.walletStore.setUnclaimedGas(data.result.unclaimedGas); } - claimGas = () => { + claimGas = async () => { const { t } = this.props; - var _this = this; - this.setState({iconLoading:true}) - setTimeout(function(){_this.setState({iconLoading:false});_this.getGas()},15000); - axios.post('http://localhost:8081', { - "id": 51, - "method": "ClaimGas" - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.success(t("wallet.gas fail"), 3); - return; - } else if (_data.msgType = 3) { - message.success(t("wallet.gas success"), 3); - } - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + this.setState({ iconLoading: true }) + setTimeout(() => { this.setState({ iconLoading: false }); this.getGas() }, 15000); + + let data = await postAsync("ClaimGas"); + if (data.msgType === -1) { + message.success(t("wallet.gas fail"), 3); + return; + } + if (data.msgType = 3) { + message.success(t("wallet.gas success"), 3); + } } - addAddress = () => { + addAddress = async () => { const { t } = this.props; - var _this = this; - axios.post('http://localhost:8081', { - "id": "1", - "method": "CreateAddress" - }) - .then(function (response) { - var _data = response.data; - if (_data.msgType === -1) { - message.error(t('wallet.open wallet first')); - console.log(_data) - return; - } - message.success(t('wallet.add address success')); - _this.props.walletStore.addAccount(_data.result); - }) - .catch(function (error) { - console.log(error); - console.log("error"); - }); + let data = await postAsync("CreateAddress"); + if (data.msgType === -1) { + message.error(t('wallet.open wallet first')); + console.log(data) + return; + } + message.success(t('wallet.add address success')); + this.props.walletStore.addAccount(data.result); } showModal = (ele) => { const { t } = this.props; - return () =>{ - this.setState({visible: true}) - switch(ele){ - case 0:this.setState({modalPanel:,modalTitle:t("wallet.import private")});break; - case 1:this.setState({modalPanel:,modalTitle:t("wallet.signature multi")});break; - default:this.setState({visible: false});break; + return () => { + this.setState({ visible: true }) + switch (ele) { + case 0: this.setState({ modalPanel: , modalTitle: t("wallet.import private") }); break; + case 1: this.setState({ modalPanel: , modalTitle: t("wallet.signature multi") }); break; + default: this.setState({ visible: false }); break; } } }; @@ -175,14 +118,14 @@ class Walletlist extends React.Component { const { assetlist } = this.state; const { t } = this.props; - let unnoadd = [],normaladd = [], mutiadd = [],contractadd = []; - Array.call([],...accounts).map(function (item) { - let _item = {...item}; - switch(_item.accountType){ - case 0:unnoadd.push(_item);break; - case 1:normaladd.push(_item);break; - case 2:mutiadd.push(_item);break; - case 3:contractadd.push(_item);break; + let unnoadd = [], normaladd = [], mutiadd = [], contractadd = []; + Array.call([], ...accounts).map(function (item) { + let _item = { ...item }; + switch (_item.accountType) { + case 0: unnoadd.push(_item); break; + case 1: normaladd.push(_item); break; + case 2: mutiadd.push(_item); break; + case 3: contractadd.push(_item); break; } }); @@ -196,7 +139,7 @@ class Walletlist extends React.Component {

{t("wallet.accounts")}
- +

- - - - + + + + @@ -224,10 +167,10 @@ class Walletlist extends React.Component { + } title={{item.symbol}} - // description={{item.asset}} + // description={{item.asset}} /> {item.balance} @@ -246,7 +189,7 @@ class Walletlist extends React.Component { onCancel={this.handleCancel} footer={null} > - {this.state.modalPanel} + {this.state.modalPanel} @@ -258,11 +201,11 @@ export default Walletlist; -const Private = ({func}) => { +const Private = ({ func }) => { const [form] = Form.useForm(); const { t } = useTranslation(); - const importPrivate = values =>{ - post("ImportAccounts",[values.private]).then(res =>{ + const importPrivate = values => { + post("ImportAccounts", [values.private]).then(res => { let _data = res.data; if (_data.msgType === 3) { message.success(t('wallet.import private success'), 2); @@ -277,8 +220,8 @@ const Private = ({func}) => { } return (
- - + + @@ -287,20 +230,20 @@ const Private = ({func}) => { ) }; -const Multiaddress = ({func}) => { +const Multiaddress = ({ func }) => { const [form] = Form.useForm(); const { t } = useTranslation(); const [accounts, changeList] = useState([]); const [maxnum, changeNum] = useState(1); const [sigBTdisabled, changeSigBTdisabled] = useState(false); - const getPublic = () =>{ + const getPublic = () => { //列出所有可选举公钥 - post("ListCandidatePublicKey",{}).then(res =>{ + post("ListCandidatePublicKey", {}).then(res => { var _data = res.data; if (_data.msgType === -1) { message.error(t("alert msg.no find")); - }else{ + } else { changeList(_data.result); } return; @@ -308,12 +251,12 @@ const Multiaddress = ({func}) => { console.log(error); }); } - const addMulti = values =>{ + const addMulti = values => { let params = { - "limit":values.limit, - "publicKeys":values.publicKeys + "limit": values.limit, + "publicKeys": values.publicKeys }; - post("CreateMultiAddress",params).then(res =>{ + post("CreateMultiAddress", params).then(res => { var _data = res.data; if (_data.msgType === -1) { message.error(wallet.signature multi error); @@ -324,12 +267,12 @@ const Multiaddress = ({func}) => { width: 600, title: wallet.signature multi success, content: ( -
+

hash :{_data.result.scriptHash}

wallet.address multi sign :{_data.result.address}

-
+
), - okText:button.ok + okText: button.ok }); form.resetFields(); } @@ -338,10 +281,10 @@ const Multiaddress = ({func}) => { }); } const handleChange = value => { - if(value.length<=0) return; + if (value.length <= 0) return; let last = value.pop().trim(); var regex = new RegExp("^0[23][0-9a-f]{64}$"); - if(!regex.test(last)){ + if (!regex.test(last)) { message.error(t("wallet.public key error")); return; } @@ -351,13 +294,13 @@ const Multiaddress = ({func}) => { const handleSignatureMinChange = value => { if (value < 0 || value > maxnum) { changeSigBTdisabled(true); - message.error(t("wallet.signature max input")); + message.error(t("wallet.signature max input")); } else { changeSigBTdisabled(false); } } - if(accounts.length === 0) getPublic(); - return( + if (accounts.length === 0) getPublic(); + return ( {console.log(accounts)}

{t("wallet.signature multi create")}

@@ -367,23 +310,23 @@ const Multiaddress = ({func}) => { mode="tags" onChange={handleChange} className="multiadd" - style={{ width: '100%'}}> - {accounts.length>0?accounts.map((item)=>{ - console.log({...item}) - return( - + style={{ width: '100%' }}> + {accounts.length > 0 ? accounts.map((item) => { + console.log({ ...item }) + return ( + ) - }):null} + }) : null}

{t("wallet.signature min")}

- + value.replace(/[^0-9]/g, '')} - step={1} min={1} + step={1} min={1} onChange={handleSignatureMinChange} - style={{ width: '100%'}}/> + style={{ width: '100%' }} /> @@ -392,33 +335,33 @@ const Multiaddress = ({func}) => { ) } -const Accounts = ({accounts,name}) => { +const Accounts = ({ accounts, name }) => { const { t } = useTranslation(); - if(accounts.length === 0) return null; - return( + if (accounts.length === 0) return null; + return ( {name}} - renderItem={item => ( - - - {item.address} - - } - description={ - - NEO {item.neo} - GAS {item.gas} - } - /> - - )} - /> + itemLayout="horizontal" + dataSource={accounts} + header={
{name}
} + renderItem={item => ( + + + {item.address} + + } + description={ + + NEO {item.neo} + GAS {item.gas} + } + /> + + )} + /> ) } \ No newline at end of file diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/WebSocket/neoWebSocket.js b/neo3-gui/neo3-gui/ClientApp/src/components/WebSocket/neoWebSocket.js index 354ad923..3190f28d 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/WebSocket/neoWebSocket.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/WebSocket/neoWebSocket.js @@ -1,3 +1,4 @@ +import Config from "../../config"; class NeoWebSocket { constructor() { this.processMethods = {}; @@ -18,7 +19,7 @@ class NeoWebSocket { createWebSocket = () => { this.log("creating new webscoket"); - let ws = new WebSocket("ws://127.0.0.1:8081"); + let ws = new WebSocket(Config.WSURL); ws.onopen = () => { this.log("[opened]"); diff --git a/neo3-gui/neo3-gui/ClientApp/src/config.js b/neo3-gui/neo3-gui/ClientApp/src/config.js index 345b59f7..32435ff5 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/config.js +++ b/neo3-gui/neo3-gui/ClientApp/src/config.js @@ -22,8 +22,10 @@ class Config { * init config object from json data */ initConfig = (config) => { + this.Host = config.Host || "localhost" this.Port = config.Port || 8081; - this.RPCURL = config.RPCURL || "http://localhost:" + this.Port; + this.RPCURL = "http://" + this.Host + ":" + this.Port; + this.WSURL = "ws://" + this.Host + ":" + this.Port; this.Language = config.Language || ""; this.Network = config.Network || "mainnet"; }; diff --git a/neo3-gui/neo3-gui/ClientApp/src/core/request.js b/neo3-gui/neo3-gui/ClientApp/src/core/request.js index 0e4eeeb0..eecd81f8 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/core/request.js +++ b/neo3-gui/neo3-gui/ClientApp/src/core/request.js @@ -31,13 +31,19 @@ const post = (method, params) => { }; const postAsync = async (method, params) => { - let response = await request(method, params); - if (response.status !== 200) { - let error = new Error("Response Error!"); - error.response = response; - throw error; + try { + let response = await request(method, params); + if (response.status !== 200) { + let error = new Error("Response Error!"); + error.response = response; + throw error; + } + return response.data; + } catch (e) { + console.error(e); + console.log(e.response); + throw e; } - return response.data; } export { post, postAsync }; diff --git a/neo3-gui/neo3-gui/ClientApp/src/store/pathStore.js b/neo3-gui/neo3-gui/ClientApp/src/store/pathStore.js deleted file mode 100644 index 3dc93228..00000000 --- a/neo3-gui/neo3-gui/ClientApp/src/store/pathStore.js +++ /dev/null @@ -1,9 +0,0 @@ -/* eslint-disable */ -import { observable, action } from "mobx"; - -class PathStore { - @observable mainnet = "http://localhost:8081"; - @observable testnet = []; -} - -export default PathStore; diff --git a/neo3-gui/neo3-gui/ClientApp/src/store/stores.js b/neo3-gui/neo3-gui/ClientApp/src/store/stores.js index 9c2f65b0..249a5ef1 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/store/stores.js +++ b/neo3-gui/neo3-gui/ClientApp/src/store/stores.js @@ -2,19 +2,16 @@ import BlockSyncStore from "./blockSyncStore"; import WalletStore from "./walletStore"; import NodeStore from "./nodeStore"; -import PathStore from "./pathStore"; let blockSyncStore = new BlockSyncStore(); let walletStore = new WalletStore(); let nodeStore = new NodeStore(); -let pathStore = new PathStore(); const Stores = { nodeStore, walletStore, blockSyncStore, - pathStore, }; -export { blockSyncStore, walletStore, nodeStore, pathStore }; +export { blockSyncStore, walletStore, nodeStore }; export default Stores; diff --git a/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs b/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs index b649aebb..0c6b870a 100644 --- a/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs +++ b/neo3-gui/neo3-gui/Common/Analyzers/BlockAnalyzer.cs @@ -88,14 +88,8 @@ private void AnalysisAppExecuteResult(Blockchain.ApplicationExecuted appExec) execResult.Trigger = appExec.Trigger; execResult.VMState = appExec.VMState; execResult.GasConsumed = appExec.GasConsumed; - try - { - execResult.ResultStack = appExec.Stack; - } - catch (InvalidOperationException) - { - //execResult.ResultStack = "error: recursive reference"; - } + execResult.ResultStack = appExec.Stack; + execResult.Notifications = appExec.Notifications.Select(n => n.ToNotificationInfo()).ToList(); Result.ExecuteResultInfos.Add(execResult); @@ -124,8 +118,8 @@ private void AnalysisAppExecuteResult(Blockchain.ApplicationExecuted appExec) case "Update": ProcessUpdate(notification, appExec); break; - case "Destory": - ProcessDestory(notification, appExec); + case "Destroy": + ProcessDestroy(notification, appExec); break; case "transfer": case "Transfer": @@ -172,6 +166,7 @@ private void ProcessTransfer(NotifyEventArgs notification, Blockchain.Applicatio Amount = transfer.Amount, TxId = appExec?.Transaction?.Hash, Trigger = appExec.Trigger, + TokenId = transfer.TokenId?.ToHexString(), }; Result.Transfers.Add(transferStorageItem); } @@ -219,7 +214,7 @@ private void ProcessUpdate(NotifyEventArgs notification, Blockchain.ApplicationE } } - private void ProcessDestory(NotifyEventArgs notification, Blockchain.ApplicationExecuted appExec) + private void ProcessDestroy(NotifyEventArgs notification, Blockchain.ApplicationExecuted appExec) { if (notification.State.Count != 1) { return; } var contractHash = notification.State[0].GetByteSafely(); diff --git a/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs b/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs index 72eb936f..01d30b99 100644 --- a/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs +++ b/neo3-gui/neo3-gui/Common/Scanners/ExecuteResultScanner.cs @@ -44,7 +44,7 @@ public async Task Start() { var span = DateTime.Now - _lastTime; Console.WriteLine($"Sync[{_lastHeight}-{_scanHeight}],cost:{span.TotalSeconds}"); - _lastTime=DateTime.Now; + _lastTime = DateTime.Now; _lastHeight = _scanHeight; } _scanHeight++; @@ -86,7 +86,7 @@ public async Task Sync(uint blockHeight) return true; } - + var block = blockHeight.GetBlock(); var blockTime = block.Timestamp.FromTimestampMS(); if (blockHeight == 0) @@ -111,17 +111,8 @@ public async Task Sync(uint blockHeight) Sender = transaction.Sender, Time = blockTime, }); - //var invokeMethods = GetInvokeMethods(transaction); - //if (invokeMethods.NotEmpty()) - //{ - // foreach (var invokeMethod in invokeMethods) - // { - // _db.AddInvokeTransaction(transaction.Hash, invokeMethod.Key, string.Join(',', invokeMethod.Value)); - // } - //} } - var transfers = new List(); var transferItems = _levelDb.GetTransfers(blockHeight); if (transferItems.NotEmpty()) @@ -138,6 +129,7 @@ public async Task Sync(uint blockHeight) Amount = item.Amount, Asset = item.Asset, Trigger = item.Trigger, + TokenId = item.TokenId }); } } diff --git a/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/TransferStorageItem.cs b/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/TransferStorageItem.cs index 35360661..275b2764 100644 --- a/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/TransferStorageItem.cs +++ b/neo3-gui/neo3-gui/Common/Storage/LevelDBModules/TransferStorageItem.cs @@ -16,5 +16,6 @@ public class TransferStorageItem public UInt160 Asset { get; set; } public UInt256 TxId { get; set; } public TriggerType Trigger { get; set; } + public string TokenId { get; set; } } } diff --git a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/SQLiteContext.cs b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/SQLiteContext.cs index 8dde662b..e5ed2559 100644 --- a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/SQLiteContext.cs +++ b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/SQLiteContext.cs @@ -23,7 +23,7 @@ public class SQLiteContext : DbContext public DbSet Identities { get; set; } public DbSet SyncIndexes { get; set; } - public DbSet Nep5Transactions { get; set; } + public DbSet Transfers { get; set; } public DbSet AssetBalances { get; set; } public DbSet Addresses { get; set; } public DbSet Transactions { get; set; } @@ -96,7 +96,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) DataSource = _filename }; optionsBuilder.UseSqlite(sb.ToString()); - //optionsBuilder.UseLoggerFactory(LoggerFactory.Create(b => b.AddConsole())); + optionsBuilder.UseLoggerFactory(LoggerFactory.Create(b => b.AddConsole())); } @@ -105,10 +105,10 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - modelBuilder.Entity().HasIndex(p => p.FromId); - modelBuilder.Entity().HasIndex(p => p.ToId); - modelBuilder.Entity().HasIndex(p => p.Time); - modelBuilder.Entity().HasIndex(p => p.TxId); + modelBuilder.Entity().HasIndex(p => p.FromId); + modelBuilder.Entity().HasIndex(p => p.ToId); + modelBuilder.Entity().HasIndex(p => p.Time); + modelBuilder.Entity().HasIndex(p => p.TxId); modelBuilder.Entity().HasIndex(p => p.Hash); diff --git a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransactionEntity.cs b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransactionEntity.cs index 92a4db50..babe7b5d 100644 --- a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransactionEntity.cs +++ b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransactionEntity.cs @@ -21,7 +21,7 @@ public class TransactionEntity public AddressEntity Sender { get; set; } public DateTime Time { get; set; } - public IList Transfers { get; set; } + public IList Transfers { get; set; } public IList InvokeContracts { get; set; } } } diff --git a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/Nep5TransferEntity.cs b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransferEntity.cs similarity index 89% rename from neo3-gui/neo3-gui/Common/Storage/SQLiteModules/Nep5TransferEntity.cs rename to neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransferEntity.cs index ce3a949a..b1ad8b6c 100644 --- a/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/Nep5TransferEntity.cs +++ b/neo3-gui/neo3-gui/Common/Storage/SQLiteModules/TransferEntity.cs @@ -5,8 +5,8 @@ namespace Neo.Common.Storage.SQLiteModules { - [Table("Nep5Transfers")] - public class Nep5TransferEntity + [Table("Transfers")] + public class TransferEntity { [Key] public long Id { get; set; } @@ -18,7 +18,6 @@ public class Nep5TransferEntity [ForeignKey(nameof(TxId))] public TransactionEntity Transaction { get; set; } - public long AssetId { get; set; } public ContractEntity Asset { get; set; } @@ -32,10 +31,11 @@ public class Nep5TransferEntity public byte[] Amount { get; set; } - public DateTime Time { get; set; } public TriggerType Trigger { get; set; } + public string TokenId { get; set; } + } } diff --git a/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs b/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs index e38f7ba7..f5cbab49 100644 --- a/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs +++ b/neo3-gui/neo3-gui/Common/Storage/TrackDB.cs @@ -18,7 +18,7 @@ public class TrackDB : IDisposable { private readonly uint _magic; private readonly SQLiteContext _sqldb; - private readonly LevelDbContext _leveldb; + public readonly LevelDbContext _leveldb; private readonly DateTime _createTime = DateTime.Now; public TimeSpan LiveTime => DateTime.Now - _createTime; @@ -152,7 +152,7 @@ public void AddTransfer(TransferInfo transfer) var to = GetOrCreateAddress(transfer.To); var asset = GetActiveContract(transfer.Asset); - var tran = new Nep5TransferEntity + var tran = new TransferEntity { BlockHeight = transfer.BlockHeight, TxId = transfer.TxId?.ToBigEndianHex(), @@ -162,8 +162,9 @@ public void AddTransfer(TransferInfo transfer) AssetId = asset.Id, Time = transfer.TimeStamp.FromTimestampMS(), Trigger = transfer.Trigger, + TokenId = transfer.TokenId, }; - _sqldb.Nep5Transactions.Add(tran); + _sqldb.Transfers.Add(tran); } @@ -363,7 +364,7 @@ public PageList QueryNep5Transactions(TransferFilter filter) var txIds = query.GroupBy(q => new { q.TxId, q.Time }).OrderByDescending(g => g.Key.Time).Select(g => g.Key) .Skip(pageIndex * filter.PageSize) .Take(filter.PageSize).Select(g => g.TxId).ToList(); - pageList.List.AddRange(query.Where(q => txIds.Contains(q.TxId)).OrderByDescending(r => r.Time).ToList().Select(ToNep5TransferInfo)); + pageList.List.AddRange(query.Where(q => txIds.Contains(q.TxId)).OrderByDescending(r => r.Time).ToList().Select(ToTransferInfo)); } return pageList; } @@ -385,7 +386,7 @@ public PageList QueryTransfers(TransferFilter filter) if (filter.PageSize > 0) { pageList.List.AddRange(query.OrderByDescending(r => r.Time).Skip(pageIndex * filter.PageSize) - .Take(filter.PageSize).ToList().Select(ToNep5TransferInfo)); + .Take(filter.PageSize).ToList().Select(ToTransferInfo)); } return pageList; } @@ -614,9 +615,9 @@ private AssetBalanceEntity GetOrCreateBalance(AddressEntity address, ContractEnt } - private IQueryable BuildQuery(TransferFilter filter) + private IQueryable BuildQuery(TransferFilter filter) { - IQueryable query = _sqldb.Nep5Transactions.Where(t => t.TxId != null) + IQueryable query = _sqldb.Transfers.Where(t => t.TxId != null) .Include(t => t.From) .Include(t => t.To) .Include(t => t.Asset).Where(t => t.Asset.DeleteTxId == null); @@ -624,17 +625,20 @@ private IQueryable BuildQuery(TransferFilter filter) if (filter.FromOrTo.NotEmpty()) { var addresses = filter.FromOrTo.Select(a => a.ToBigEndianHex()).ToList(); - query = query.Where(r => addresses.Contains(r.From.Hash) || addresses.Contains(r.To.Hash)); + var addressIds = _sqldb.Addresses.Where(a => addresses.Contains(a.Hash)).Select(a => a.Id).ToList(); + query = query.Where(r => addressIds.Contains(r.FromId.Value) || addressIds.Contains(r.ToId.Value)); } if (filter.From.NotEmpty()) { var addresses = filter.From.Select(a => a.ToBigEndianHex()).ToList(); - query = query.Where(r => addresses.Contains(r.From.Hash)); + var addressIds = _sqldb.Addresses.Where(a => addresses.Contains(a.Hash)).Select(a => a.Id).ToList(); + query = query.Where(r => addressIds.Contains(r.FromId.Value)); } if (filter.To.NotEmpty()) { var addresses = filter.To.Select(a => a.ToBigEndianHex()).ToList(); - query = query.Where(r => addresses.Contains(r.To.Hash)); + var addressIds = _sqldb.Addresses.Where(a => addresses.Contains(a.Hash)).Select(a => a.Id).ToList(); + query = query.Where(r => addressIds.Contains(r.ToId.Value)); } if (filter.StartTime != null) { @@ -662,7 +666,7 @@ private IQueryable BuildQuery(TransferFilter filter) } - private TransferInfo ToNep5TransferInfo(Nep5TransferEntity entity) + private TransferInfo ToTransferInfo(TransferEntity entity) { return new TransferInfo() { @@ -672,7 +676,7 @@ private TransferInfo ToNep5TransferInfo(Nep5TransferEntity entity) To = entity.To != null ? UInt160.Parse(entity.To.Hash) : null, Amount = new BigInteger(entity.Amount), Asset = UInt160.Parse(entity.Asset.Hash), - + TokenId = entity.TokenId, TimeStamp = entity.Time.AsUtcTime().ToTimestampMS(), }; } diff --git a/neo3-gui/neo3-gui/Helpers.cs b/neo3-gui/neo3-gui/Helpers.cs index 23e850ea..44a02fa9 100644 --- a/neo3-gui/neo3-gui/Helpers.cs +++ b/neo3-gui/neo3-gui/Helpers.cs @@ -935,53 +935,15 @@ public static TransferNotifyItem ConvertToTransfer(this NotifyEventArgs notifica Amount = amount.Value, Asset = notification.ScriptHash, }; - return record; - } - - - public static TransferNotifyItem GetTransferNotify(this VmArray notifyArray, UInt160 asset) - { - if (notifyArray.Count < 4) return null; - // Event name should be encoded as a byte array. - if (notifyArray[0].NotVmByteArray()) return null; - var eventName = notifyArray[0].GetString(); - if (!"Transfer".Equals(eventName, StringComparison.OrdinalIgnoreCase)) return null; - - var fromItem = notifyArray[1]; - if (fromItem.NotVmByteArray() && fromItem.NotVmNull()) return null; - - var fromBytes = fromItem.GetByteSafely(); - if (fromBytes?.Length != 20) + if (notify.Count == 4) { - fromBytes = null; + record.TokenId = notify[3].GetSpan().ToArray(); } - - var toItem = notifyArray[2]; - if (toItem != null && toItem.NotVmByteArray()) return null; - - byte[] toBytes = toItem.GetByteSafely(); - if (toBytes?.Length != 20) - { - toBytes = null; - } - if (fromBytes == null && toBytes == null) return null; - - var amountItem = notifyArray[3]; - if (amountItem.NotVmByteArray() && amountItem.NotVmInt()) return null; - - var transfer = new TransferNotifyItem() - { - Asset = asset, - From = fromBytes == null ? null : new UInt160(fromBytes), - To = new UInt160(toBytes), - Amount = amountItem.GetInteger(), - }; - return transfer; + return record; } - /// /// /// diff --git a/neo3-gui/neo3-gui/Models/TransferNotifyItem.cs b/neo3-gui/neo3-gui/Models/TransferNotifyItem.cs index a2f6ee6b..80fa35ee 100644 --- a/neo3-gui/neo3-gui/Models/TransferNotifyItem.cs +++ b/neo3-gui/neo3-gui/Models/TransferNotifyItem.cs @@ -13,6 +13,11 @@ public class TransferNotifyItem public UInt160 From { get; set; } public UInt160 To { get; set; } public BigInteger Amount { get; set; } + + /// + /// Nep11 Token + /// + public byte[] TokenId { get; set; } public string Symbol { get; set; } public byte Decimals { get; set; } } diff --git a/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs b/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs index 7e04d51f..805e15cf 100644 --- a/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs +++ b/neo3-gui/neo3-gui/Services/ApiServices/ContractApiService.cs @@ -266,7 +266,7 @@ public async Task InvokeContract(InvokeContractParameterModel para) Transaction tx = null; try { - tx = CurrentWallet.InitTransaction(sb.ToArray(), null, signers.ToArray()); + tx = CurrentWallet.InitTransaction(sb.ToArray(), signers?.FirstOrDefault()?.Account, signers.ToArray()); } catch (InvalidOperationException ex) { diff --git a/neo3-gui/neo3-gui/config.private.json b/neo3-gui/neo3-gui/config.private.json index f6b4d42e..2509ca6a 100644 --- a/neo3-gui/neo3-gui/config.private.json +++ b/neo3-gui/neo3-gui/config.private.json @@ -7,7 +7,7 @@ }, "Storage": { "Engine": "LevelDBStore", - "Path": "Data_LevelDB_330" + "Path": "Data_LevelDB_340" }, "P2P": { "Port": 30333, From b3ec0c862458de81c77b68fb9f5237948fcfd426 Mon Sep 17 00:00:00 2001 From: Shuai Date: Fri, 23 Sep 2022 14:21:18 +0800 Subject: [PATCH 2/2] contract invoke refac --- .../public/locales/en/translation.json | 8 +- .../public/locales/zh/translation.json | 8 +- .../ClientApp/src/components/Chain/asset.js | 2 + .../src/components/Chain/assetSearch.js | 92 ++++ .../src/components/Chain/blockdetail.js | 9 +- .../ClientApp/src/components/Chain/chain.js | 3 +- .../Chain/{searcharea.js => chainSearch.js} | 20 +- .../src/components/Chain/hashdetail.js | 115 ----- .../src/components/Common/dataConverter.js | 9 + .../src/components/Common/menudown.js | 1 - .../src/components/Common/parameterInput.js | 165 +++++++ .../src/components/Common/searcharea.js | 1 - .../src/components/Contract/invoke.js | 417 ++++++++---------- .../src/components/Contract/searcharea.js | 1 - .../src/components/Transaction/searcharea.js | 1 - .../src/components/Transaction/transaction.js | 19 +- .../ClientApp/src/components/Wallet/trans.js | 5 +- .../neo3-gui/ClientApp/src/core/request.js | 2 +- .../neo3-gui/ClientApp/src/router/router.js | 18 +- .../neo3-gui/Common/Consoles/MainService.cs | 79 ++-- .../Storage/SQLiteModules/SQLiteContext.cs | 2 +- neo3-gui/neo3-gui/Common/Storage/TrackDB.cs | 6 +- neo3-gui/neo3-gui/GuiStarter.cs | 18 +- .../ApiServices/ContractApiService.cs | 21 +- .../ApiServices/TransactionApiService.cs | 20 +- .../Services/ApiServices/WalletApiService.cs | 2 +- 26 files changed, 592 insertions(+), 452 deletions(-) create mode 100644 neo3-gui/neo3-gui/ClientApp/src/components/Chain/assetSearch.js rename neo3-gui/neo3-gui/ClientApp/src/components/Chain/{searcharea.js => chainSearch.js} (80%) delete mode 100644 neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js create mode 100644 neo3-gui/neo3-gui/ClientApp/src/components/Common/parameterInput.js diff --git a/neo3-gui/neo3-gui/ClientApp/public/locales/en/translation.json b/neo3-gui/neo3-gui/ClientApp/public/locales/en/translation.json index 6c09ef86..266a95a3 100644 --- a/neo3-gui/neo3-gui/ClientApp/public/locales/en/translation.json +++ b/neo3-gui/neo3-gui/ClientApp/public/locales/en/translation.json @@ -111,7 +111,8 @@ "transaction info": "Transaction Info", "transactions": "Transactions", "unconfirmed transactions": "Unconfirmed Transactions", - "witness": "Witness" + "witness": "Witness", + "search input-invalid": "input block is not exist" }, "button": { "cancel": "Cancel", @@ -194,11 +195,12 @@ "please input password": "Please input password", "please select file location": "Please select file location", "search": { - "chain-hint": "Pelese input height", + "chain-hint": "Please input height or hash", "check again": "Please check input", "hash unexist": "The hash not exist,please check again", "hash-hint": "Pelese input hash", - "height unexist": "The height not exist,please check again" + "height unexist": "The height not exist,please check again", + "asset-search-hint": "please input asset hash" }, "select account": "Select Address", "select path": "Select Path", diff --git a/neo3-gui/neo3-gui/ClientApp/public/locales/zh/translation.json b/neo3-gui/neo3-gui/ClientApp/public/locales/zh/translation.json index d53fb59c..c62c9a0e 100644 --- a/neo3-gui/neo3-gui/ClientApp/public/locales/zh/translation.json +++ b/neo3-gui/neo3-gui/ClientApp/public/locales/zh/translation.json @@ -111,7 +111,8 @@ "transaction info": "交易信息", "transactions": "交易列表", "unconfirmed transactions": "待确认交易", - "witness": "见证人" + "witness": "见证人", + "search input-invalid": "查询的区块不存在" }, "button": { "cancel": "取消", @@ -194,11 +195,12 @@ "please input password": "请输入密码", "please select file location": "请选择文件存储位置", "search": { - "chain-hint": "输入需要查找的 height", + "chain-hint": "输入需要查找的高度或Hash", "check again": "请检查输入是否正确", "hash unexist": "该合约hash不存在,请查证后再输入", "hash-hint": "输入需要查找的脚本散列", - "height unexist": "该高度不存在,请查证后再输入" + "height unexist": "该高度不存在,请查证后再输入", + "asset-search-hint": "请输入资产Hash" }, "select account": "选择地址", "select path": "选择路径", diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/asset.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/asset.js index 624eca55..9835dad1 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/asset.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/asset.js @@ -14,6 +14,7 @@ import Sync from "../sync"; import { withTranslation, useTranslation } from "react-i18next"; import { postAsync } from "../../core/request"; import "../../static/css/chain.css"; +import AssetSearch from "./assetSearch"; export default function ChainAsset() { const { Content } = Layout; @@ -78,6 +79,7 @@ export default function ChainAsset() { /> +
diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/assetSearch.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/assetSearch.js new file mode 100644 index 00000000..de49469a --- /dev/null +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/assetSearch.js @@ -0,0 +1,92 @@ +/* eslint-disable */ +import React from "react"; +import "antd/dist/antd.css"; +import { Input, message } from "antd"; +import Topath from "../Common/topath"; +import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; +import { withTranslation } from "react-i18next"; +import { postAsync } from "../../core/request"; + +@withTranslation() +class AssetSearch extends React.Component { + constructor(props) { + super(props); + this.state = { + size: "default", + path: "", + disabled: false, + cname: "search-content", + }; + } + addClass = (e) => { + this.stopPropagation(e); + this.setState({ + cname: "search-content height-sea show-child", + disabled: true, + }); + document.addEventListener("click", this.removeClass); + }; + removeClass = () => { + if (this.state.disabled) { + this.setState({ + cname: "search-content height-sea", + disabled: false, + }); + } + document.removeEventListener("click", this.removeClass); + setTimeout( + () => + this.setState({ + cname: "search-content", + disabled: false, + }), + 500 + ); + }; + stopPropagation(e) { + e.nativeEvent.stopImmediatePropagation(); + } + searchAsset = async () => { + const { t } = this.props; + let hash = this.refs.sinput.input.value.trim(); + if (!hash || hash.length != 42) { + message.info(t("search.check again")); + return; + } + let response = await postAsync("GetContract", { + contractHash: hash, + }); + if (response.msgType === -1) { + message.info(t("search.check again")); + return; + } + this.setState({ topath: "/chain/asset:" + hash }); + }; + render = () => { + const { t } = this.props; + return ( +
+ +
+ +
+
+
+ } + /> +
+
+
+ ); + }; +} + +export default AssetSearch; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/blockdetail.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/blockdetail.js index c1c6ca4d..b22e69e0 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/blockdetail.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/blockdetail.js @@ -16,7 +16,8 @@ export default function BlockDetail() { const [height, setHeight] = useState(0); const [blockdetail, setBlockDetail] = useState({}); const [translist, setTransList] = useState([]); - let blockHeight = Number(location.pathname.split(":").pop()); + let identity = location.pathname.split(":").pop(); + let blockHeight = Number(identity); useEffect(() => { postAsync("GetBlock", { index: blockHeight }) .then(function (data) { @@ -25,9 +26,6 @@ export default function BlockDetail() { return; } setBlockDetail(data.result); - }) - .catch(function (error) { - console.log(error); }); postAsync("QueryTransactions", { blockHeight: blockHeight, limit: 500, }) @@ -37,9 +35,6 @@ export default function BlockDetail() { return; } setTransList(msg.result.list); - }) - .catch(function (error) { - console.log(error); }); }, [height]); return ( diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js index b356ad7a..7501a77a 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chain.js @@ -12,10 +12,9 @@ import { Button, PageHeader, } from "antd"; -import Chainsearch from "./searcharea"; +import Chainsearch from "./chainSearch"; import Sync from "../sync"; import { withTranslation } from "react-i18next"; - import "../../static/css/contract.css"; import { postAsync } from "../../core/request"; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chainSearch.js similarity index 80% rename from neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js rename to neo3-gui/neo3-gui/ClientApp/src/components/Chain/chainSearch.js index aa36060e..0427ea2c 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/chainSearch.js @@ -1,7 +1,6 @@ /* eslint-disable */ import React from "react"; import "antd/dist/antd.css"; -import axios from "axios"; import { Input, message } from "antd"; import Topath from "../Common/topath"; import { ArrowRightOutlined, SearchOutlined } from "@ant-design/icons"; @@ -49,19 +48,24 @@ class Chainsearch extends React.Component { } searchChain = async () => { const { t } = this.props; - let _height = Number(this.refs.sinput.input.value.trim()); - if (!_height && _height != 0) { + let input = this.refs.sinput.input.value.trim(); + let blockHeight = 0; + let blockHash = null; + if (input.length == 66) { + blockHash = input + } else { + blockHeight = Number(input); + } + if (!input) { message.info(t("search.check again")); return; } - let response = await postAsync("GetBlock", { - index: _height, - }); + let response = !blockHash ? (await postAsync("GetBlock", { index: blockHeight })) : (await postAsync("GetBlockByHash", { hash: blockHash })); if (response.msgType === -1) { - message.info(t("blockchain.height unexist")); + message.info(t("blockchain.search input-invalid")); return; } - this.setState({ topath: "/chain/detail:" + _height }); + this.setState({ topath: "/chain/detail:" + response.result.blockHeight }); }; render = () => { const { t } = this.props; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js b/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js deleted file mode 100644 index 8e53eb19..00000000 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Chain/hashdetail.js +++ /dev/null @@ -1,115 +0,0 @@ -/* eslint-disable */ -//just test replace wallet// -import React from 'react'; -import { Link } from 'react-router-dom'; -import { Layout, Row, Col, message, List, Typography, PageHeader } from 'antd'; -import Sync from '../sync'; -import { postAsync } from '../../core/request'; - -const { Content } = Layout; - -class Blockdetail extends React.Component { - constructor(props) { - super(props); - this.state = { - blockdetail: {}, - hash: "", - witness: "", - nonce: 0, - }; - } - componentDidMount() { - let _h = location.pathname.split(":").pop(); - this.setHash(_h)(); - this.setState({ - local: location.pathname - }) - } - getAllblock = async () => { - let _hash = this.state.hash; - let response = await postAsync("GetBlockByHash", { - "hash": _hash - }); - if (response.msgType === -1) { - message.error("查询失败,该hash错误"); - return; - } - this.setState({ - blockdetail: response.result, - witness: response.result.witness.scriptHash, - nonce: response.result.consensusData.nonce, - translist: response.result.transactions - }); - } - setHash = (h) => { - return () => { - this.setState({ - hash: h - }, () => this.getAllblock()); - } - } - render() { - const { blockdetail, witness, nonce, translist, local } = this.state; - return ( - - - - - - -
-
Hash:    {blockdetail.blockHash}
- - -
    -
  • 高度:{blockdetail.blockHeight}
  • -
  • 时间戳:{blockdetail.blockTime}
  • -
  • 网络费:{blockdetail.networkFee ? blockdetail.networkFee : '--'}
  • -
  • 确认数:{blockdetail.confirmations}
  • -
- - -
    -
  • 大小:{blockdetail.blockHeight}
  • -
  • 随机数:{nonce}
  • -
  • 系统费:{blockdetail.networkFee ? blockdetail.networkFee : '--'}
  • -
  • 见证人:{witness}
  • -
- -
-
- -
- - - - 交易hash数量时间} - footer={} - itemLayout="horizontal" - dataSource={translist} - className="font-s" - renderItem={item => ( - - {item.txId}} - description={ -
- From:{item.transfers[0].fromAddress ? item.transfers[0].fromAddress : "--"}

- To:{item.transfers[0].toAddress ? item.transfers[0].toAddress : "--"} -
} - /> - {item.blockTime} - {item.transfers[0].amount}{item.transfers[0].symbol} -
- )} - /> - -
-
-
- ); - } -} - -export default Blockdetail; \ No newline at end of file diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/dataConverter.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/dataConverter.js index 3730a92e..3d9fb133 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Common/dataConverter.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/dataConverter.js @@ -48,6 +48,15 @@ class DataConverter { return Buffer.from(hexString, "hex").toString("base64"); } + + /** + * input: 'Y6OYnLSplXGqADltPHFV+upAmLo=',output:'63a3989cb4a99571aa00396d3c7155faea4098ba' + * @param {*} base64String + */ + fromBase64String(base64String) { + return Buffer.from(base64String, "base64").toString("hex"); + } + /** * Encode hex string to utf8 string,input:'7472616e73666572',output:'transfer' * @param {*} hexString diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js index 81118f98..c045fc03 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/menudown.js @@ -4,7 +4,6 @@ import { observer, inject } from "mobx-react"; import { withRouter } from "react-router-dom"; import "antd/dist/antd.css"; import { message, Modal, Radio } from "antd"; -import axios from "axios"; import { Addressdetail, Changepass, Setting } from "./menuaction"; import { ReadOutlined, diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/parameterInput.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/parameterInput.js new file mode 100644 index 00000000..b3f18d59 --- /dev/null +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/parameterInput.js @@ -0,0 +1,165 @@ +import React from "react"; +import { Input, PageHeader, Modal, Select, Row, Col, Form, message, Button, } from "antd"; +import DataConverter from "./dataConverter"; + + +class ParameterInput extends React.Component { + constructor(props) { + super(props); + this.dataConverter = new DataConverter(); + //select type + // let type = this.props.type; + this.initComponentModel(); + console.log("init ParameterInput", this.props); + this.state = { + options: this.options || [], + }; + } + + initComponentModel = () => { + const { type } = this.props; + switch (type) { + case "ByteArray": + this.options = ["HexString", "ByteArray", "String", "Integer"]; + // if (value) { + // this.hexValue = this.dataConverter.toBase64String(value); + // if (value.length == 40) { + // this.options.push("Hash160"); + // this.options.push("Address"); + // } + // if (value.length == 64) { + // this.options.push("Hash256"); + // } + // } + break; + case "Hash160": + this.options = ["Hash160", "Address"]; + // if (value) { + // this.hexValue = value; + // } + break; + case "String": + this.options = ["ByteArray", "String"]; + // if (value) { + // this.hexValue = this.dataConverter.fromUtf8String(value); + // } + break; + case "Integer": + this.options = ["ByteArray", "Integer"]; + // if (value) { + // let hexInt = BigInt(value).toString(16); + // if (hexInt.startsWith("-")) { + // //unsupport negative number + // return; + // } + // if (hexInt.length & 1) { + // hexInt = "0" + hexInt; + // } + // this.hexValue = this.dataConverter.reverseHexString(hexInt); + // } + break; + case "Any": + this.options = ["HexString", "ByteArray", "String", "Integer", "Hash160", "Address", "Array"]; + break; + default: + this.options = [type]; + break; + } + }; + + // setValue = (val) => { + // this.setState({ value: val }); + // }; + + // onChangeType = (e) => { + // const { type } = this.props; + // const newType = e; + // if (!this.hexValue) { + // return; + // } + // switch (newType) { + // case "Address": + // this.value = this.dataConverter.toAddress(this.hexValue); + // break; + // case "ByteArray": + // this.value = this.hexValue; + // break; + // case "Hash160": + // case "Hash256": + // this.value = "0x" + this.dataConverter.reverseHexString(this.hexValue); + // break; + // case "Base64": + // this.value = this.dataConverter.toBase64String(this.hexValue); + // break; + // case "String": + // this.value = this.dataConverter.toUtf8String(this.hexValue); + // break; + // case "Integer": + // this.value = this.dataConverter.toBigInt(this.hexValue).toString(10); + // break; + // } + // this.type = newType; + // this.setValue(this.value); + // } + + // onChangeValue = (e) => { + // let type = this.type; + // let value = e.currentTarget.value; + // if (!value) { + // this.hexValue = null; + // return; + // } + // switch (type) { + // case "ByteArray": + // this.hexValue = this.dataConverter.fromBase64String(value); + // break; + // case "Hash160": + // case "Hash256": + // this.hexValue = this.dataConverter.reverseHexString(value.replace('0x', '')); + // break; + // case "String": + // this.hexValue = this.dataConverter.fromUtf8String(value); + // break; + // case "Integer": + // this.hexValue = value.toString(16); + // break; + // case "Address": + // let scriptHash = this.dataConverter.toScriptHash(value); + // this.hexValue = this.dataConverter.reverseHexString(scriptHash.replace('0x', '')); + // break; + // } + // console.log(e); + // } + + render = () => { + const { name, type } = this.props; + const { options } = this.state; + return ( + {name}} > + + + + + + + + + + ); + }; +} + +export default ParameterInput; \ No newline at end of file diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js b/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js index 18e47e68..db7b0452 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Common/searcharea.js @@ -2,7 +2,6 @@ import React, { useState } from "react"; import "antd/dist/antd.css"; import { useHistory } from "react-router-dom"; -import axios from "axios"; import { Input, message } from "antd"; import Topath from "../Common/topath"; import { post, postAsync } from "../../core/request"; diff --git a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/invoke.js b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/invoke.js index c76b4536..eea13458 100644 --- a/neo3-gui/neo3-gui/ClientApp/src/components/Contract/invoke.js +++ b/neo3-gui/neo3-gui/ClientApp/src/components/Contract/invoke.js @@ -21,8 +21,11 @@ import { SwapOutlined } from "@ant-design/icons"; import { withRouter } from "react-router-dom"; import { withTranslation } from "react-i18next"; import DynamicArray from "./dynamicArray"; -import { post } from "../../core/request"; +import { post, postAsync } from "../../core/request"; import { MinusSquareOutlined, PlusOutlined } from "@ant-design/icons"; +import ParameterInput from "../Common/parameterInput"; +import { createRef } from "react"; +import FormItem from "antd/lib/form/FormItem"; const { Option } = Select; @@ -42,47 +45,33 @@ const typeOption = ["ByteArray", "Address", "Hash160"]; class Contractinvoke extends React.Component { constructor(props) { super(props); + this.myForm = createRef(); this.state = { size: 'default', - path:"", - disabled:false, - visible: false, - modal:false, - loading:false, - methods:[], - params:[], - methodselect:"" - }; - } - toHome = () =>{ - location.href=location.origin; - } - showDrawer = () => { - this.setState({ - visible: true, - }); + path: "", + disabled: false, + visible: false, + modal: false, + loading: false, + methods: [], + params: [], + methodselect: "" }; - onClose = () => { - this.setState({ - visible: false, - }); - }; - showDetail = () =>{ - this.searchContract(res=>{ - this.refs.formRef.resetFields() - this.setState({ - hash:res.contractHash, - methods:res.manifest.abi.methods, - params:[], - tresult:"" - }) - this.refs.formRef.setFieldsValue({ - guihash:this.state.hash - }) - }); - console.log(this.refs.formRef); + } + toHome = () => { + location.href = location.origin; + } + showDrawer = () => { + this.setState({ + visible: true, + }); + }; + onClose = () => { + this.setState({ + visible: false, + }); }; - searchContract = (callback) => { + searchContract = async () => { const { t } = this.props; let _hash = this.refs.sinput.input.value.trim(); if (!_hash) { @@ -90,33 +79,42 @@ class Contractinvoke extends React.Component { return; } this.setState({ loading: true }); - var _this = this; var params = { contractHash: _hash }; - post("GetContract", params) - .then(function (response) { - var _data = response.data; - _this.setState({loading:false}); - if(_data.msgType === -1){ - _this.setState({ - methods: [], - params: [], - tresult: "", - }); - _this.refs.formRef.resetFields(); - _this.refs.formRef.setFieldsValue({ - guihash: _hash, - }); - message.info(t("contract.search fail")); - return; - }else if(_data.msgType === 3){ - callback(_data.result) - } - }) - .catch(function (error) { - console.log(error); + let response = await postAsync("GetContract", params); + this.setState({ loading: false }); + if (response.msgType === -1) { + this.setState({ + methods: [], + params: [], + tresult: "", + }); + this.myForm.current.resetFields(); + this.myForm.current.setFieldsValue({ + guihash: _hash, }); + message.info(t("contract.search fail")); + return; + } + + let result = response.result; + this.myForm.current.resetFields() + this.setState({ + hash: result.contractHash, + methods: result.manifest.abi.methods, + params: [], + tresult: "" + }) + this.myForm.current.setFieldsValue({ + guihash: this.state.hash + }) + // callback(response.result); }; showPara = (e) => { + this.myForm.current.resetFields(); + this.myForm.current.setFieldsValue({ + guihash: this.state.hash, + guimethod: e, + }); this.setState({ params: this.state.methods[e].parameters, methodselect: this.state.methods[e], @@ -124,7 +122,6 @@ class Contractinvoke extends React.Component { }; makeParams = (data) => { let method = this.state.methodselect; - let _params = { contractHash: this.state.hash, method: method.name, @@ -136,44 +133,44 @@ class Contractinvoke extends React.Component { let inside = new Array(); this.state.params.map((item, index) => { //深拷贝 - let _item = JSON.parse(JSON.stringify(item)); + let parameterItem = JSON.parse(JSON.stringify(item)); + let value = data[parameterItem.name]; - let _type = method.parameters[index].type.toLowerCase(); - _item.value = data[_item.name]; + //检测字符串中是否包含两种类型值 + // if (_type.search(/(hash160)|(bytearray)/g) !== -1 && typeof _item.value === "object") { + // _item.type = _item.value.type; + // _item.value = _item.value.value; + // } - //检测字符串中是否包含两种类型值 - if(_type.search(/(hash160)|(bytearray)/g) !== -1 && typeof _item.value === "object"){ - _item.type = _item.value.type; - _item.value = _item.value.string; - } + if (value.type === 'Array') { + value.value = JSON.parse(value.value); + } + if (value.type) { + parameterItem.type = value.type; + parameterItem.value = value.value; + } else { + parameterItem.value = value; + } - if(_type === 'any'){ - _item.type = 'String'; - _item.value = _item.value; - } - - if(_type === 'array'){ - _item.value = JSON.parse(_item.value); - } - inside = inside.concat(_item); - }) - if(inside) _params.parameters = inside; + inside = inside.concat(parameterItem); + }) + if (inside) _params.parameters = inside; //构造consigners let cosigners = new Array(); data.cosigners ? data.cosigners.map((item) => { - let _list = {}; - _list.account = item; - cosigners = cosigners.concat(_list); - }) + let _list = {}; + _list.account = item; + cosigners = cosigners.concat(_list); + }) : null; if (cosigners) _params.cosigners = cosigners; return _params; }; onFill = () => { - this.refs.formRef.setFieldsValue({ + this.myForm.current.setFieldsValue({ tresult: this.state.tresult, }); }; @@ -185,7 +182,7 @@ class Contractinvoke extends React.Component { }, this.onFill() ); - this.refs.formRef + this.myForm.current .validateFields() .then((data) => { let params = this.makeParams(data); @@ -216,7 +213,7 @@ class Contractinvoke extends React.Component { }, _this.onFill() ); - _this.refs.formRef.resetFields(); + _this.myForm.current.resetFields(); Modal.success({ title: t("contract.invoke contract"), @@ -233,56 +230,50 @@ class Contractinvoke extends React.Component { }); }); }; - invokeContract = (params, callback) => { + + invokeContract = async (params, callback) => { const { t } = this.props; - post("InvokeContract", params) - .then(function (res) { - var _data = res.data; - if (_data.msgType === -1) { - Modal.error({ - title: t("contract.fail title"), - width: 600, - content: ( -
-

- {t("error code")}: {_data.error.code} -

-

- {t("error msg")}: {_data.error.message} -

-
- ), - okText: t("button.ok"), - }); - return; - } else if (_data.msgType === 3) { - callback(_data); - } - }) - .catch(function (error) { - console.log(error); - }); - } - handleCancel = () => { - this.setState({ - modal: false, - }); - }; - makeArray = () =>{ - this.setState({ - modal: true + let response = await postAsync("InvokeContract", params); + if (response.msgType === -1) { + Modal.error({ + title: t("contract.fail title"), + width: 600, + content: ( +
+

+ {t("error code")}: {response.error.code} +

+

+ {t("error msg")}: {response.error.message} +

+
+ ), + okText: t("button.ok"), }); + return; } - handleparam = (val) =>{ - if(val.length <= 0) return ""; - this.handleCancel() - return JSON.stringify(val); - } - onOk = () => { - form.submit(); - }; - render = () =>{ - const {methods,params,disabled} = this.state; + callback(response); + } + handleCancel = () => { + this.setState({ + modal: false, + }); + }; + makeArray = () => { + this.setState({ + modal: true + }); + } + handleparam = (val) => { + if (val.length <= 0) return ""; + this.handleCancel() + return JSON.stringify(val); + } + onOk = () => { + form.submit(); + }; + render = () => { + const { methods, params, disabled } = this.state; const accounts = this.props.walletStore.accountlist; const { t } = this.props; return ( @@ -302,7 +293,7 @@ class Contractinvoke extends React.Component { {/* */} - + { return ( -
- {item.type.toLowerCase() === "bytearray" || - item.type.toLowerCase() == "hash160" ? ( - {item.name}} - > - - - - - - - - - +
+ {item.type.toLowerCase() === "bytearray" || item.type.toLowerCase() == "hash160" || item.type.toLowerCase() === 'any' ? ( + ) : ( :} */} - {item.type.toLowerCase() === 'any'? - : - } - ) - } -
- )} - )} - - + ) + } +
) - })} - + } + )} + + + + + + + +
+ + - - - - - - - - -
-

{t('contract.test result')}

-