Skip to content

Commit

Permalink
<fix>(transaction,contract): fix transaction builder set extension ve…
Browse files Browse the repository at this point in the history
…rsion bug.
  • Loading branch information
kyonRay committed Jun 11, 2024
1 parent 9cb825c commit 5c8b203
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public void testClient() {
"New block, group: " + groupId + ", blockNumber: " + blockNumber));

Map<String, Optional<SystemConfig>> systemConfigList = client.getSystemConfigList();
Assert.assertFalse(systemConfigList.isEmpty());
systemConfigList.forEach(
(key, value) ->
System.out.println(
Expand Down
38 changes: 26 additions & 12 deletions src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import org.fisco.bcos.sdk.jni.BcosSDKJniObj;
import org.fisco.bcos.sdk.jni.rpc.RpcJniObj;
import org.fisco.bcos.sdk.v3.client.exceptions.ClientException;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.fisco.bcos.sdk.v3.client.protocol.response.SystemConfig;
import org.fisco.bcos.sdk.v3.client.protocol.response.TotalTransactionCount;
import org.fisco.bcos.sdk.v3.config.ConfigOption;
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.crypto.CryptoSuite;
import org.fisco.bcos.sdk.v3.model.CryptoType;
Expand Down Expand Up @@ -1070,6 +1072,11 @@ public void onResponse(BcosGroupInfoList bcosGroupInfoList) {
.filter(gInfo -> gInfo.getGroupID().equals(getGroup()))
.findFirst();
Set<String> keys = new TreeSet<>();
keys.addAll(
Arrays.stream(SystemConfigFeature.Features.values())
.map(SystemConfigFeature.Features::toString)
.collect(Collectors.toList()));
keys.addAll(SystemConfigService.getConfigKeys());
if (group.isPresent() && !group.get().getNodeList().isEmpty()) {
group.get()
.getNodeList()
Expand Down Expand Up @@ -1099,6 +1106,10 @@ public void getSystemConfigListAsync(
public void onResponse(Set<String> keys) {
Map<String, Optional<SystemConfig>> configMap =
new ConcurrentSkipListMap<>();
if (keys.isEmpty()) {
callback.onResponse(configMap);
return;
}
keys.forEach(
key ->
getSystemConfigByKeyAsync(
Expand Down Expand Up @@ -1718,41 +1729,44 @@ public static <T extends JsonRpcResponse<?>> T parseResponseIntoJsonRpcResponse(
// parse the response into JsonRPCResponse
T jsonRpcResponse =
getObjectMapper().readValue(response.getContent(), responseType);
if (jsonRpcResponse.getError() != null) {
logger.error(
"parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, retErrorMessage: {}, retErrorCode: {}",
// error code inside json rpc response
if (jsonRpcResponse.hasError()) {
logger.info(
"parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, msg: {}, code: {}, rawRsp: {}",
method,
jsonRpcResponse.getError().getMessage(),
jsonRpcResponse.getError().getCode());
jsonRpcResponse.getError().getCode(),
response.getContentString());
throw new ClientException(
jsonRpcResponse.getError().getCode(),
jsonRpcResponse.getError().getMessage(),
"ErrorMessage: " + jsonRpcResponse.getError().getMessage());
"msg: " + jsonRpcResponse.getError().getMessage());
}
return jsonRpcResponse;
} else {
logger.error(
"parseResponseIntoJsonRpcResponse failed, method: {}, retErrorMessage: {}, retErrorCode: {}",
logger.info(
"parseResponseIntoJsonRpcResponse failed, method: {}, msg: {}, code: {}, rawRsp: {}",
method,
response.getErrorMessage(),
response.getErrorCode());
response.getErrorCode(),
response.getContent());
throw new ClientException(
response.getErrorCode(),
response.getErrorMessage(),
"get response failed, errorCode: "
"get response failed, code: "
+ response.getErrorCode()
+ ", error message: "
+ ", msg: "
+ response.getErrorMessage());
}
} catch (ClientException e) {
logger.error(
logger.info(
"parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}",
response,
e.getMessage(),
e);
throw e;
} catch (Exception e) {
logger.error(
logger.info(
"parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}",
response,
e.getMessage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public String toString() {
+ ", errorMessage='"
+ errorMessage
+ '\''
+ ", msg="
+ getMessage()
+ '}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NetworkConfig {

private List<String> peers;
private List<String> tarsPeers;
private int timeout = -1;
private int timeout = 10000; // ms
private String defaultGroup;
private boolean sendRpcRequestToHighestBlockNode = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,20 +898,29 @@ private RetCode getRetCode(

private void getExecEvent(TransactionReceipt tr, BigInteger proposalId)
throws ContractException {
List<CommitteeManager.ExecResultEventResponse> execResultEvents =
committeeManager.getExecResultEvents(tr);
if (!execResultEvents.isEmpty()) {
BigInteger execResultParam0 = execResultEvents.get(0).execResultParam0;
if (!BigInteger.ZERO.equals(execResultParam0)) {
RetCode precompiledResponse =
PrecompiledRetCode.getPrecompiledResponse(execResultParam0.intValue(), "");
throw new ContractException(
"Exec proposal finished with error occurs, proposalId: "
+ proposalId
+ ", exec error msg: "
+ precompiledResponse.getMessage(),
precompiledResponse.getCode());
try {
List<CommitteeManager.ExecResultEventResponse> execResultEvents =
committeeManager.getExecResultEvents(tr);
if (!execResultEvents.isEmpty()) {
BigInteger execResultParam0 = execResultEvents.get(0).execResultParam0;
if (!BigInteger.ZERO.equals(execResultParam0)) {
RetCode precompiledResponse =
PrecompiledRetCode.getPrecompiledResponse(
execResultParam0.intValue(), "");
throw new ContractException(
"Exec proposal finished with error occurs, proposalId: "
+ proposalId
+ ", exec error msg: "
+ precompiledResponse.getMessage(),
precompiledResponse.getCode());
}
}
} catch (Exception e) {
throw new ContractException(
"Exec proposal finished with exception, proposalId: "
+ proposalId
+ ", exception msg: "
+ e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.fisco.bcos.sdk.v3.client.Client;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class SystemConfigService {
predicateMap.put(
TX_GAS_LIMIT, value -> value.compareTo(BigInteger.valueOf(TX_GAS_LIMIT_MIN)) >= 0);
predicateMap.put(TX_GAS_PRICE, value -> value.compareTo(BigInteger.ZERO) >= 0);
predicateMap.put(COMPATIBILITY_VERSION, value -> true);
}

public SystemConfigService(Client client, CryptoKeyPair credential) {
Expand Down Expand Up @@ -150,6 +152,10 @@ public static boolean isCheckableInValueValidation(String key) {
return predicateMap.containsKey(key);
}

public static Set<String> getConfigKeys() {
return predicateMap.keySet();
}

public static boolean checkCompatibilityVersion(Client client, String version) {
try {
EnumNodeVersion.Version setVersion = EnumNodeVersion.getClassVersion(version);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/v3/model/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public byte[] getContent() {
return content;
}

public String getContentString() {
return new String(content);
}

public void setContent(byte[] content) {
this.content = content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public TransactionVersion getVersion() {
}

public void setVersion(TransactionVersion version) {
if (this.version.getValue() < version.getValue()) this.version = version;
}

public void setVersionForce(TransactionVersion version) {
this.version = version;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public TransactionRequestBuilder(String abi, String bin) {
this.bin = bin;
}

public TransactionRequestBuilder setVersion(TransactionVersion version) {
if (this.version.getValue() < version.getValue()) {
this.version = version;
}
return this;
}

public TransactionRequestBuilder setVersionForce(TransactionVersion version) {
this.version = version;
return this;
}

public TransactionRequestBuilder setMethod(String method) {
this.method = method;
return this;
Expand Down Expand Up @@ -66,31 +78,41 @@ public TransactionRequestBuilder setNonce(String nonce) {

public TransactionRequestBuilder setValue(BigInteger value) {
this.value = value;
if (value != null) this.version = TransactionVersion.V1;
if (value != null) {
return setVersion(TransactionVersion.V1);
}
return this;
}

public TransactionRequestBuilder setGasPrice(BigInteger gasPrice) {
this.gasPrice = gasPrice;
if (gasPrice != null) this.version = TransactionVersion.V1;
if (gasPrice != null) {
return setVersion(TransactionVersion.V1);
}
return this;
}

public TransactionRequestBuilder setGasLimit(BigInteger gasLimit) {
this.gasLimit = gasLimit;
if (gasLimit != null) this.version = TransactionVersion.V1;
if (gasLimit != null) {
return setVersion(TransactionVersion.V1);
}
return this;
}

public TransactionRequestBuilder setEIP1559Struct(EIP1559Struct eip1559Struct) {
this.eip1559Struct = eip1559Struct;
if (eip1559Struct != null) this.version = TransactionVersion.V1;
if (eip1559Struct != null) {
setVersion(TransactionVersion.V1);
}
return this;
}

public TransactionRequestBuilder setExtension(byte[] extension) {
this.extension = extension;
if (extension != null && extension.length > 0) this.version = TransactionVersion.V2;
if (extension != null && extension.length > 0) {
setVersion(TransactionVersion.V2);
}
return this;
}

Expand All @@ -116,7 +138,6 @@ public TransactionRequest buildRequest(List<Object> params) throws ContractExcep
this.gasLimit,
this.eip1559Struct,
this.extension);
sendTransactionRequest.setVersion(version);
sendTransactionRequest.setParams(params);
return sendTransactionRequest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class TransactionResponse extends CommonResponse {
private TransactionReceipt transactionReceipt;
private String contractAddress;
private String values;
@Deprecated private String values;
private String events;
private String receiptMessages;
private List<Object> returnObject;
Expand Down

0 comments on commit 5c8b203

Please sign in to comment.