-
Notifications
You must be signed in to change notification settings - Fork 30
[ECR-2906] LC: Implemented System API endpoints support #716
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
19 commits
Select commit
Hold shift + click to select a range
0ebdd95
Implemented System API endpoints support
bullet-tooth 7b33137
test rename
bullet-tooth 7c6d080
fmt
bullet-tooth c5fd9f6
fmt
bullet-tooth 80334bc
Revert lombok changes incidentally committed
bullet-tooth 411a1a6
added javadocs
bullet-tooth c7746a4
Merge branch 'master' into ecr-2906
bullet-tooth 0aae6e6
fixed PR comments
bullet-tooth e0db8ff
fix build
bullet-tooth 688f924
Merge branch 'master' into ecr-2906
bullet-tooth a97222c
fix javadocs
bullet-tooth e4a4969
Merge remote-tracking branch 'origin/ecr-2906' into ecr-2906
bullet-tooth 515bc2c
revert user agent response parsing
bullet-tooth 6d819b2
Fixed PR comments
bullet-tooth 8ab36f1
helpers composition
bullet-tooth 0e5dc5c
javadoc update
bullet-tooth 826c351
added todo
bullet-tooth 809be09
Merge branch 'master' into ecr-2906
bullet-tooth 6562719
Fix PR comments
bullet-tooth 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
64 changes: 64 additions & 0 deletions
64
exonum-light-client/src/main/java/com/exonum/client/ExplorerApiHelper.java
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.exonum.client; | ||
|
||
import static com.exonum.binding.common.serialization.json.JsonSerializer.json; | ||
|
||
import com.exonum.binding.common.hash.HashCode; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Value; | ||
|
||
/** | ||
* Utility class for Exonum Explorer API. | ||
*/ | ||
final class ExplorerApiHelper { | ||
|
||
static String createSubmitTxBody(String message) { | ||
SubmitTxRequest request = new SubmitTxRequest(message); | ||
return json().toJson(request); | ||
} | ||
|
||
static HashCode parseSubmitTxResponse(String json) { | ||
SubmitTxResponse response = json().fromJson(json, SubmitTxResponse.class); | ||
return response.getHash(); | ||
} | ||
|
||
/** | ||
* Json object wrapper for submit transaction request. | ||
*/ | ||
@Value | ||
@VisibleForTesting | ||
static class SubmitTxRequest { | ||
@SerializedName("tx_body") | ||
String body; | ||
} | ||
|
||
/** | ||
* Json object wrapper for submit transaction response. | ||
*/ | ||
@Value | ||
private static class SubmitTxResponse { | ||
@SerializedName("tx_hash") | ||
HashCode hash; | ||
} | ||
|
||
private ExplorerApiHelper() { | ||
throw new UnsupportedOperationException("Not instantiable"); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
exonum-light-client/src/main/java/com/exonum/client/SystemApiHelper.java
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.exonum.client; | ||
|
||
import static com.exonum.binding.common.serialization.json.JsonSerializer.json; | ||
|
||
import com.exonum.client.response.ConsensusStatus; | ||
import com.exonum.client.response.HealthCheckInfo; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Value; | ||
|
||
/** | ||
* Utility class for Exonum System API. | ||
*/ | ||
final class SystemApiHelper { | ||
|
||
static HealthCheckInfo parseHealthCheckJson(String json) { | ||
// TODO: ECR-2925 (core dependency) change after the response format update | ||
HealthCheckResponse response = json().fromJson(json, HealthCheckResponse.class); | ||
String consensusStatus = response.getConsensusStatus().toUpperCase(); | ||
JsonElement connectivity = response.getConnectivity(); | ||
if (connectivity.isJsonObject()) { | ||
JsonObject connectivityObject = connectivity.getAsJsonObject(); | ||
int connectionsNumber = connectivityObject | ||
.get("Connected").getAsJsonObject() | ||
.get("amount").getAsInt(); | ||
return new HealthCheckInfo(ConsensusStatus.valueOf(consensusStatus), connectionsNumber); | ||
} else { | ||
return new HealthCheckInfo(ConsensusStatus.valueOf(consensusStatus), 0); | ||
} | ||
} | ||
|
||
static int parseMemoryPoolJson(String json) { | ||
MemoryPoolResponse response = json().fromJson(json, MemoryPoolResponse.class); | ||
return response.getSize(); | ||
} | ||
|
||
/** | ||
* Json object wrapper for memory pool response. | ||
*/ | ||
@Value | ||
private static class MemoryPoolResponse { | ||
int size; | ||
} | ||
|
||
/** | ||
* Json object wrapper for health check response. | ||
*/ | ||
@Value | ||
private class HealthCheckResponse { | ||
@SerializedName("consensus_status") | ||
String consensusStatus; | ||
JsonElement connectivity; | ||
} | ||
|
||
private SystemApiHelper() { | ||
throw new UnsupportedOperationException("Not instantiable"); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -15,16 +15,23 @@ | |
* | ||
*/ | ||
|
||
package com.exonum.client; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.Value; | ||
package com.exonum.client.response; | ||
|
||
/** | ||
* Json object wrapper for submit transaction request. | ||
* Consensus status of a particular node. | ||
*/ | ||
@Value | ||
class SubmitTxRequest { | ||
@SerializedName("tx_body") | ||
String body; | ||
public enum ConsensusStatus { | ||
/** | ||
* Shows that consensus is active | ||
* i.e. it is enabled and the node has enough connected peers. | ||
*/ | ||
ACTIVE, | ||
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. Do you happen to know the difference between these two? As it is public, I'd document it. |
||
/** | ||
* Shows that consensus is enabled on the node. | ||
*/ | ||
ENABLED, | ||
/** | ||
* Shows that consensus is disabled on the node. | ||
*/ | ||
DISABLED | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.