From b3ec0c862458de81c77b68fb9f5237948fcfd426 Mon Sep 17 00:00:00 2001 From: Shuai Date: Fri, 23 Sep 2022 14:21:18 +0800 Subject: [PATCH] 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')}

-