From 4ef8243bb4e64befdd3474daf203e75f1c7fce6d Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:43:44 +0800 Subject: [PATCH 1/5] (console): add v2 extension usage. (#835) --- build.gradle | 4 ++-- release_note.txt | 2 +- src/main/java/console/ConsoleInitializer.java | 10 ++++++++++ src/main/java/console/common/ConsoleVersion.java | 2 +- .../java/console/contract/ConsoleContractImpl.java | 9 ++++++++- tools/download_console.sh | 2 +- 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index a00fd787..a40d261a 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ dependencies { //implementation 'org.fisco-bcos:solcJ:0.5.2.1' implementation 'org.fisco-bcos:solcJ:0.8.11.1' - implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.6.0') { + implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.7.0-SNAPSHOT') { exclude group: "org.slf4j" } @@ -53,7 +53,7 @@ dependencies { implementation('org.jline:jline:3.21.0') implementation('io.bretty:console-table-builder:1.2') implementation('com.github.jsqlparser:jsqlparser:2.0') - implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.3.0') { + implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.5.0-SNAPSHOT') { exclude group: "org.fisco-bcos.java-sdk" exclude group: "org.slf4j" } diff --git a/release_note.txt b/release_note.txt index 130165bc..d1e9cf3b 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1 +1 @@ -v3.6.0 +v3.7.0 diff --git a/src/main/java/console/ConsoleInitializer.java b/src/main/java/console/ConsoleInitializer.java index af7a03aa..fde68e61 100644 --- a/src/main/java/console/ConsoleInitializer.java +++ b/src/main/java/console/ConsoleInitializer.java @@ -73,11 +73,21 @@ public void init(String[] args) throws ConfigException { if (args.length > 3 && "-v1".equals(args[3])) { // use v1 transaction service + logger.info("use v1 transaction service"); useV1TxService = true; } + byte[] extension = null; + if (args.length > 3 && "-v2".equals(args[3])) { + logger.info("use v2 transaction service"); + useV1TxService = true; + extension = args.length > 4 ? args[4].getBytes() : null; + } this.consoleClientFace = new ConsoleClientImpl(client); this.precompiledFace = new PrecompiledImpl(client); this.consoleContractFace = new ConsoleContractImpl(client, useV1TxService); + if (extension != null) { + ((ConsoleContractImpl) this.consoleContractFace).setExtension(extension); + } this.collaborationFace = new CollaborationImpl(client); this.authFace = new AuthImpl(client); } diff --git a/src/main/java/console/common/ConsoleVersion.java b/src/main/java/console/common/ConsoleVersion.java index c1adf690..d741ed94 100644 --- a/src/main/java/console/common/ConsoleVersion.java +++ b/src/main/java/console/common/ConsoleVersion.java @@ -2,7 +2,7 @@ public class ConsoleVersion { - public static final String Version = "3.6.0"; + public static final String Version = "3.7.0"; public static void main(String[] args) { System.out.println("console version: " + Version); diff --git a/src/main/java/console/contract/ConsoleContractImpl.java b/src/main/java/console/contract/ConsoleContractImpl.java index e4ea0898..c53b3aa6 100644 --- a/src/main/java/console/contract/ConsoleContractImpl.java +++ b/src/main/java/console/contract/ConsoleContractImpl.java @@ -88,7 +88,7 @@ public class ConsoleContractImpl implements ConsoleContractFace { private AssembleTransactionService assembleTransactionService = null; private final TransferTransactionService transferTransactionService; private final BFSService bfsService; - + private byte[] extension = null; private boolean useTransactionV1 = false; public ConsoleContractImpl(Client client) { @@ -117,6 +117,10 @@ public ConsoleContractImpl(Client client, boolean useTransactionV1) { } } + public void setExtension(byte[] extension) { + this.extension = extension; + } + @Override public void deploy(String[] params, String pwd) throws Exception { List paramsList = new ArrayList<>(Arrays.asList(params)); @@ -268,6 +272,7 @@ public TransactionResponse deploySolidity( if (useTransactionV1) { DeployTransactionRequestWithStringParams request = new TransactionRequestBuilder(abiAndBin.getAbi(), bin) + .setExtension(extension) .buildDeployStringParamsRequest(tempInputParams); response = assembleTransactionService.deployContract(request); } else { @@ -333,6 +338,7 @@ public TransactionResponse deployWasm( DeployTransactionRequestWithStringParams request = new TransactionRequestBuilder(abi, binStr) .setTo(path) + .setExtension(extension) .buildDeployStringParamsRequest(inputParams); response = assembleTransactionService.deployContract(request); } else { @@ -768,6 +774,7 @@ private void sendTransaction( if (useTransactionV1) { TransactionRequestWithStringParams request = new TransactionRequestBuilder(abiAndBin.getAbi(), functionName, contractAddress) + .setExtension(extension) .buildStringParamsRequest(callParams); response = assembleTransactionService.sendTransaction(request); } else { diff --git a/tools/download_console.sh b/tools/download_console.sh index 39155a14..f6ab3ae9 100755 --- a/tools/download_console.sh +++ b/tools/download_console.sh @@ -3,7 +3,7 @@ package_name="console.tar.gz" solcj_name="" solcj_default_version="solcJ-0.8.11.1.jar" only_solc_flag="" -default_version="3.6.0" +default_version="3.7.0" download_version="${default_version}" solc_download_version="3.0.0" specify_console=0 From f31bccd12ede536044d8f52faf62607c25bca507 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:10:55 +0800 Subject: [PATCH 2/5] (console): adapt code-gen 1.5.0. (#836) --- build.gradle | 4 ++-- src/main/java/console/common/ConsoleUtils.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a40d261a..a1cfe501 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ googleJavaFormat { include '**/*.java' } -def log4j_version = '2.19.0' +def log4j_version = '2.22.1' List logger = [ "org.apache.logging.log4j:log4j-api:$log4j_version", "org.apache.logging.log4j:log4j-core:$log4j_version", @@ -50,7 +50,7 @@ dependencies { exclude group: "org.slf4j" } implementation('commons-cli:commons-cli:1.5.0') - implementation('org.jline:jline:3.21.0') + implementation('org.jline:jline:3.25.0') implementation('io.bretty:console-table-builder:1.2') implementation('com.github.jsqlparser:jsqlparser:2.0') implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.5.0-SNAPSHOT') { diff --git a/src/main/java/console/common/ConsoleUtils.java b/src/main/java/console/common/ConsoleUtils.java index 1676f787..03220624 100644 --- a/src/main/java/console/common/ConsoleUtils.java +++ b/src/main/java/console/common/ConsoleUtils.java @@ -856,7 +856,7 @@ public static void main(String[] args) { "t", TRANSACTION_VERSION, true, - "[Optional] Specify transaction version interface, default is 0; If you want to use the latest transaction interface, please specify 1."); + "[Optional] Specify transaction version interface, default is 0; Supporting {0,1,2}; If you want to use the latest transaction interface, please specify 2."); transactionVersion.setRequired(false); options.addOption(transactionVersion); if (mode.equals("solidity")) { From c2b56ee3d4dc9e78ec0404d0fc3e2fa49da72a0f Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:53:02 +0800 Subject: [PATCH 3/5] (command): fix jline completion not contain all features key. (#837) --- build.gradle | 2 +- src/main/java/console/command/JlineUtils.java | 77 +++++++++---------- 2 files changed, 36 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index a1cfe501..dd61c4ef 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ dependencies { exclude group: "org.slf4j" } implementation('commons-cli:commons-cli:1.5.0') - implementation('org.jline:jline:3.25.0') + implementation('org.jline:jline:3.21.0') implementation('io.bretty:console-table-builder:1.2') implementation('com.github.jsqlparser:jsqlparser:2.0') implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.5.0-SNAPSHOT') { diff --git a/src/main/java/console/command/JlineUtils.java b/src/main/java/console/command/JlineUtils.java index aa870f02..c75dc6f8 100644 --- a/src/main/java/console/command/JlineUtils.java +++ b/src/main/java/console/command/JlineUtils.java @@ -17,8 +17,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Optional; +import java.util.Set; import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.response.BcosGroupInfo; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigFeature; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService; import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; @@ -183,50 +187,39 @@ private static List generateComplters(Client client) { if (client.isEnableCommittee()) { commands.add(AuthOpCommand.SET_SYS_CONFIG_PROPOSAL.getCommand()); } + Set keys = new HashSet<>(); + keys.add(SystemConfigService.TX_COUNT_LIMIT); + keys.add(SystemConfigService.TX_GAS_LIMIT); + keys.add(SystemConfigService.TX_GAS_PRICE); + keys.add(SystemConfigService.CONSENSUS_PERIOD); + keys.add(SystemConfigService.COMPATIBILITY_VERSION); + keys.add(SystemConfigService.AUTH_STATUS); + for (SystemConfigFeature.Features feature : SystemConfigFeature.Features.values()) { + if (client.getChainCompatibilityVersion() + .compareTo(EnumNodeVersion.convertToVersion(feature.enableVersion())) + >= 0) { + keys.add(feature.toString()); + } + } + Optional group = + client.getGroupInfoList() + .getResult() + .stream() + .filter(groupInfo -> groupInfo.getGroupID().equals(client.getGroup())) + .findFirst(); + if (group.isPresent() && !group.get().getNodeList().isEmpty()) { + group.get() + .getNodeList() + .forEach(groupNodeInfo -> keys.addAll(groupNodeInfo.getFeatureKeys())); + } for (String command : commands) { - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_COUNT_LIMIT), - new StringsCompleterIgnoreCase())); - - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_GAS_LIMIT), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.TX_GAS_PRICE), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.CONSENSUS_PERIOD), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.COMPATIBILITY_VERSION), - new StringsCompleterIgnoreCase())); - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(SystemConfigService.AUTH_STATUS), - new StringsCompleterIgnoreCase())); - for (SystemConfigFeature.Features feature : SystemConfigFeature.Features.values()) { - if (client.getChainCompatibilityVersion() - .compareTo( - EnumNodeVersion.convertToVersion(feature.enableVersion())) - >= 0) { - completers.add( - new ArgumentCompleter( - new StringsCompleter(command), - new StringsCompleter(feature.toString()), - new StringsCompleterIgnoreCase())); - } + for (String key : keys) { + completers.add( + new ArgumentCompleter( + new StringsCompleter(command), + new StringsCompleter(key), + new StringsCompleterIgnoreCase())); } } completers.add( From f1fbe875237b4448bc6737f4dd33a0bd87da0b59 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:14:28 +0800 Subject: [PATCH 4/5] (console): fix console extension lose when switch group. (#838) --- src/main/java/console/ConsoleInitializer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/console/ConsoleInitializer.java b/src/main/java/console/ConsoleInitializer.java index fde68e61..b33433ce 100644 --- a/src/main/java/console/ConsoleInitializer.java +++ b/src/main/java/console/ConsoleInitializer.java @@ -47,6 +47,9 @@ public class ConsoleInitializer { private LineReader lineReader; private boolean useV1TxService; + // v2 transaction extension + private byte[] extension; + public LineReader getLineReader() { return lineReader; } @@ -76,7 +79,6 @@ public void init(String[] args) throws ConfigException { logger.info("use v1 transaction service"); useV1TxService = true; } - byte[] extension = null; if (args.length > 3 && "-v2".equals(args[3])) { logger.info("use v2 transaction service"); useV1TxService = true; @@ -294,6 +296,9 @@ public void switchGroup(String[] params) { this.consoleClientFace = new ConsoleClientImpl(client); this.precompiledFace = new PrecompiledImpl(client); this.consoleContractFace = new ConsoleContractImpl(client, useV1TxService); + if (extension != null) { + ((ConsoleContractImpl) this.consoleContractFace).setExtension(extension); + } this.collaborationFace = new CollaborationImpl(client); this.authFace = new AuthImpl(client); JlineUtils.switchGroup(client); @@ -368,6 +373,9 @@ public void loadAccount(String[] params) { this.consoleClientFace = new ConsoleClientImpl(client); this.precompiledFace = new PrecompiledImpl(client); this.consoleContractFace = new ConsoleContractImpl(client, useV1TxService); + if (extension != null) { + ((ConsoleContractImpl) this.consoleContractFace).setExtension(extension); + } this.collaborationFace = new CollaborationImpl(client); this.authFace = new AuthImpl(client); System.out.println("Load account " + params[1] + " success!"); From a099c4d1465c5aca3f88f64d9c7aaaf21b1200d3 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:03:06 +0800 Subject: [PATCH 5/5] (jline): fix jline getGroupInfoList bug in light node. (#839) --- src/main/java/console/command/JlineUtils.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/console/command/JlineUtils.java b/src/main/java/console/command/JlineUtils.java index c75dc6f8..ed2f40aa 100644 --- a/src/main/java/console/command/JlineUtils.java +++ b/src/main/java/console/command/JlineUtils.java @@ -23,6 +23,7 @@ import java.util.Set; import org.fisco.bcos.sdk.v3.client.Client; import org.fisco.bcos.sdk.v3.client.protocol.response.BcosGroupInfo; +import org.fisco.bcos.sdk.v3.client.protocol.response.BcosGroupInfoList; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigFeature; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService; import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; @@ -201,16 +202,22 @@ private static List generateComplters(Client client) { keys.add(feature.toString()); } } - Optional group = - client.getGroupInfoList() - .getResult() - .stream() - .filter(groupInfo -> groupInfo.getGroupID().equals(client.getGroup())) - .findFirst(); - if (group.isPresent() && !group.get().getNodeList().isEmpty()) { - group.get() - .getNodeList() - .forEach(groupNodeInfo -> keys.addAll(groupNodeInfo.getFeatureKeys())); + BcosGroupInfoList groupInfoList; + try { + groupInfoList = client.getGroupInfoList(); + Optional group = + groupInfoList + .getResult() + .stream() + .filter(groupInfo -> groupInfo.getGroupID().equals(client.getGroup())) + .findFirst(); + if (group.isPresent() && !group.get().getNodeList().isEmpty()) { + group.get() + .getNodeList() + .forEach(groupNodeInfo -> keys.addAll(groupNodeInfo.getFeatureKeys())); + } + } catch (Exception ignored) { + logger.info("Failed to get group info list, skip feature keys."); } for (String command : commands) {