java-sdk发送交易超时,导致丢失交易问题
Closed this issue · 2 comments
shanyoufusu commented
在使用java-sdk调用同步接口发送交易时,因遇到网络波动导致获取交易回执超时,此时java-sdk直接返回ClientException,但交易已发送到链上并最终交易成功,但客户端因为没有拿到交易hash导致丢失这笔交易。
kyonRay commented
请提供使用的Java SDK版本,以及使用的发交易接口。
可以尝试使用异步接口,异步接口会先计算交易的哈希,上层拿到交易哈希可以先记录。
shanyoufusu commented
使用的是master分支,使用的是编译后生成的java智能合约类,最后调用方法走到了ClientImpl类里,出问题的地方在parseResponseIntoJsonRpcResponse这个地方,这里只对errCode是否等于0做判断,如果不等于0,直接抛出异常信息
if (response.getErrorCode() == 0) {
// parse the response into JsonRPCResponse
T jsonRpcResponse =
ObjectMapperFactory.getObjectMapper()
.readValue(response.getContent(), responseType);
if (jsonRpcResponse.getError() != null) {
logger.error(
"parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, retErrorMessage: {}, retErrorCode: {}",
method,
jsonRpcResponse.getError().getMessage(),
jsonRpcResponse.getError().getCode());
throw new ClientException(
jsonRpcResponse.getError().getCode(),
jsonRpcResponse.getError().getMessage(),
"ErrorMessage: " + jsonRpcResponse.getError().getMessage());
}
return jsonRpcResponse;
} else {
logger.error(
"parseResponseIntoJsonRpcResponse failed, method: {}, retErrorMessage: {}, retErrorCode: {}",
method,
response.getErrorMessage(),
response.getErrorCode());
throw new ClientException(
response.getErrorCode(),
response.getErrorMessage(),
"get response failed, errorCode: "
+ response.getErrorCode()
+ ", error message: "
+ response.getErrorMessage());
}
这里是否可以做多一点事,根据具体的code去做判断而不是直接抛出异常,调用同步的sendTransaction方法时,也是提前在本地算好了交易hash,只是交易hash字段没有作为参数传到后面调用方法中,只把signedTransactionData作为参数传递了下去。