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 a00743a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 33 deletions.
27 changes: 15 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 @@ -1718,41 +1718,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());
}
}
}
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 a00743a

Please sign in to comment.