-
Notifications
You must be signed in to change notification settings - Fork 30
Update LC with DS changes [ECR-3860] #1244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
b35a48e
76b4050
dbc08c9
589f861
cc470a0
9fb0e60
453c623
9c1a4a8
dfde8ce
003a8e1
2bff988
41d708e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,17 +18,21 @@ | |
| package com.exonum.client; | ||
|
|
||
| import static com.exonum.client.ExonumApi.JSON; | ||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| import com.exonum.binding.common.blockchain.ExecutionStatuses; | ||
| import com.exonum.binding.common.blockchain.TransactionLocation; | ||
| import com.exonum.binding.common.blockchain.TransactionResult; | ||
| import com.exonum.binding.common.hash.HashCode; | ||
| import com.exonum.binding.common.message.TransactionMessage; | ||
| import com.exonum.client.response.Block; | ||
| import com.exonum.client.response.BlockResponse; | ||
| import com.exonum.client.response.BlocksResponse; | ||
| import com.exonum.client.response.TransactionResponse; | ||
| import com.exonum.client.response.TransactionStatus; | ||
| import com.exonum.core.messages.Runtime.ErrorKind; | ||
| import com.exonum.core.messages.Runtime.ExecutionError; | ||
| import com.exonum.core.messages.Runtime.ExecutionStatus; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does it come here? Is it a part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it is, but, ideally, it mustn't be a part of it, but a dependency of it. I think we shall extract the messages into a separate module (or modules, if we believe that some messages are not needed everywhere, e.g., supervisor messages, or merkledb messages) that will have not just have its own package, but its own release cadence (since the main reason for their release is a new Exonum release). |
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.gson.JsonArray; | ||
|
|
@@ -58,7 +62,7 @@ static HashCode parseSubmitTxResponse(String json) { | |
|
|
||
| static TransactionResponse parseGetTxResponse(String json) { | ||
| GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); | ||
| TransactionResult executionResult = getTransactionResult(response.getStatus()); | ||
| ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); | ||
|
|
||
| return new TransactionResponse( | ||
| response.getType(), | ||
|
|
@@ -87,25 +91,48 @@ static BlocksResponse parseGetBlocksResponse(String json) { | |
| ); | ||
| } | ||
|
|
||
| private static TransactionResult getTransactionResult( | ||
| private static ExecutionStatus getExecutionStatus( | ||
| GetTxResponseExecutionResult executionStatus) { | ||
| if (executionStatus == null) { | ||
| return null; | ||
| } | ||
| switch (executionStatus.getType()) { | ||
| case SUCCESS: | ||
| return TransactionResult.successful(); | ||
| case ERROR: | ||
| return TransactionResult.error(executionStatus.getCode(), | ||
| executionStatus.getDescription()); | ||
| return ExecutionStatuses.success(); | ||
| case PANIC: | ||
| return TransactionResult.unexpectedError(executionStatus.getDescription()); | ||
| return buildPanicExecutionStatus(executionStatus.getDescription()); | ||
| case DISPATCHER_ERROR: | ||
| return buildExecutionStatus(ErrorKind.DISPATCHER, executionStatus.getCode(), | ||
| executionStatus.getDescription()); | ||
| case RUNTIME_ERROR: | ||
| return buildExecutionStatus(ErrorKind.RUNTIME, executionStatus.getCode(), | ||
| executionStatus.getDescription()); | ||
| case SERVICE_ERROR: | ||
| return ExecutionStatuses.serviceError(executionStatus.getCode(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not complete — see below. |
||
| executionStatus.getDescription()); | ||
| default: | ||
| throw new IllegalStateException("Unexpected transaction execution status: " | ||
| + executionStatus.getType()); | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static ExecutionStatus buildPanicExecutionStatus(String description) { | ||
| return buildExecutionStatus(ErrorKind.PANIC, 0, description); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static ExecutionStatus buildExecutionStatus(ErrorKind errorKind, int code, | ||
| String description) { | ||
| checkArgument(0 <= code, "Error code (%s) must be non-negative", code); | ||
| return ExecutionStatus.newBuilder() | ||
| .setError(ExecutionError.newBuilder() | ||
| .setKind(errorKind) | ||
| .setCode(code) | ||
| .setDescription(description)) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Json object wrapper for submit transaction request. | ||
| */ | ||
|
|
@@ -137,7 +164,7 @@ private static class GetTxResponse { | |
| } | ||
|
|
||
| /** | ||
| * Json object wrapper for get transaction response content i.e. | ||
| * Json object wrapper for get transaction response content, i.e., | ||
| * {@code "$.content"}. | ||
| */ | ||
| @Value | ||
|
|
@@ -148,7 +175,7 @@ private static class GetTxResponseContent { | |
| } | ||
|
|
||
| /** | ||
| * Json object wrapper for transaction execution result i.e. | ||
| * Json object wrapper for transaction execution result, i.e., | ||
| * {@code "$.status"}. | ||
| */ | ||
| @Value | ||
|
|
@@ -159,16 +186,20 @@ private static class GetTxResponseExecutionResult { | |
| } | ||
|
|
||
| /** | ||
| * Json object wrapper for transaction execution status i.e. | ||
| * Json object wrapper for transaction execution status, i.e., | ||
| * {@code "$.status.type"}. | ||
| */ | ||
| private enum GetTxResponseExecutionStatus { | ||
| @SerializedName("success") | ||
| SUCCESS, | ||
| @SerializedName("error") | ||
| ERROR, | ||
| @SerializedName("panic") | ||
| PANIC | ||
| PANIC, | ||
| @SerializedName("dispatcher_error") | ||
| DISPATCHER_ERROR, | ||
| @SerializedName("runtime_error") | ||
| RUNTIME_ERROR, | ||
| @SerializedName("service_error") | ||
| SERVICE_ERROR | ||
| } | ||
|
|
||
| @Value | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused.