-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b35a48e
ECR-3860 Update LC with DS changes
MakarovS 76b4050
Merge remote-tracking branch 'origin/master' into ECR-3860
MakarovS dbc08c9
ECR-3860 Review fixes
MakarovS 589f861
ECR-3860 Minor changelog fix
MakarovS cc470a0
ECR-3860 Add other possible execution statuses
MakarovS 9fb0e60
Merge remote-tracking branch 'origin/master' into ECR-3860
MakarovS 453c623
ECR-3860 Refactor ExplorerApiHelperTest
MakarovS 9c1a4a8
ECR-3860 Use arguments method
MakarovS dfde8ce
ECR-3860 Change Transaction format
MakarovS 003a8e1
Merge remote-tracking branch 'remotes/origin/master' into ECR-3860
MakarovS 2bff988
ECR-3860 Remove time and redundant pom property
MakarovS 41d708e
Merge remote-tracking branch 'remotes/origin/master' into ECR-3860
MakarovS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.gson.JsonArray; | ||
|
@@ -58,11 +62,11 @@ 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(), | ||
response.getContent().getMessage(), | ||
response.getContent(), | ||
executionResult, | ||
response.getLocation() | ||
); | ||
|
@@ -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. | ||
*/ | ||
|
@@ -130,25 +157,14 @@ private static class GetTxResponse { | |
@NonNull | ||
TransactionStatus type; | ||
@NonNull | ||
GetTxResponseContent content; | ||
TransactionMessage content; | ||
TransactionLocation location; | ||
JsonObject locationProof; //TODO: in scope of LC P3 | ||
GetTxResponseExecutionResult status; | ||
} | ||
|
||
/** | ||
* Json object wrapper for get transaction response content i.e. | ||
* {@code "$.content"}. | ||
*/ | ||
@Value | ||
private static class GetTxResponseContent { | ||
JsonObject debug; // contains executable tx in json. currently not supported | ||
@NonNull | ||
TransactionMessage message; | ||
} | ||
|
||
/** | ||
* Json object wrapper for transaction execution result i.e. | ||
* Json object wrapper for transaction execution result, i.e., | ||
* {@code "$.status"}. | ||
*/ | ||
@Value | ||
|
@@ -159,16 +175,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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
how does it come here? Is it a part of
exonum-java-binding-common
? I meanexonum.core.
packageThere 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.
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).