From ec513bb82e46a3709354b2b1159112a1ee77c272 Mon Sep 17 00:00:00 2001 From: kyonRay Date: Tue, 11 Jun 2024 16:34:29 +0800 Subject: [PATCH] (transaction,contract): fix transaction builder set extension version bug. --- .../fisco/bcos/sdk/v3/client/ClientImpl.java | 27 +++++++------- .../v3/contract/auth/manager/AuthManager.java | 35 ++++++++++++------- .../org/fisco/bcos/sdk/v3/model/Response.java | 4 +++ .../transactionv1/dto/BasicRequest.java | 4 +++ .../utils/TransactionRequestBuilder.java | 33 +++++++++++++---- .../model/dto/TransactionResponse.java | 2 +- 6 files changed, 73 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java b/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java index fd9b0c710..2f9ead92e 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java @@ -1718,41 +1718,44 @@ public static > 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(), diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java index 6617119b8..faf1c8866 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java @@ -898,20 +898,29 @@ private RetCode getRetCode( private void getExecEvent(TransactionReceipt tr, BigInteger proposalId) throws ContractException { - List 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 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()); } } } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java b/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java index 5211edbb1..0e98fabb5 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java @@ -47,6 +47,10 @@ public byte[] getContent() { return content; } + public String getContentString() { + return new String(content); + } + public void setContent(byte[] content) { this.content = content; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java index 6e9973dc0..ba99e67ba 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java @@ -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; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java index e9ac22aa6..82bfab0aa 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java @@ -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; @@ -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; } @@ -116,7 +138,6 @@ public TransactionRequest buildRequest(List params) throws ContractExcep this.gasLimit, this.eip1559Struct, this.extension); - sendTransactionRequest.setVersion(version); sendTransactionRequest.setParams(params); return sendTransactionRequest; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java index 1afe41abb..737547baa 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java @@ -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 returnObject;