-
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.
- Loading branch information
1 parent
3350713
commit 1cb43e2
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
concordium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetBakersRewardPeriod.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,47 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.requests.BlockQuery; | ||
import com.concordium.sdk.responses.bakersrewardperiod.BakerRewardPeriodInfo; | ||
import lombok.val; | ||
import picocli.CommandLine; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Calls {@link ClientV2#getBakersRewardPeriod(BlockQuery)} | ||
* retrieving a list of {@link BakerRewardPeriodInfo} about the bakers in the reward period of the block. | ||
* Prints the result to the terminal. | ||
*/ | ||
@CommandLine.Command(name = "GetBakersRewardPeriod", mixinStandardHelpOptions = true) | ||
public class GetBakersRewardPeriod 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); | ||
|
||
|
||
val bakerInfo = client.getBakersRewardPeriod(BlockQuery.BEST); | ||
bakerInfo.forEach(System.out::println); | ||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GetBakersRewardPeriod()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |