Skip to content

Commit

Permalink
<feat&fix>(transaction): fix call with sign result not handle revert …
Browse files Browse the repository at this point in the history
…message bug, add system features. (FISCO-BCOS#819)
  • Loading branch information
kyonRay committed Oct 12, 2023
1 parent 165e3ea commit 2f184e8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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_RPBFT_EPOCH_BLOCK_NUM(
"feature_rpbft_epoch_block_num", EnumNodeVersion.BCOS_3_5_0.getVersion()),
FEATURE_RPBFT_EPOCH_SEALER_NUM(
"feature_rpbft_epoch_sealer_num", 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_rpbft_epoch_block_num":
return Features.FEATURE_RPBFT_EPOCH_BLOCK_NUM;
case "feature_rpbft_epoch_sealer_num":
return Features.FEATURE_RPBFT_EPOCH_SEALER_NUM;
case "feature_paillier":
return Features.FEATURE_PAILLIER;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, EnumNodeVersion> versionLookupMap = new HashMap<>();
Expand All @@ -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) {
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>, List<ABIObject>> 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<Object>, List<ABIObject>> outputObject =
ContractCodecTools.decodeJavaObjectAndGetOutputObject(decodedResult);
callResponse.setReturnObject(outputObject.getLeft());
Expand Down

0 comments on commit 2f184e8

Please sign in to comment.