From 4ccdd183757fee1d13e54fee2ba5fd9a00ae11ce Mon Sep 17 00:00:00 2001 From: kyonRay Date: Tue, 5 Sep 2023 16:43:34 +0800 Subject: [PATCH] (transaction): fix call with sign result not handle revert message bug, add system features. --- .../sysconfig/SystemConfigFeature.java | 44 +++++++++++++++++++ .../bcos/sdk/v3/model/EnumNodeVersion.java | 8 +++- .../manager/AssembleTransactionProcessor.java | 30 ++++++++----- 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigFeature.java diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigFeature.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigFeature.java new file mode 100644 index 000000000..ccd271ce4 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigFeature.java @@ -0,0 +1,44 @@ +package org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig; + +import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; + +public class SystemConfigFeature { + public enum Features { + BUGFIX_REVERT("bugfix_revert", EnumNodeVersion.BCOS_3_2_3.getVersion()), + FEATURE_SHARDING("feature_sharding", EnumNodeVersion.BCOS_3_5_0.getVersion()), + FEATURE_RPBFT("feature_rpbft", EnumNodeVersion.BCOS_3_5_0.getVersion()), + FEATURE_PAILLIER("feature_paillier", EnumNodeVersion.BCOS_3_5_0.getVersion()); + + private final String featureName; + private final int enableVersion; + + Features(String name, int enableVersion) { + this.featureName = name; + this.enableVersion = enableVersion; + } + + @Override + public String toString() { + return featureName; + } + + public int enableVersion() { + return enableVersion; + } + } + + public static Features fromString(String name) { + switch (name) { + case "bugfix_revert": + return Features.BUGFIX_REVERT; + case "feature_sharding": + return Features.FEATURE_SHARDING; + case "feature_rpbft": + return Features.FEATURE_RPBFT; + case "feature_paillier": + return Features.FEATURE_PAILLIER; + default: + return null; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/model/EnumNodeVersion.java b/src/main/java/org/fisco/bcos/sdk/v3/model/EnumNodeVersion.java index ea357c7c3..93a950bdb 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/model/EnumNodeVersion.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/model/EnumNodeVersion.java @@ -9,8 +9,10 @@ public enum EnumNodeVersion { BCOS_3_0_0(0x03000000), BCOS_3_1_0(0x03010000), BCOS_3_2_0(0x03020000), + BCOS_3_2_3(0x03020300), BCOS_3_3_0(0x03030000), - BCOS_3_4_0(0x03040000); + BCOS_3_4_0(0x03040000), + BCOS_3_5_0(0x03050000); private final Integer version; private static final Map versionLookupMap = new HashMap<>(); @@ -20,8 +22,10 @@ public enum EnumNodeVersion { versionLookupMap.put(0x03000000, BCOS_3_0_0); versionLookupMap.put(0x03010000, BCOS_3_1_0); versionLookupMap.put(0x03020000, BCOS_3_2_0); + versionLookupMap.put(0x03020300, BCOS_3_2_3); versionLookupMap.put(0x03030000, BCOS_3_3_0); versionLookupMap.put(0x03040000, BCOS_3_4_0); + versionLookupMap.put(0x03050000, BCOS_3_5_0); } EnumNodeVersion(Integer version) { @@ -46,6 +50,8 @@ public String getVersionString() { return "3.3.0"; case BCOS_3_4_0: return "3.4.0"; + case BCOS_3_5_0: + return "3.5.0"; case UNKNOWN: default: return "0.0.0"; diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/AssembleTransactionProcessor.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/AssembleTransactionProcessor.java index 0efb08a0b..9cfb54300 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/AssembleTransactionProcessor.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/AssembleTransactionProcessor.java @@ -883,35 +883,43 @@ public CallResponse callAndGetResponse( String from, String to, String abi, String functionName, byte[] data) throws ContractCodecException, TransactionBaseException { Call call = this.executeCall(from, to, data); + CallResponse callResponse = this.parseCallResponseStatus(call.getCallResult()); ABIObject decodedResult = this.contractCodec.decodeMethodAndGetOutputAbiObject( abi, functionName, call.getCallResult().getOutput()); - return getCallResponse(call, decodedResult); + Pair, List> outputObject = + ContractCodecTools.decodeJavaObjectAndGetOutputObject(decodedResult); + callResponse.setReturnObject(outputObject.getLeft()); + callResponse.setReturnABIObject(outputObject.getRight()); + try { + callResponse.setResults(ContractCodecTools.getABIObjectTypeListResult(decodedResult)); + } catch (Exception ignored) { + log.error("decode results failed, ignored. value: {}", decodedResult); + } + return callResponse; } public CallResponse callAndGetResponse( String from, String to, ABIDefinition abiDefinition, byte[] data) throws ContractCodecException, TransactionBaseException { Call call = this.executeCall(from, to, data); - ABIObject abiObject = - contractCodec.decodeMethodAndGetOutAbiObjectByABIDefinition( - abiDefinition, call.getCallResult().getOutput()); - return getCallResponse(call, abiObject); + return getCallResponse(call, abiDefinition); } public CallResponse callWithSignAndGetResponse( String from, String to, ABIDefinition abiDefinition, byte[] data) throws ContractCodecException, TransactionBaseException { Call call = this.executeCallWithSign(from, to, data); - ABIObject abiObject = - contractCodec.decodeMethodAndGetOutAbiObjectByABIDefinition( - abiDefinition, call.getCallResult().getOutput()); - return getCallResponse(call, abiObject); + + return getCallResponse(call, abiDefinition); } - public CallResponse getCallResponse(Call call, ABIObject decodedResult) - throws TransactionBaseException { + public CallResponse getCallResponse(Call call, ABIDefinition abiDefinition) + throws TransactionBaseException, ContractCodecException { CallResponse callResponse = this.parseCallResponseStatus(call.getCallResult()); + ABIObject decodedResult = + contractCodec.decodeMethodAndGetOutAbiObjectByABIDefinition( + abiDefinition, call.getCallResult().getOutput()); Pair, List> outputObject = ContractCodecTools.decodeJavaObjectAndGetOutputObject(decodedResult); callResponse.setReturnObject(outputObject.getLeft());