-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from Concordium/supportNewEndpoints
Support new endpoints
- Loading branch information
Showing
11 changed files
with
474 additions
and
8 deletions.
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
42 changes: 42 additions & 0 deletions
42
...rdium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetBakerEarliestWinTime.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,42 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.responses.BakerId; | ||
import com.concordium.sdk.types.Timestamp; | ||
import picocli.CommandLine; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Creates a {@link ClientV2} from the specified connection ("http://localhost:20002" if not specified). | ||
* Retrieves and prints the {@link Timestamp} of the projected earliest time at which baker with id = 1 will be required to bake a block. | ||
*/ | ||
@CommandLine.Command(name = "GetBakerEarliestWinTime", mixinStandardHelpOptions = true) | ||
public class GetBakerEarliestWinTime implements Callable<Integer> { | ||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20002") | ||
private String endpoint; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
URL endpointUrl = new URL(this.endpoint); | ||
Connection connection = Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build(); | ||
|
||
ClientV2 client = ClientV2.from(connection); | ||
Timestamp timestamp = client.getBakerEarliestWinTime(BakerId.from(1)); | ||
System.out.println(timestamp); | ||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GetBakerEarliestWinTime()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
concordium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetFirstBlockEpoch.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,55 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.requests.EpochQuery; | ||
import com.concordium.sdk.responses.Epoch; | ||
import com.concordium.sdk.transactions.Hash; | ||
import picocli.CommandLine; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Creates a {@link ClientV2} from the specified connection ("http://localhost:20002" if not specified). | ||
* Retrieves and prints the {@link Hash} of the first finalized block for specified Epoch at the specified genesis index (Epoch 2 at genesis index 5 if not specified). | ||
*/ | ||
@CommandLine.Command(name = "GetFirstBlockEpoch", mixinStandardHelpOptions = true) | ||
public class GetFirstBlockEpoch implements Callable<Integer> { | ||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20002") | ||
private String endpoint; | ||
|
||
@CommandLine.Option( | ||
names = {"--genesisIndex"}, | ||
description = "Genesis index to query at", | ||
defaultValue = "5") | ||
private int genesisIndex; | ||
|
||
@CommandLine.Option( | ||
names = {"--epoch"}, | ||
description = "Epoch index to query", | ||
defaultValue = "5") | ||
private int epoch; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
URL endpointUrl = new URL(this.endpoint); | ||
Connection connection = Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build(); | ||
|
||
ClientV2 client = ClientV2.from(connection); | ||
Hash hash = client.getFirstBlockEpoch(EpochQuery.RELATIVE_EPOCH(genesisIndex, Epoch.from(epoch))); | ||
System.out.println(hash); | ||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GetFirstBlockEpoch()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
concordium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetWinningBakersEpoch.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,56 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.grpc.v2.WinningBaker; | ||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.requests.EpochQuery; | ||
import com.concordium.sdk.responses.Epoch; | ||
import picocli.CommandLine; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Creates a {@link ClientV2} from the specified connection ("http://localhost:20002" if not specified). | ||
* Retrieves and prints the {@link WinningBaker}s for the first finalized block for specified Epoch at the specified genesis index (Epoch 2 at genesis index 5 if not specified). | ||
*/ | ||
@CommandLine.Command(name = "GetWinningBakersEpoch", mixinStandardHelpOptions = true) | ||
public class GetWinningBakersEpoch implements Callable<Integer> { | ||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20002") | ||
private String endpoint; | ||
|
||
@CommandLine.Option( | ||
names = {"--genesisIndex"}, | ||
description = "Genesis index to query at", | ||
defaultValue = "5") | ||
private int genesisIndex; | ||
|
||
@CommandLine.Option( | ||
names = {"--epoch"}, | ||
description = "Epoch index to query", | ||
defaultValue = "5") | ||
private int epoch; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
URL endpointUrl = new URL(this.endpoint); | ||
Connection connection = Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build(); | ||
|
||
ClientV2 client = ClientV2.from(connection); | ||
client.getWinningBakersEpoch(EpochQuery.RELATIVE_EPOCH(genesisIndex, Epoch.from(epoch))) | ||
.forEach(System.out::println); | ||
|
||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GetWinningBakersEpoch()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
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
Oops, something went wrong.