From 0568a0efe282af9a0c381cc998d782ddb880267f Mon Sep 17 00:00:00 2001 From: "hhyyy9@qq.com" Date: Fri, 1 Apr 2022 10:33:37 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9TransService=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8constant=E5=85=B3=E9=94=AE=20?= =?UTF-8?q?=E5=AD=97=E4=B8=8B=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8msg.sende?= =?UTF-8?q?r=E5=AF=B9=E5=90=88=E7=BA=A6=E8=BF=9B=E8=A1=8C=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../front/transaction/TransService.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/webank/webase/front/transaction/TransService.java b/src/main/java/com/webank/webase/front/transaction/TransService.java index 9c99908ea..1b91aafbb 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -499,11 +499,10 @@ public Object transHandleLocal(ReqTransHandle req) { CryptoKeyPair cryptoKeyPair = getCredentials(isTxConstant, userAddress); Client client = web3ApiService.getWeb3j(groupId); - if (isTxConstant) { - if (StringUtils.isBlank(userAddress)) { - userAddress = cryptoKeyPair.getAddress(); - } +// if (StringUtils.isBlank(userAddress)) { +// userAddress = cryptoKeyPair.getAddress(); +// } return this.handleCall(groupId, userAddress, contractAddress, encodeFunction, abiStr, funcName); } else { return this.handleTransaction(client, cryptoKeyPair, contractAddress, encodeFunction); @@ -624,11 +623,16 @@ public static ABIDefinition getFunctionAbiDefinition(String functionName, String private CryptoKeyPair getCredentials(boolean constant, String keyUser) { // get privateKey CryptoKeyPair credentials; - if (constant) { + // TODO constant不能使用msg.sender调用合约问题。 + // 注释了constant随机生成秘钥 + System.out.println("修改了constant不能使用msg.sender调用合约问题"); + if (StringUtils.isBlank(keyUser)) { +// if (constant) { credentials = keyStoreService.getCredentialsForQuery(); } else { credentials = keyStoreService.getCredentials(keyUser); } + return credentials; } @@ -836,10 +840,20 @@ private ABIDefinition getABIDefinition(String abiStr, String functionName) { public List handleCall(int groupId, String userAddress, String contractAddress, String encodedFunction, String abiStr, String funcName) { + // TODO constant不能使用msg.sender调用合约问题。 + // 注释掉随机生成秘钥,采用用户地址生成 + System.out.println("修改了constant不能使用msg.sender调用合约问题"); + TransactionProcessor transactionProcessor; + if (StringUtils.isBlank(userAddress)) { + transactionProcessor = new TransactionProcessor( + web3ApiService.getWeb3j(groupId), keyStoreService.getCredentialsForQuery(), + groupId, Constants.chainId); + }else{ + transactionProcessor = new TransactionProcessor( + web3ApiService.getWeb3j(groupId), keyStoreService.getCredentials(userAddress), + groupId, Constants.chainId); + } - TransactionProcessor transactionProcessor = new TransactionProcessor( - web3ApiService.getWeb3j(groupId), keyStoreService.getCredentialsForQuery(), - groupId, Constants.chainId); CallOutput callOutput = transactionProcessor .executeCall(userAddress, contractAddress, encodedFunction) .getCallResult(); From ed4af9f01c331b9fb457e75e8a519bb0eb6a9f22 Mon Sep 17 00:00:00 2001 From: "hhyyy9@qq.com" Date: Fri, 1 Apr 2022 10:35:43 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9TransService=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8constant=E5=85=B3=E9=94=AE=20?= =?UTF-8?q?=E5=AD=97=E4=B8=8B=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8msg.sende?= =?UTF-8?q?r=E5=AF=B9=E5=90=88=E7=BA=A6=E8=BF=9B=E8=A1=8C=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/webank/webase/front/transaction/TransService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/webank/webase/front/transaction/TransService.java b/src/main/java/com/webank/webase/front/transaction/TransService.java index 1b91aafbb..3fb21954f 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -625,6 +625,7 @@ private CryptoKeyPair getCredentials(boolean constant, String keyUser) { CryptoKeyPair credentials; // TODO constant不能使用msg.sender调用合约问题。 // 注释了constant随机生成秘钥 + System.out.println("修改了constant不能使用msg.sender调用合约问题"); if (StringUtils.isBlank(keyUser)) { // if (constant) { From 9ecb582a6b9a2351251a2d56ab81aa006eb4e7ff Mon Sep 17 00:00:00 2001 From: farmer <85018486+CN-GaoXuLiang@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:06:36 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=20=E6=96=B0=E5=A2=9E16=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E7=A7=81=E9=92=A5=E8=BD=AC10=E8=BF=9B=E5=88=B6=E7=A7=81?= =?UTF-8?q?=E9=92=A5=E7=9A=84tool=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WeBASE-Front/tool/hexKey2Dec --- .../com/webank/webase/front/tool/ToolController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/webank/webase/front/tool/ToolController.java b/src/main/java/com/webank/webase/front/tool/ToolController.java index 33c8cfe99..20153ccc8 100644 --- a/src/main/java/com/webank/webase/front/tool/ToolController.java +++ b/src/main/java/com/webank/webase/front/tool/ToolController.java @@ -222,5 +222,14 @@ public RspSignData getSignedData(@Valid @RequestBody ReqSign reqSign) { return new RspSignData(signatureData, cryptoSuite.cryptoTypeConfig); } + @ApiOperation(value = "hex privateKey to decimal ", notes = "get decimal PrivateKey") + @ApiImplicitParam(name = "hexPrivateKey", value = "hex private key", dataType = "String") + @GetMapping("/hexKey2Dec") + public String hexKey2Dec(@RequestParam String hexPrivateKey) { + if (hexPrivateKey.startsWith("0x")){ + hexPrivateKey = hexPrivateKey.substring(2); + } + return new BigInteger(hexPrivateKey,16).toString(); + } } From 66e013aa95ef1600dfdd15d47307c80e2e9a2bfd Mon Sep 17 00:00:00 2001 From: codingcattwo <847701726@qq.com> Date: Mon, 18 Apr 2022 10:53:33 +0800 Subject: [PATCH 04/16] optimize community constant tx random user or targe user bug --- .../front/transaction/TransService.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/webank/webase/front/transaction/TransService.java b/src/main/java/com/webank/webase/front/transaction/TransService.java index 3fb21954f..65b1643f2 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -500,9 +500,9 @@ public Object transHandleLocal(ReqTransHandle req) { Client client = web3ApiService.getWeb3j(groupId); if (isTxConstant) { -// if (StringUtils.isBlank(userAddress)) { -// userAddress = cryptoKeyPair.getAddress(); -// } + if (StringUtils.isBlank(userAddress)) { + userAddress = cryptoKeyPair.getAddress(); + } return this.handleCall(groupId, userAddress, contractAddress, encodeFunction, abiStr, funcName); } else { return this.handleTransaction(client, cryptoKeyPair, contractAddress, encodeFunction); @@ -621,15 +621,21 @@ public static ABIDefinition getFunctionAbiDefinition(String functionName, String * get CryptoKeyPair by keyUser locally */ private CryptoKeyPair getCredentials(boolean constant, String keyUser) { + log.info("getCredentials constant:{},keyUser:{}", constant, keyUser); // get privateKey CryptoKeyPair credentials; - // TODO constant不能使用msg.sender调用合约问题。 - // 注释了constant随机生成秘钥 - - System.out.println("修改了constant不能使用msg.sender调用合约问题"); - if (StringUtils.isBlank(keyUser)) { -// if (constant) { + // TODO constant不能使用msg.sender调用合约问题 + if (constant) { credentials = keyStoreService.getCredentialsForQuery(); + // 非空,尝试从db获取user的credential,否则就随机 + if (StringUtils.isNotBlank(keyUser)) { + try { + credentials = keyStoreService.getCredentials(keyUser); + log.info("getCredentials constant, now return db keyUser:{}", credentials.getAddress()); + } catch (FrontException ex) { + log.warn("getCredentials constant, now return random:{}", credentials.getAddress()); + } + } } else { credentials = keyStoreService.getCredentials(keyUser); } @@ -842,19 +848,10 @@ private ABIDefinition getABIDefinition(String abiStr, String functionName) { public List handleCall(int groupId, String userAddress, String contractAddress, String encodedFunction, String abiStr, String funcName) { // TODO constant不能使用msg.sender调用合约问题。 - // 注释掉随机生成秘钥,采用用户地址生成 - System.out.println("修改了constant不能使用msg.sender调用合约问题"); - TransactionProcessor transactionProcessor; - if (StringUtils.isBlank(userAddress)) { - transactionProcessor = new TransactionProcessor( - web3ApiService.getWeb3j(groupId), keyStoreService.getCredentialsForQuery(), - groupId, Constants.chainId); - }else{ - transactionProcessor = new TransactionProcessor( - web3ApiService.getWeb3j(groupId), keyStoreService.getCredentials(userAddress), - groupId, Constants.chainId); - } - + TransactionProcessor transactionProcessor = new TransactionProcessor( + web3ApiService.getWeb3j(groupId), + getCredentials(true, userAddress), // 尝试db获取该address的私钥,否则随机创建 + groupId, Constants.chainId); CallOutput callOutput = transactionProcessor .executeCall(userAddress, contractAddress, encodedFunction) .getCallResult(); From 9f0a08d9f0cd32046d0c0bc34c1f3252116516ad Mon Sep 17 00:00:00 2001 From: farmer <85018486+CN-GaoXuLiang@users.noreply.github.com> Date: Mon, 18 Apr 2022 11:42:28 +0800 Subject: [PATCH 05/16] Update ToolController.java --- src/main/java/com/webank/webase/front/tool/ToolController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/webank/webase/front/tool/ToolController.java b/src/main/java/com/webank/webase/front/tool/ToolController.java index 20153ccc8..fa8d3fafd 100644 --- a/src/main/java/com/webank/webase/front/tool/ToolController.java +++ b/src/main/java/com/webank/webase/front/tool/ToolController.java @@ -32,6 +32,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import javax.validation.Valid; +import java.math.BigInteger; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.fisco.bcos.sdk.abi.ABICodec; From 78f10aa6eae870a787c7a4b1bf62dee0c89bd22e Mon Sep 17 00:00:00 2001 From: jiahao Date: Fri, 13 May 2022 10:32:51 +0800 Subject: [PATCH 06/16] fix [#744] --- web/src/components/sendTransaction.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/components/sendTransaction.vue b/web/src/components/sendTransaction.vue index e271cdd93..0d9a89ed9 100644 --- a/web/src/components/sendTransaction.vue +++ b/web/src/components/sendTransaction.vue @@ -206,7 +206,7 @@ export default { trigger: "blur", }, { - pattern: /^-?[1-9]\d*$/, + pattern: /^-?[0-9]\d*$/, message: "必须是数字,可以是负数", trigger: "blur", }, @@ -225,7 +225,7 @@ export default { trigger: "blur", }, { - pattern: /^[1-9]\d*$/, + pattern: /^[0-9]\d*$/, message: "必须是数字,不可以是负数", trigger: "blur", }, @@ -237,7 +237,7 @@ export default { trigger: "blur", }, { - pattern: /^-?[1-9]\d*$/, + pattern: /^-?[0-9]\d*$/, message: "必须是数字,可以是负数", trigger: "blur", }, @@ -282,7 +282,7 @@ export default { trigger: "blur", }, { - pattern: /^[1-9]\d*$/, + pattern: /^[0-9]\d*$/, message: "必须是数字,不可以是负数", trigger: "blur", }, From 19e2c124c2d441e8c8077ff6db27750fca6d2a13 Mon Sep 17 00:00:00 2001 From: konglj Date: Wed, 25 May 2022 14:09:42 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E6=A0=A1=E9=AA=8Cint/uint/uint256?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=AD=A3=E5=88=99?= =?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=88=E5=BD=93=E5=89=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BB=A3=E7=A0=81=E4=B8=BA1-9=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BE=93=E5=85=A5=E5=8F=82=E6=95=B0=E4=B8=BA?= =?UTF-8?q?0=EF=BC=8C=E5=8D=B3=E6=94=AF=E6=8C=810-9=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/sendTransaction.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/components/sendTransaction.vue b/web/src/components/sendTransaction.vue index e271cdd93..0d9a89ed9 100644 --- a/web/src/components/sendTransaction.vue +++ b/web/src/components/sendTransaction.vue @@ -206,7 +206,7 @@ export default { trigger: "blur", }, { - pattern: /^-?[1-9]\d*$/, + pattern: /^-?[0-9]\d*$/, message: "必须是数字,可以是负数", trigger: "blur", }, @@ -225,7 +225,7 @@ export default { trigger: "blur", }, { - pattern: /^[1-9]\d*$/, + pattern: /^[0-9]\d*$/, message: "必须是数字,不可以是负数", trigger: "blur", }, @@ -237,7 +237,7 @@ export default { trigger: "blur", }, { - pattern: /^-?[1-9]\d*$/, + pattern: /^-?[0-9]\d*$/, message: "必须是数字,可以是负数", trigger: "blur", }, @@ -282,7 +282,7 @@ export default { trigger: "blur", }, { - pattern: /^[1-9]\d*$/, + pattern: /^[0-9]\d*$/, message: "必须是数字,不可以是负数", trigger: "blur", }, From 37ff00517883bf6f13dce08ce90c9a17a492afd8 Mon Sep 17 00:00:00 2001 From: Skkypy Date: Wed, 24 Aug 2022 15:17:06 +0800 Subject: [PATCH 08/16] =?UTF-8?q?WeBASE=20Task=202:=20struct=20Tuple?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=85=A5=E5=8F=82=E5=A2=9E=E5=8A=A0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/lang/en.js | 2 +- web/src/lang/zh.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/lang/en.js b/web/src/lang/en.js index 60ef92163..a199c7480 100644 --- a/web/src/lang/en.js +++ b/web/src/lang/en.js @@ -420,7 +420,7 @@ export default { folderSameFail: "The new folder has the same name as the existing folder", user: "User", params: "Params", - paramsInfo: 'If the parameter type is an array, enter the following format, comma separated, with double quotes for non-numeric and Boolean values, such as ["aaa","bbb"] and [100,101]; Escape if array parameters contain double quotes, for example: ["aaa\\"bbb","ccc"].', + paramsInfo: 'If the parameter type is an array, struct or tuple, enter the following format, comma separated, with double quotes for non-numeric and Boolean values, such as ["aaa","bbb"] and [100,101]; Escape if array, struct or tuple parameters contain double quotes, for example: ["aaa\\"bbb","ccc"].', contractAddress: "Address", method: "Method", contractAddressInput: "Please enter the correct contract address", diff --git a/web/src/lang/zh.js b/web/src/lang/zh.js index 40b249b14..601f9cbd0 100644 --- a/web/src/lang/zh.js +++ b/web/src/lang/zh.js @@ -422,7 +422,7 @@ export default { folderSameFail: "新建文件夹与已存在的文件夹名称相同", user: "用户", params: "参数", - paramsInfo: '如果参数类型是数组,请按照以下格式输入,以逗号分隔,非数值和布尔值须使用双引号,例如:["aaa","bbb"]和[100,101];如果数组参数包含双引号,需转义,例如:["aaa\\"bbb","ccc"]。', + paramsInfo: '如果参数类型是数组、Struct或Tuple,请按照以下格式输入,以逗号分隔,非数值和布尔值须使用双引号,例如:["aaa","bbb"]和[100,101];如果数组、Struct或Tuple参数包含双引号,需转义,例如:["aaa\\"bbb","ccc"]。', contractAddress: "合约地址", method: "方法", contractAddressInput: "请输入正确的合约地址", From 283b4a6bd116e399d29a8cae6d2f9ac3b406dd47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BA=A6=E7=AB=8B=E5=81=A5?= <102428352+MaiLiJian-CN@users.noreply.github.com> Date: Sun, 28 Aug 2022 12:21:19 +0800 Subject: [PATCH 09/16] =?UTF-8?q?Task=20=E4=BB=BB=E5=8A=A13|=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E7=9B=91=E6=8E=A7WeBase=E4=B8=80=E9=94=AE=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E4=B8=8B=E5=90=84=E5=AD=90=E7=B3=BB=E7=BB=9F=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WeBase-Listen.sh | 98 +++++++++++++++++++ ...07\344\273\266\350\257\246\350\247\243.md" | 64 ++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 WeBase-Listen.sh create mode 100644 "WeBase-Listen.sh \346\226\207\344\273\266\350\257\246\350\247\243.md" diff --git a/WeBase-Listen.sh b/WeBase-Listen.sh new file mode 100644 index 000000000..ab01d61ff --- /dev/null +++ b/WeBase-Listen.sh @@ -0,0 +1,98 @@ +#!/bin/bash +#获取webase系统路径 +wb_path=$(pwd) #默认脚本与WeBase子系统处于同级目录,如有不同,自行修改 +port=0 +web_Port=5000 #默认5000 + +function webase_front(){ + echo "check webase-front..." #在同级目录下查找webase-front文件夹 + wabse_front_path=$(find $wb_path -name 'webase-front' -type d) + cd $wabse_front_path #进入WeBase-Front目录 + status="$(bash status.sh)" #运行状态脚本 + if [[ $status == *"running"* ]] + then + msg=`echo ${status#*Port}` + port=`echo ${msg%%i*}` #进行字符串截取获得端口(默认5002) + fi + + port_msg=`lsof -i:$port` #lsof -i:port 查看端口连接 + if [[ $port_msg == *"LISTEN"* ]] #判断端口是否被监听,是则正常运行,否则运行有误 + then #后续两个子系统方法大致相同 + echo "WeBase-Front is Successful" + else + echo "WeBase-Front is Fail" + return + fi + echo -e "Check webase-front finish\n" +} + +function webase_node_mgr(){ + #查找webase-node-mgr文件夹 + echo "check webase-node-mgr..." + webase_node_mgr_path=$(find $wb_path -name 'webase-node-mgr' -type d) + cd $webase_node_mgr_path + status=$(bash status.sh) + if [[ $status == *"running"* ]] + then + msg=`echo ${status#*Port}` + port=`echo ${msg%%i*}` #获得端口 + fi + port_msg=`lsof -i:$port` + if [[ $port_msg == *"LISTEN"* ]] + then + echo "WeBase-Node-Mgr is Successful" + else + echo "WeBase-Node-Mgr is Fail" + return + fi + echo -e "Check WeBase-Node-Mgr finish\n" +} + +function webase_sign(){ + #查找webase_sign文件夹 + echo "check webase_sign..." + webase_sign_path=$(find $wb_path -name 'webase-sign' -type d) + cd $webase_sign_path + status=$(bash status.sh) + if [[ $status == *"running"* ]] + then + msg=`echo ${status#*Port}` + port=`echo ${msg%%i*}` #获得端口 + else + echo "no running" + fi + + port_msg=`lsof -i:$port` + if [[ $port_msg == *"LISTEN"* ]] + then + echo "WeBase-Sign is Successful" + else + echo "WeBase-Sign is Fail" + fi + echo -e "Check WeBase-Sign finish\n" +} +function webase_web(){ + echo "check webase_web..." + nginx_conf=$wb_path/comm/nginx.conf #获取nginx.conf的工作路径 + nginx_msg="`ps -ef |grep nginx`" #ps(英文全拼:process status)命令用于显示当前进程的状态 ps -ef -e显示所有进程,-f全格式。 + + if [[ $nginx_msg == *$nginx_conf* ]] #进行匹配查看,nginx服务有无使用webase-web自带的nginx配置 + then + echo "WeBase-Web is Successful" + else + echo "WeBase-Web is Fail" + fi + echo -e "Check WeBase-Web finish\n" +} +# WeBase-Front子系统测试 +sleep 3 +webase_front +# WeBase-Node-Msg子系统测试 +sleep 3 +webase_node_mgr +# WeBase-Sign子系统测试 +sleep 3 +webase_sign +# WeBase-Web子系统测试 +sleep 3 +webase_web \ No newline at end of file diff --git "a/WeBase-Listen.sh \346\226\207\344\273\266\350\257\246\350\247\243.md" "b/WeBase-Listen.sh \346\226\207\344\273\266\350\257\246\350\247\243.md" new file mode 100644 index 000000000..0e5178288 --- /dev/null +++ "b/WeBase-Listen.sh \346\226\207\344\273\266\350\257\246\350\247\243.md" @@ -0,0 +1,64 @@ +# WeBase-Listen.sh 文件详解 + +------ + +作者:深职院-麦立健 + +ps:shell语言的编写,平时不常接触,有不足,请包涵,欢迎各位指出问题。 + +获取WeBase子系统的同级路径 + +```shell +wb_path=$(pwd) #默认脚本与WeBase子系统处于同级目录,如有不同,自行修改 +port=0 +web_Port=5000 #默认5000 +``` + +Webase_Front函数的思路是去获取子系统下的status.sh函数,判断其是否有正常启动,获得输出字符,经过字符串的截取获得WeBase-Front启动时的浏览器端口,通过losf -i:端口,进行判断是否有在监听状态。 + +```shell +function webase_front(){ + echo "check webase-front..." #在同级目录下查找webase-front文件夹 + wabse_front_path=$(find $wb_path -name 'webase-front' -type d) + cd $wabse_front_path #进入WeBase-Front目录 + status="$(bash status.sh)" #运行状态脚本 + if [[ $status == *"running"* ]] + then + msg=`echo ${status#*Port}` + port=`echo ${msg%%i*}` #进行字符串截取获得端口(默认5002) + fi + + port_msg=`lsof -i:$port` #lsof -i:port 查看端口连接 + if [[ $port_msg == *"LISTEN"* ]] #判断端口是否被监听,是则正常运行,否则运行有误 + then #后续两个子系统方法大致相同 + echo "WeBase-Front is Successful" + else + echo "WeBase-Front is Fail" + return + fi + echo -e "Check webase-front finish\n" +} +``` + +WeBase-Node-Msg和WeBase-Sign方法同上,不再赘述。 + +------ + +WeBase-Web本身主要是存放静态页面等资源,所以不存在start.sh和status.sh等脚本文件,而log日志文件也记录的是浏览器的请求信息,对于判断意义不大,所以用监听nginx服务的方法。通过获取WeBase一键部署时的nginx配置文件路径,再查看nginx服务,通过字符串比较来判断nginx服务有无采用WeBase一键部署的配置文件,有则说明WeBase-Web服务成功跑起来了~ + +```shell +function webase_web(){ + echo "check webase_web..." + nginx_conf=$wb_path/comm/nginx.conf #获取nginx.conf的工作路径 + nginx_msg="`ps -ef |grep nginx`" #ps(英文全拼:process status)命令用于显示当前进程的状态 ps -ef -e显示所有进程,-f全格式。 + + if [[ $nginx_msg == *$nginx_conf* ]] #进行匹配查看,nginx服务有无使用webase-web自带的nginx配置 + then + echo "WeBase-Web is Successful" + else + echo "WeBase-Web is Fail" + fi + echo -e "Check WeBase-Web finish\n" +} +``` + From f2c3a1c1496cbb796d3ba5ec60e71ec25a105a70 Mon Sep 17 00:00:00 2001 From: lyh <81232339+carpONE@users.noreply.github.com> Date: Wed, 12 Oct 2022 09:04:04 -0500 Subject: [PATCH 10/16] Add files via upload --- ...47\233\256\344\270\255\347\232\204logo.md" | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "task11-\344\277\256\346\224\271WeBASE-Front\345\211\215\347\253\257\351\241\271\347\233\256\344\270\255\347\232\204logo.md" diff --git "a/task11-\344\277\256\346\224\271WeBASE-Front\345\211\215\347\253\257\351\241\271\347\233\256\344\270\255\347\232\204logo.md" "b/task11-\344\277\256\346\224\271WeBASE-Front\345\211\215\347\253\257\351\241\271\347\233\256\344\270\255\347\232\204logo.md" new file mode 100644 index 000000000..e7457af2b --- /dev/null +++ "b/task11-\344\277\256\346\224\271WeBASE-Front\345\211\215\347\253\257\351\241\271\347\233\256\344\270\255\347\232\204logo.md" @@ -0,0 +1,37 @@ +# Second quarter 第二季 + +## task11:修改WeBASE-Front前端项目中的logo + +### 第一步:克隆WeBASE-Front项目 + +``git clone https://gitee.com/WeBank/WeBASE-Front.git`` + +### 第二步:修改WeBASE-Front前端项目logo + +> 注意:修改的logo图片类型以及名称需要跟原来的一致 + +在 /WeBASE-Front/src/main/resources/static/static/image 目录下找到 logo.jpg 将其替换调即可 + +如果是浏览器显示的logo则修改 /WeBASE-Front/src/main/resources/static/static/image 目录下的 webase_35x35.png + +### 第三步:编译代码 + +在 WeBASE-Front 目录下运行命令: + +```bash +chmod +x ./gradlew && ./gradlew build -x test +``` + +### 第四步:修改配置 + +按照[官方的配置说明](https://webasedoc.readthedocs.io/zh_CN/latest/docs/WeBASE-Front/install.html#id6)即可 + +#### 第五步:启动 + +返回到dist目录执行: + +```bash +启动: bash start.sh +停止: bash stop.sh +检查: bash status.sh +``` \ No newline at end of file From ac39e51594d20bc55aa34a8f29f6fa2543f827ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=97=E6=B3=95?= Date: Fri, 21 Oct 2022 15:52:50 +0800 Subject: [PATCH 11/16] Update CRUDParseUtils.java --- .../precompiledapi/crud/CRUDParseUtils.java | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/webank/webase/front/precompiledapi/crud/CRUDParseUtils.java b/src/main/java/com/webank/webase/front/precompiledapi/crud/CRUDParseUtils.java index 748b8c227..5ab3701bc 100644 --- a/src/main/java/com/webank/webase/front/precompiledapi/crud/CRUDParseUtils.java +++ b/src/main/java/com/webank/webase/front/precompiledapi/crud/CRUDParseUtils.java @@ -50,6 +50,13 @@ public class CRUDParseUtils { private static final Logger logger = LoggerFactory.getLogger(CRUDParseUtils.class); public static final String PRIMARY_KEY = "primary key"; + private static String unescape(String name){ + if(name.contains("`")){ + return name.replace("`",""); + } + return name; + } + public static void parseCreateTable(String sql, Table table) throws JSQLParserException, FrontException { Statement statement = CCJSqlParserUtil.parse(sql); @@ -71,8 +78,8 @@ public static void parseCreateTable(String sql, Table table) Index index = indexes.get(0); String type = index.getType().toLowerCase(); if (PRIMARY_KEY.equals(type)) { - table.setKey(index.getColumnsNames().get(0)); - table.setKeyFieldName(index.getColumnsNames().get(0)); + table.setKey(unescape(index.getColumnsNames().get(0))); + table.setKeyFieldName(unescape(index.getColumnsNames().get(0))); } else { throw new FrontException(ConstantCode.SQL_ERROR, "Please provide only one primary key for the table."); @@ -96,7 +103,7 @@ public static void parseCreateTable(String sql, Table table) } } else { keyFlag = true; - table.setKey(key); + table.setKey(unescape(key)); } break; } @@ -109,16 +116,16 @@ public static void parseCreateTable(String sql, Table table) List fieldsList = new ArrayList<>(); for (int i = 0; i < columnDefinitions.size(); i++) { String columnName = columnDefinitions.get(i).getColumnName(); - if (fieldsList.contains(columnName)) { + if (fieldsList.contains(unescape(columnName))) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide the field '" + columnName + "' only once."); + "Please provide the field '" + columnName + "' only once."); } else { - fieldsList.add(columnName); + fieldsList.add(unescape(columnName)); } } if (!fieldsList.contains(table.getKey())) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide the field '" + table.getKey() + "' in column definition."); + "Please provide the field '" + table.getKey() + "' in column definition."); } else { fieldsList.remove(table.getKey()); } @@ -172,7 +179,7 @@ public static boolean parseInsert( } if (expectedValueNum != columns.size()) { throw new FrontException(ConstantCode.SQL_ERROR, - "Column count doesn't match value count, fields size: " + "Column count doesn't match value count, fields size: " + valueFields.length + ", provided field value size: " + columns.size() @@ -182,11 +189,11 @@ public static boolean parseInsert( List columnNames = new ArrayList<>(); for (Column column : columns) { String columnName = trimQuotes(column.toString()); - if (columnNames.contains(columnName)) { + if (columnNames.contains(unescape(columnName))) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide the field '" + columnName + "' only once."); + "Please provide the field '" + columnName + "' only once."); } else { - columnNames.add(columnName); + columnNames.add(unescape(columnName)); } } for (int i = 0; i < columnNames.size(); i++) { @@ -197,7 +204,7 @@ public static boolean parseInsert( String keyField = tableDesc.get(PrecompiledConstant.KEY_FIELD_NAME); if (expectedValueNum != itemArr.length) { throw new FrontException(ConstantCode.SQL_ERROR, - "Column count doesn't match value count, fields size: " + "Column count doesn't match value count, fields size: " + valueFields.length + ", provided field value size: " + itemArr.length @@ -266,10 +273,10 @@ public static void parseSelect( if (expression instanceof Function) { Function func = (Function) expression; throw new FrontException(ConstantCode.SQL_ERROR, - "The " + func.getName() + " function is not supported."); + "The " + func.getName() + " function is not supported."); } } - selectColumns.add(item.toString()); + selectColumns.add(unescape(item.toString())); } } @@ -351,7 +358,7 @@ public static void parseUpdate(String sql, Table table, Entry entry, Condition c } for (int i = 0; i < columns.size(); i++) { entry.getFieldNameToValue() - .put(trimQuotes(columns.get(i).toString()), trimQuotes(values[i])); + .put(trimQuotes(unescape(columns.get(i).toString())), trimQuotes(values[i])); } // parse where clause @@ -398,8 +405,8 @@ private static void parseLimit(Condition condition, Limit limit) } } catch (NumberFormatException e) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide limit parameters by non-negative integer mode, " - + PrecompiledUtils.NonNegativeIntegerRange + "Please provide limit parameters by non-negative integer mode, " + + "from 0 to 2147483647" + "."); } } @@ -415,7 +422,7 @@ private static Condition getWhereClause(Expression expr, Condition condition) @Override protected void visitBinaryExpression(BinaryExpression expr) { if (expr instanceof ComparisonOperator) { - String key = trimQuotes(expr.getLeftExpression().toString()); + String key = unescape(trimQuotes(expr.getLeftExpression().toString())); if (keySet.contains(key)) { conflictKeys.add(key); } @@ -456,12 +463,12 @@ protected void visitBinaryExpression(BinaryExpression expr) { }); if (conflictKeys.size() > 0) { throw new FrontException(ConstantCode.SQL_ERROR, - "Wrong condition! There cannot be the same field in the same condition! The conflicting field is: " + "Wrong condition! There cannot be the same field in the same condition! The conflicting field is: " + conflictKeys.toString()); } if (unsupportedConditions.size() > 0) { throw new FrontException(ConstantCode.SQL_ERROR, - "Wrong condition! Find unsupported conditions! message: " + "Wrong condition! Find unsupported conditions! message: " + unsupportedConditions.toString()); } return condition; @@ -482,7 +489,7 @@ public static void invalidSymbol(String sql) throws FrontException { public static boolean checkTableExistence(List> descTable) { if (descTable.size() == 0 - || descTable.get(0).get(PrecompiledConstant.KEY_FIELD_NAME).equals("")) { + || descTable.get(0).get(PrecompiledConstant.KEY_FIELD_NAME).equals("")) { // System.out.println("The table \"" + tableName + "\" doesn't exist!"); return false; } @@ -563,17 +570,17 @@ public static void handleKey(Table table, Condition condition) { Map keyMap = condition.getConditions().get(keyName); if (keyMap == null) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide a equal condition for the key field '" - + keyName - + "' in where clause."); + "Please provide a equal condition for the key field '" + + keyName + + "' in where clause."); } else { Set keySet = keyMap.keySet(); for (ConditionOperator enumOP : keySet) { if (enumOP != ConditionOperator.eq) { throw new FrontException(ConstantCode.SQL_ERROR, - "Please provide a equal condition for the key field '" - + keyName - + "' in where clause."); + "Please provide a equal condition for the key field '" + + keyName + + "' in where clause."); } else { keyValue = keyMap.get(enumOP); } @@ -601,7 +608,7 @@ public static List> filterSystemColum(List> getSelectedColumn( - List selectColumns, List> result) { + List selectColumns, List> result) { List> selectedResult = new ArrayList<>(result.size()); Map selectedRecords; for (Map records : result) { From 45a05f845c1683e93c95f268e5e99a32c3fe8603 Mon Sep 17 00:00:00 2001 From: marsli Date: Tue, 18 Apr 2023 14:28:54 +0800 Subject: [PATCH 12/16] 1.5.5 --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 0fa0ece59..57286c9d4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,4 @@ -### v1.5.4(2023-03-09) +### v1.5.5(2023-04-17) **Fix** - 支持合约函数复杂参数如Struct类型的入参与返回值,部署合约与发交易相关接口中`funcParam`类型从`List`改为`List` From e5df7e1eeab12f972b83cd68d1c1085dce301353 Mon Sep 17 00:00:00 2001 From: hior-y <126435017+hior-y@users.noreply.github.com> Date: Fri, 5 May 2023 14:29:58 +0800 Subject: [PATCH 13/16] =?UTF-8?q?TASK=201=20=E5=B7=A5=E5=85=B7=E5=90=88?= =?UTF-8?q?=E7=BA=A6-Crypto=E5=90=88=E7=BA=A6=E8=AF=A6=E7=BB=86=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...46\347\273\206\344\275\277\347\224\250.md" | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 "\345\267\245\345\205\267\345\220\210\347\272\246-Crypto\345\220\210\347\272\246\350\257\246\347\273\206\344\275\277\347\224\250.md" diff --git "a/\345\267\245\345\205\267\345\220\210\347\272\246-Crypto\345\220\210\347\272\246\350\257\246\347\273\206\344\275\277\347\224\250.md" "b/\345\267\245\345\205\267\345\220\210\347\272\246-Crypto\345\220\210\347\272\246\350\257\246\347\273\206\344\275\277\347\224\250.md" new file mode 100644 index 000000000..e1f3d872a --- /dev/null +++ "b/\345\267\245\345\205\267\345\220\210\347\272\246-Crypto\345\220\210\347\272\246\350\257\246\347\273\206\344\275\277\347\224\250.md" @@ -0,0 +1,159 @@ +# 工具合约-Crypto合约使用 + +## Crypto合约详细 + +Crypto的智能合约,它包含4个函数: + +1. `sm3(bytes memory data)`:使用Sm3 hash算法处理数据并返回结果。 +2. `keccak256Hash(bytes memory data)`:使用Keccak256 hash算法处理数据并返回结果。 +3. `sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s)`:使用SM2签名算法验证信息。 +4. `curve25519VRFVerify(string memory input, string memory vrfPublicKey, string memory vrfProof)` :使用Curve25519 VRF签名算法验证信息,并返回一个布尔值和签名后的随机数。 + +这个合约提供了不同类型的加密算法支持,在区块链上进行加密、解密和验证操作,并且只有合约创建者才有权提交和执行这些操作。 + +```solidity +/** + * @title Crypto + * @dev 智能合约提供了Sm3, Keccak256, SM2 signature verification和Curve25519 VRF签名算法支持,只能在FISCO-BCOS v2.8.0+上使用。 + */ +contract Crypto +{ + /** + * @dev 使用Sm3 hash算法处理数据并返回结果。 + * @param data 要进行哈希的数据 + * @return bytes32 哈希结果 + */ + function sm3(bytes memory data) public view returns(bytes32){} + + /** + * @dev 使用Keccak256 hash算法处理数据并返回结果。 + * @param data 要进行哈希的数据 + * @return bytes32 哈希结果 + */ + function keccak256Hash(bytes memory data) public view returns(bytes32){} + + /** + * @dev 使用SM2签名算法验证信息是否正确。 + * @param message 待验信息的哈希值 + * @param publicKey 签名密钥的公钥 + * @param r 签名中的r的值 + * @param s 签名中的s的值 + * @return bool 验证结果true为成功,false为失败 + * @return address 签名验证通过后返回签名地址 + */ + function sm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns(bool, address){} + + /** + * @dev 使用Curve25519 VRF签名算法验证输入字符串,并返回一个布尔值和签名后的随机数。 + * @param input 将要被签名的字符串形式数据 + * @param vrfPublicKey 用于签名的公钥 + * @param vrfProof 签名后的证明内容 + * @return bool 验证结果 true为成功,false为失败 + * @return uint256 返回签名后的随机数 + */ + function curve25519VRFVerify(string memory input, string memory vrfPublicKey, string memory vrfProof) public view returns(bool,uint256){} +} +``` + +### sm3函数使用 + +将给定的字符串和数字哈希为一个byte数组,然后计算它的SHA3/Keccak-256哈希。 + +```solidity +function testSm3(string memory message, uint num) public view returns (bytes32) { + bytes memory data = abi.encodePacked(message, num); + Crypto cryptoInstance = Crypto(cryptoAddress); + return cryptoInstance.sm3(data); +} +``` + +### keccak256Hash函数 + +将两个字符串连接到一起,再使用keccak256算法计算它的哈希值。 + +```solidity +function testKeccak256Hash(string memory str1, string memory str2) public view returns (bytes32) { + bytes memory data = abi.encodePacked(str1, str2); + Crypto cryptoInstance = Crypto(cryptoAddress); + return cryptoInstance.keccak256Hash(data); +} +``` + +### sm2Verify函数 + +传入该协议中之前交互过的信息、公钥、签名 r 和 s ,验证该签名是否正确,并返回签名的账户地址。 + +```solidity +function testSm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address) { + Crypto cryptoInstance = Crypto(cryptoAddress); + return cryptoInstance.sm2Verify(message, publicKey, r, s); +} +``` + +### curve25519VRFVerify函数 + +将给定的字符串用 UTF8 编码,然后使用 curve25519 VRF 签名算法和公钥对其进行签名,最后在智能合约中验证签名,并返回是否验证成功以及签名后的随机数。 + +```solidity +function testCurve25519VRFVerify(string memory input, string memory vrfPublicKey, string memory vrfProof) public view returns (bool, uint256) { + Crypto cryptoInstance = Crypto(cryptoAddress); + return cryptoInstance.curve25519VRFVerify(input, vrfPublicKey, vrfProof); +} +``` + + + +### 完整的合约 + +首先需要搭建好WeBASE-Front以及FISCO BCOS 2.8.0。 + +![](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051050302.webp) + +```solidity +pragma solidity ^0.4.25; + +import "./Crypto.sol"; + +contract CryptoTest{ + Crypto crypto; + // 初始化构造函数实例化一个Crypto + constructor() public { + crypto = Crypto(0x5006); + } + // sm3函数使用 + function testSm3(string memory message, uint num) public view returns (bytes32) { + bytes memory data = abi.encodePacked(message, num); + return crypto.sm3(data); + } + // keccak256Hash函数 + function testKeccak256Hash(string memory str1, string memory str2) public view returns (bytes32) { + bytes memory data = abi.encodePacked(str1, str2); + return crypto.keccak256Hash(data); + } + // sm2Verify函数 + function testSm2Verify(bytes32 message, bytes memory publicKey, bytes32 r, bytes32 s) public view returns (bool, address) { + return crypto.sm2Verify(message, publicKey, r, s); + } + // curve25519VRFVerify函数 + function testCurve25519VRFVerify(string memory input, string memory vrfPublicKey, string memory vrfProof) public view returns (bool, uint256) { + return crypto.curve25519VRFVerify(input, vrfPublicKey, vrfProof); + } +} +``` + +部署CryptoTest合约。 + +![image-20230505105153585](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051051780.webp) + +调用testSm3函数,计算它的SHA3/Keccak-256哈希。 + +![image-20230505113300203](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051133321.webp) + +![image-20230505105231063](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051052170.webp) + +调用testKeccak256Hash函数,使用keccak256算法计算它的哈希值。 + +![image-20230505105708175](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051057292.webp) + +![image-20230505105741558](https://blog-1304715799.cos.ap-nanjing.myqcloud.com/imgs/202305051057668.webp) + From af787e76609ec6e8578c026d72f4dc006cdb5760 Mon Sep 17 00:00:00 2001 From: CodingCattwo <847701726@qq.com> Date: Fri, 5 May 2023 16:08:13 +0800 Subject: [PATCH 14/16] fix pure in v0.6 above version --- .../webase/front/transaction/TransService.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/webank/webase/front/transaction/TransService.java b/src/main/java/com/webank/webase/front/transaction/TransService.java index 4c83db753..7f88bd205 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -180,7 +180,13 @@ public Object transHandleWithSign(int groupId, String signUserId, userAddress = keyStoreService.getCredentialsForQuery().getAddress(); } - boolean isTxConstant = this.getABIDefinition(abiStr, funcName).isConstant(); + ABIDefinition abiDefinition = this.getABIDefinition(abiStr, funcName); + boolean isTxConstant = abiDefinition.isConstant(); + if (abiDefinition.getStateMutability().equals("pure") + || abiDefinition.getStateMutability().equals("constant") + || abiDefinition.getStateMutability().equals("view")) { + isTxConstant = true; + } if (isTxConstant) { return this.handleCall(groupId, userAddress, contractAddress, encodeFunction, abiStr, funcName); } else { @@ -290,7 +296,13 @@ public Object transHandleLocal(ReqTransHandle req) { String encodeFunction = this.encodeFunction2Str(abiStr, funcName, funcParam); - boolean isTxConstant = this.getABIDefinition(abiStr, funcName).isConstant(); + ABIDefinition abiDefinition = this.getABIDefinition(abiStr, funcName); + boolean isTxConstant = abiDefinition.isConstant(); + if (abiDefinition.getStateMutability().equals("pure") + || abiDefinition.getStateMutability().equals("constant") + || abiDefinition.getStateMutability().equals("view")) { + isTxConstant = true; + } // get privateKey CryptoKeyPair cryptoKeyPair = getCredentials(isTxConstant, userAddress); From 495ddb5ab8ca077781e7e7cf6669727eebe00061 Mon Sep 17 00:00:00 2001 From: CodingCattwo <847701726@qq.com> Date: Mon, 8 May 2023 16:27:58 +0800 Subject: [PATCH 15/16] fix tx constant of pure in 0.6 above --- .../front/transaction/TransService.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/webank/webase/front/transaction/TransService.java b/src/main/java/com/webank/webase/front/transaction/TransService.java index 7f88bd205..4042e2af5 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -180,13 +180,7 @@ public Object transHandleWithSign(int groupId, String signUserId, userAddress = keyStoreService.getCredentialsForQuery().getAddress(); } - ABIDefinition abiDefinition = this.getABIDefinition(abiStr, funcName); - boolean isTxConstant = abiDefinition.isConstant(); - if (abiDefinition.getStateMutability().equals("pure") - || abiDefinition.getStateMutability().equals("constant") - || abiDefinition.getStateMutability().equals("view")) { - isTxConstant = true; - } + boolean isTxConstant = this.getABIDefinition(abiStr, funcName).isConstant(); if (isTxConstant) { return this.handleCall(groupId, userAddress, contractAddress, encodeFunction, abiStr, funcName); } else { @@ -296,13 +290,7 @@ public Object transHandleLocal(ReqTransHandle req) { String encodeFunction = this.encodeFunction2Str(abiStr, funcName, funcParam); - ABIDefinition abiDefinition = this.getABIDefinition(abiStr, funcName); - boolean isTxConstant = abiDefinition.isConstant(); - if (abiDefinition.getStateMutability().equals("pure") - || abiDefinition.getStateMutability().equals("constant") - || abiDefinition.getStateMutability().equals("view")) { - isTxConstant = true; - } + boolean isTxConstant = this.getABIDefinition(abiStr, funcName).isConstant(); // get privateKey CryptoKeyPair cryptoKeyPair = getCredentials(isTxConstant, userAddress); @@ -595,8 +583,13 @@ private ABIDefinition getABIDefinition(String abiStr, String functionName) { throw new FrontException(ConstantCode.IN_FUNCTION_ERROR); } // abi only contain one function, so get first one - ABIDefinition function = abiDefinitionList.get(0); - return function; + ABIDefinition abiDefinition = abiDefinitionList.get(0); + if (abiDefinition.getStateMutability().equals("pure") + || abiDefinition.getStateMutability().equals("constant") + || abiDefinition.getStateMutability().equals("view")) { + abiDefinition.setConstant(true); + } + return abiDefinition; } public Object handleCall(int groupId, String userAddress, String contractAddress, From 98035854d861493c41a523cde5531c57d294b59a Mon Sep 17 00:00:00 2001 From: henryy <1148684516@qq.com> Date: Wed, 23 Aug 2023 19:05:36 +0800 Subject: [PATCH 16/16] =?UTF-8?q?task17:=E6=96=B0=E5=A2=9E=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E6=9B=B4=E6=96=B0P2P=E8=BF=9E=E6=8E=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=88=E5=8C=85=E6=8B=ACadd/erase/query=E4=B8=89?= =?UTF-8?q?=E7=B1=BB=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../front/web3api/Web3ApiController.java | 30 +++++++++++++++---- .../webase/front/web3api/Web3ApiService.java | 29 +++++++++++------- .../front/web3api/entity/PeersManageInfo.java | 15 ++++++++++ 3 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/webank/webase/front/web3api/entity/PeersManageInfo.java diff --git a/src/main/java/com/webank/webase/front/web3api/Web3ApiController.java b/src/main/java/com/webank/webase/front/web3api/Web3ApiController.java index ff3051d24..a62065865 100644 --- a/src/main/java/com/webank/webase/front/web3api/Web3ApiController.java +++ b/src/main/java/com/webank/webase/front/web3api/Web3ApiController.java @@ -17,11 +17,7 @@ import com.webank.webase.front.base.exception.FrontException; import com.webank.webase.front.base.response.BaseResponse; import com.webank.webase.front.util.Address; -import com.webank.webase.front.web3api.entity.GenerateGroupInfo; -import com.webank.webase.front.web3api.entity.NodeStatusInfo; -import com.webank.webase.front.web3api.entity.ReqGroupStatus; -import com.webank.webase.front.web3api.entity.RspStatBlock; -import com.webank.webase.front.web3api.entity.RspTransCountInfo; +import com.webank.webase.front.web3api.entity.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -29,10 +25,11 @@ import java.math.BigInteger; import java.util.List; import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; +import org.fisco.bcos.sdk.client.protocol.response.AddPeers; import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; -import org.fisco.bcos.sdk.client.protocol.response.BcosBlockHeader; import org.fisco.bcos.sdk.client.protocol.response.BcosBlockHeader.BlockHeader; import org.fisco.bcos.sdk.client.protocol.response.ConsensusStatus.ConsensusInfo; +import org.fisco.bcos.sdk.client.protocol.response.ErasePeers; import org.fisco.bcos.sdk.client.protocol.response.NodeInfo.NodeInformation; import org.fisco.bcos.sdk.client.protocol.response.Peers; import org.fisco.bcos.sdk.client.protocol.response.SyncStatus.SyncStatusInfo; @@ -378,4 +375,25 @@ public NodeInformation getNodeInfo() { } /* above 2.7.0 */ + + @ApiOperation(value = "addPeers", notes = "Add p2p connection configuration") + @PostMapping("/addPeers") + public AddPeers.AddPeersStatus addPeers(@PathVariable int groupId, + @RequestBody PeersManageInfo peersInfo) { + return web3ApiService.addPeers(groupId, peersInfo); + } + + @ApiOperation(value = "erasePeers", notes = "Remove p2p connection configuration") + @PostMapping("/erasePeers") + public ErasePeers.ErasePeersStatus erasePeers(@PathVariable int groupId, + @RequestBody PeersManageInfo peersInfo) { + return web3ApiService.erasePeers(groupId, peersInfo); + } + + @ApiOperation(value = "queryPeers", notes = "Query p2p connection List") + @PostMapping("/queryPeers") + public List queryPeers(@PathVariable int groupId, + @RequestParam String peerIpPort) { + return web3ApiService.queryPeers(groupId, peerIpPort); + } } diff --git a/src/main/java/com/webank/webase/front/web3api/Web3ApiService.java b/src/main/java/com/webank/webase/front/web3api/Web3ApiService.java index eb8a4af26..f95d56417 100644 --- a/src/main/java/com/webank/webase/front/web3api/Web3ApiService.java +++ b/src/main/java/com/webank/webase/front/web3api/Web3ApiService.java @@ -22,11 +22,8 @@ import com.webank.webase.front.base.response.BaseResponse; import com.webank.webase.front.util.CommonUtils; import com.webank.webase.front.util.JsonUtils; -import com.webank.webase.front.web3api.entity.GenerateGroupInfo; -import com.webank.webase.front.web3api.entity.NodeStatusInfo; -import com.webank.webase.front.web3api.entity.RspSearchTransaction; -import com.webank.webase.front.web3api.entity.RspStatBlock; -import com.webank.webase.front.web3api.entity.RspTransCountInfo; +import com.webank.webase.front.web3api.entity.*; + import java.io.IOException; import java.math.BigInteger; import java.time.Duration; @@ -46,18 +43,14 @@ import org.fisco.bcos.sdk.client.Client; import org.fisco.bcos.sdk.client.protocol.model.GroupStatus; import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; -import org.fisco.bcos.sdk.client.protocol.response.BcosBlock; +import org.fisco.bcos.sdk.client.protocol.response.*; import org.fisco.bcos.sdk.client.protocol.response.BcosBlock.Block; import org.fisco.bcos.sdk.client.protocol.response.BcosBlockHeader.BlockHeader; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceiptsDecoder; import org.fisco.bcos.sdk.client.protocol.response.ConsensusStatus.ConsensusInfo; import org.fisco.bcos.sdk.client.protocol.response.ConsensusStatus.ViewInfo; -import org.fisco.bcos.sdk.client.protocol.response.GroupPeers; import org.fisco.bcos.sdk.client.protocol.response.NodeInfo.NodeInformation; -import org.fisco.bcos.sdk.client.protocol.response.Peers; import org.fisco.bcos.sdk.client.protocol.response.SyncStatus.PeersInfo; import org.fisco.bcos.sdk.client.protocol.response.SyncStatus.SyncStatusInfo; -import org.fisco.bcos.sdk.client.protocol.response.TotalTransactionCount; import org.fisco.bcos.sdk.model.NodeVersion.ClientVersion; import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.utils.Numeric; @@ -855,4 +848,20 @@ private void checkConnection() { private String getNodeIpPort() { return web3ConfigConstants.getIp() + ":" + web3ConfigConstants.getChannelPort(); } + + public AddPeers.AddPeersStatus addPeers(Integer groupId, PeersManageInfo peersInfo) { + String peerIpPort = peersInfo.getPeerIpPort(); + List peers = peersInfo.getPeers(); + return getWeb3j(groupId).addPeers(peerIpPort, peers).getAddPeersStatus(); + } + + public ErasePeers.ErasePeersStatus erasePeers(int groupId, PeersManageInfo peersInfo) { + String peerIpPort = peersInfo.getPeerIpPort(); + List peers = peersInfo.getPeers(); + return getWeb3j(groupId).erasePeers(peerIpPort, peers).getErasePeersStatus(); + } + + public List queryPeers(int groupId, String peerIpPort) { + return getWeb3j(groupId).queryPeers(peerIpPort).getQueryPeers(); + } } diff --git a/src/main/java/com/webank/webase/front/web3api/entity/PeersManageInfo.java b/src/main/java/com/webank/webase/front/web3api/entity/PeersManageInfo.java new file mode 100644 index 000000000..497b13195 --- /dev/null +++ b/src/main/java/com/webank/webase/front/web3api/entity/PeersManageInfo.java @@ -0,0 +1,15 @@ +package com.webank.webase.front.web3api.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PeersManageInfo { + private String peerIpPort; + private List peers; +}