-
Notifications
You must be signed in to change notification settings - Fork 363
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
sdk/java: add CoreConfig class #1055
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2ad668
sdk/java: add CoreConfig class
jeffomatic 8e446ae
jfmt
jeffomatic 64b20db
add integration test
jeffomatic 0fb7f9a
jfmt
jeffomatic eb33017
fix CI build
jeffomatic 9f0fc25
lowercase boolean for input
jeffomatic a3979f6
lowercase everywhere
jeffomatic aedc009
try to fix wercker
jeffomatic eed8db1
auto rev id
iampogo 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 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 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
public final class RevId { | ||
public final String Id = "main/rev3032"; | ||
public final String Id = "main/rev3033"; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package rev | ||
|
||
const ID string = "main/rev3032" | ||
const ID string = "main/rev3033" |
This file contains 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
export const rev_id = "main/rev3032" | ||
export const rev_id = "main/rev3033" |
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
module Chain::Rev | ||
ID = "main/rev3032".freeze | ||
ID = "main/rev3033".freeze | ||
end |
This file contains 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,141 @@ | ||
package com.chain.api; | ||
|
||
import com.chain.http.*; | ||
import com.chain.exception.*; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import java.util.*; | ||
|
||
public class CoreConfig { | ||
|
||
public static class Info { | ||
public String state; | ||
|
||
@SerializedName("is_configured") | ||
public boolean isConfigured; | ||
|
||
@SerializedName("configured_at") | ||
public Date configuredAt; | ||
|
||
@SerializedName("is_signer") | ||
public boolean isSigner; | ||
|
||
@SerializedName("is_generator") | ||
public boolean isGenerator; | ||
|
||
@SerializedName("generator_url") | ||
public String generatorUrl; | ||
|
||
@SerializedName("generator_access_token") | ||
public String generatorAccessToken; | ||
|
||
@SerializedName("blockchain_id") | ||
public String blockchainId; | ||
|
||
@SerializedName("block_height") | ||
public long blockHeight; | ||
|
||
@SerializedName("generator_block_height") | ||
public long generatorBlockHeight; | ||
|
||
@SerializedName("generator_block_height_fetched_at") | ||
public Date generatorBlockHeightFetchedAt; | ||
|
||
@SerializedName("network_rpc_version") | ||
public int networkRpcVersion; | ||
|
||
@SerializedName("core_id") | ||
public String coreId; | ||
|
||
public String version; | ||
|
||
@SerializedName("build_commit") | ||
public String buildCommit; | ||
|
||
@SerializedName("build_date") | ||
public String buildDate; | ||
|
||
@SerializedName("build_config") | ||
public BuildConfig buildConfig; | ||
|
||
public Map<String, Object> health; | ||
|
||
public Snapshot snapshot; | ||
|
||
public static class BuildConfig { | ||
@SerializedName("is_loopback_auth") | ||
public boolean isLoopbackAuth; | ||
|
||
@SerializedName("is_mockhsm") | ||
public boolean isMockHsm; | ||
|
||
@SerializedName("is_reset") | ||
public boolean isReset; | ||
} | ||
|
||
public static class Snapshot { | ||
public int attempt; | ||
|
||
public long height; | ||
|
||
public long size; | ||
|
||
public long downloaded; | ||
|
||
@SerializedName("in_progress") | ||
public boolean inProgress; | ||
} | ||
} | ||
|
||
public static Info getInfo(Client client) throws ChainException { | ||
return client.request("info", null, Info.class); | ||
} | ||
|
||
public static void reset(Client client) throws ChainException { | ||
client.request("reset", null, SuccessMessage.class); | ||
} | ||
|
||
public static void resetEverything(Client client) throws ChainException { | ||
Map<String, Object> params = new HashMap<>(); | ||
params.put("everything", true); | ||
client.request("reset", params, SuccessMessage.class); | ||
} | ||
|
||
public static class Builder { | ||
@SerializedName("is_generator") | ||
private boolean isGenerator; | ||
|
||
@SerializedName("generator_url") | ||
private String generatorUrl; | ||
|
||
@SerializedName("generator_access_token") | ||
private String generatorAccessToken; | ||
|
||
@SerializedName("blockchain_id") | ||
private String blockchainId; | ||
|
||
public Builder setIsGenerator(boolean isGenerator) { | ||
this.isGenerator = isGenerator; | ||
return this; | ||
} | ||
|
||
public Builder setGeneratorUrl(String url) { | ||
generatorUrl = url; | ||
return this; | ||
} | ||
|
||
public Builder setGeneratorAccessToken(String token) { | ||
generatorAccessToken = token; | ||
return this; | ||
} | ||
|
||
public Builder setBlockchainId(String blockchainId) { | ||
this.blockchainId = blockchainId; | ||
return this; | ||
} | ||
|
||
public void configure(Client client) throws ChainException { | ||
client.request("configure", this); | ||
} | ||
} | ||
} |
This file contains 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
25 changes: 25 additions & 0 deletions
25
sdk/java/src/test/java/com/chain/integration/CoreConfigTest.java
This file contains 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,25 @@ | ||
package com.chain.integration; | ||
|
||
import com.chain.api.*; | ||
import com.chain.http.*; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class CoreConfigTest { | ||
@Test | ||
public void run() throws Exception { | ||
Client c = new Client(); | ||
|
||
CoreConfig.Info info = CoreConfig.getInfo(c); | ||
assertTrue(info.isConfigured); | ||
|
||
CoreConfig.resetEverything(c); | ||
info = CoreConfig.getInfo(c); | ||
assertFalse(info.isConfigured); | ||
|
||
new CoreConfig.Builder().setIsGenerator(true).configure(c); | ||
info = CoreConfig.getInfo(c); | ||
assertTrue(info.isConfigured); | ||
} | ||
} |
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.
is there any more schema to this that we can provide? it's a little unclear how to use this as-is. If I understand the cored code right, this map would look something like:
Maybe instead of a Map<String,Object> this should be a separate class? Even if we only expose a method that returns this map, it'll give us the flexibility to introduce more convenience methods down the road.
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.
I think this also might be the most useful of the fields exposed here, so I don't feel like it's over-engineering to ensure we can make it easy to access.
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.
Agreed. Let's land this PR and follow up with something. How confident are you in the stability of the structure of the health object?
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.
Might want to ask @kr, I'm not really sure.