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` 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" +} +``` + 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) { 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 c37ac69fd..d20386653 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; @@ -222,5 +223,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(); + } } 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..6dac4614b 100644 --- a/src/main/java/com/webank/webase/front/transaction/TransService.java +++ b/src/main/java/com/webank/webase/front/transaction/TransService.java @@ -295,7 +295,6 @@ public Object transHandleLocal(ReqTransHandle req) { CryptoKeyPair cryptoKeyPair = getCredentials(isTxConstant, userAddress); Client client = web3ApiService.getWeb3j(groupId); - if (isTxConstant) { if (StringUtils.isBlank(userAddress)) { userAddress = cryptoKeyPair.getAddress(); @@ -376,13 +375,25 @@ 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调用合约问题 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); } + return credentials; } @@ -583,16 +594,22 @@ 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, String encodedFunction, String abiStr, String funcName) { - + // TODO constant不能使用msg.sender调用合约问题。 TransactionProcessor transactionProcessor = new TransactionProcessor( - web3ApiService.getWeb3j(groupId), keyStoreService.getCredentialsForQuery(), - groupId, Constants.chainId); + web3ApiService.getWeb3j(groupId), + getCredentials(true, userAddress), // 尝试db获取该address的私钥,否则随机创建 + groupId, Constants.chainId); CallOutput callOutput = transactionProcessor .executeCall(userAddress, contractAddress, encodedFunction) .getCallResult(); 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; +} 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 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/\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) +