Skip to content
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

Add example for GetBlockTransactionEvents #254

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading