-
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.
Add example for GetBlockTransactionEvents (#254)
* Add example for GetBlockTransactionEvents.
- Loading branch information
1 parent
443fddb
commit 09c4a16
Showing
3 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...ium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetBlockTransactionEvents.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,51 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.exceptions.ClientInitializationException; | ||
import com.concordium.sdk.requests.BlockQuery; | ||
import com.concordium.sdk.responses.blockitemsummary.Summary; | ||
import picocli.CommandLine; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Iterator; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Gets the block transaction events by {@link com.concordium.sdk.examples.GetBlockTransactionEvents} and prints it to the console. | ||
*/ | ||
@CommandLine.Command(name = "GetBlockTransactionEvents", mixinStandardHelpOptions = true) | ||
public class GetBlockTransactionEvents implements Callable<Integer> { | ||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20000") | ||
private String endpoint; | ||
|
||
|
||
@Override | ||
public Integer call() throws ClientInitializationException, MalformedURLException { | ||
URL endpointUrl = new URL(this.endpoint); | ||
Connection connection = Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build(); | ||
|
||
Iterator<Summary> blockTransactionEvents = ClientV2 | ||
.from(connection) | ||
.getBlockTransactionEvents(BlockQuery.LAST_FINAL); | ||
|
||
while(blockTransactionEvents.hasNext()) { | ||
Summary event = blockTransactionEvents.next(); | ||
System.out.println(event); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new com.concordium.sdk.examples.GetBlockTransactionEvents()).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