From dff0b76c8e98d53499ffaf10ae642fc1c5627d6e Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 28 Dec 2023 17:38:36 +0800 Subject: [PATCH] (console): adapt code-gen 1.3.0. (#812) --- build.gradle | 2 +- .../java/console/common/ConsoleUtils.java | 42 +++++++++++++++---- .../console/contract/ConsoleContractImpl.java | 6 +-- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index 3ab86628..beeb9f16 100644 --- a/build.gradle +++ b/build.gradle @@ -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.2.0') { + implementation('org.fisco-bcos.code-generator:bcos-code-generator:1.3.0-SNAPSHOT') { exclude group: "org.fisco-bcos.java-sdk" exclude group: "org.slf4j" } diff --git a/src/main/java/console/common/ConsoleUtils.java b/src/main/java/console/common/ConsoleUtils.java index 84a4da1f..1676f787 100644 --- a/src/main/java/console/common/ConsoleUtils.java +++ b/src/main/java/console/common/ConsoleUtils.java @@ -318,7 +318,8 @@ public static void compileSolToJava( String librariesOption, String specifyContract, boolean isContractParallelAnalysis, - boolean enableAsyncCall) + boolean enableAsyncCall, + String transactionVersion) throws IOException, CompileContractException { String contractName = solFile.getName().split("\\.")[0]; @@ -360,6 +361,10 @@ public static void compileSolToJava( if (enableAsyncCall) { args.add("-e"); } + if (!transactionVersion.equals("V0")) { + args.add("-t"); + args.add(transactionVersion); + } CodeGenMain.main(args.toArray(new String[0])); System.out.println( "*** Convert solidity to java for " + solFile.getName() + " success ***\n"); @@ -372,7 +377,8 @@ public static void compileAllSolToJava( String abiDir, String binDir, boolean isContractParallelAnalysis, - boolean enableAsyncCall) + boolean enableAsyncCall, + String transactionVersion) throws IOException { File[] solFiles = solFileList.listFiles(); if (solFiles.length == 0) { @@ -397,7 +403,8 @@ public static void compileAllSolToJava( null, null, isContractParallelAnalysis, - enableAsyncCall); + enableAsyncCall, + transactionVersion); } catch (Exception e) { System.out.println( "ERROR:convert solidity to java for " @@ -842,7 +849,16 @@ public static void main(String[] args) { String NO_ANALYSIS_OPTION = "no-analysis"; String ENABLE_ASYNC_CALL_OPTION = "enable-async-call"; + String TRANSACTION_VERSION = "transaction-version"; + Option transactionVersion = + new Option( + "t", + TRANSACTION_VERSION, + true, + "[Optional] Specify transaction version interface, default is 0; If you want to use the latest transaction interface, please specify 1."); + transactionVersion.setRequired(false); + options.addOption(transactionVersion); if (mode.equals("solidity")) { Option solidityFilePathOption = new Option( @@ -934,6 +950,7 @@ public static void main(String[] args) { String pkgName = cmd.getOptionValue(PACKAGE_OPTION, DEFAULT_PACKAGE); String javaDir = cmd.getOptionValue(OUTPUT_OPTION, DEFAULT_OUTPUT); + String transactionVersionStr = "V" + cmd.getOptionValue(TRANSACTION_VERSION, "0"); if (mode.equals("solidity")) { String solPathOrDir = cmd.getOptionValue(SOL_OPTION, DEFAULT_SOL); String librariesOption = cmd.getOptionValue(LIBS_OPTION, ""); @@ -963,7 +980,8 @@ public static void main(String[] args) { librariesOption, specifyContract, useDagAnalysis, - enableAsyncCall); + enableAsyncCall, + transactionVersionStr); } else { // input dir compileAllSolToJava( fullJavaDir, @@ -972,7 +990,8 @@ public static void main(String[] args) { ABI_PATH, BIN_PATH, useDagAnalysis, - enableAsyncCall); + enableAsyncCall, + transactionVersionStr); } } catch (IOException | CompileContractException e) { System.out.print(e.getMessage()); @@ -985,15 +1004,20 @@ public static void main(String[] args) { String abiFile = cmd.getOptionValue(ABI_OPTION); String binFile = cmd.getOptionValue(BIN_OPTION); String smBinFile = cmd.getOptionValue(SM_BIN_OPTION); - CodeGenMain.main( - Arrays.asList( + List params = + new ArrayList<>( + Arrays.asList( "-v", "V3", "-a", abiFile, "-b", binFile, "-s", smBinFile, "-p", pkgName, - "-o", javaDir) - .toArray(new String[0])); + "-o", javaDir)); + if (!transactionVersionStr.equals("0")) { + params.add("-t"); + params.add(transactionVersionStr); + } + CodeGenMain.main(params.toArray(new String[0])); } } } diff --git a/src/main/java/console/contract/ConsoleContractImpl.java b/src/main/java/console/contract/ConsoleContractImpl.java index 74113d32..2c0d4798 100644 --- a/src/main/java/console/contract/ConsoleContractImpl.java +++ b/src/main/java/console/contract/ConsoleContractImpl.java @@ -260,7 +260,7 @@ public TransactionResponse deploySolidity( DeployTransactionRequestWithStringParams request = new TransactionRequestBuilder(abiAndBin.getAbi(), bin) .buildDeployStringParamsRequest(tempInputParams); - response = assembleTransactionService.deployContractWithStringParams(request); + response = assembleTransactionService.deployContract(request); } else { response = this.assembleTransactionProcessor.deployAndGetResponseWithStringParams( @@ -325,7 +325,7 @@ public TransactionResponse deployWasm( new TransactionRequestBuilder(abi, binStr) .setTo(path) .buildDeployStringParamsRequest(inputParams); - response = assembleTransactionService.deployContractWithStringParams(request); + response = assembleTransactionService.deployContract(request); } else { response = this.assembleTransactionProcessor.deployAndGetResponseWithStringParams( @@ -760,7 +760,7 @@ private void sendTransaction( TransactionRequestWithStringParams request = new TransactionRequestBuilder(abiAndBin.getAbi(), functionName, contractAddress) .buildStringParamsRequest(callParams); - response = assembleTransactionService.sendTransactionWithStringParams(request); + response = assembleTransactionService.sendTransaction(request); } else { response = assembleTransactionProcessor.sendTransactionWithStringParamsAndGetResponse(