Skip to content

Commit

Permalink
Add example for GetBlockTransactionEvents (#254)
Browse files Browse the repository at this point in the history
* Add example for GetBlockTransactionEvents.
  • Loading branch information
MilkywayPirate authored Jul 31, 2023
1 parent 443fddb commit 09c4a16
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.concordium.sdk.ClientV2;
import com.concordium.sdk.Connection;
import com.concordium.sdk.Credentials;
import com.concordium.sdk.exceptions.ClientInitializationException;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.responses.modulelist.ModuleRef;
Expand Down Expand Up @@ -38,7 +37,6 @@ public Integer call() throws ClientInitializationException, MalformedURLExceptio
Connection connection = Connection.newBuilder()
.host(endpointUrl.getHost())
.port(endpointUrl.getPort())
.credentials(new Credentials())
.build();

WasmModule moduleSource = ClientV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.concordium.sdk.ClientV2;
import com.concordium.sdk.Connection;
import com.concordium.sdk.Credentials;
import com.concordium.sdk.exceptions.ClientInitializationException;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.types.ContractAddress;
Expand Down

0 comments on commit 09c4a16

Please sign in to comment.