Skip to content

Commit

Permalink
possibility for using TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusbechwind committed Mar 11, 2024
1 parent 9453fc1 commit 25f223a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.concordium.sdk.ClientV2;
import com.concordium.sdk.Connection;
import com.concordium.sdk.TLSConfig;
import com.concordium.sdk.exceptions.ClientInitializationException;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.responses.BlockIdentifier;
Expand All @@ -13,9 +14,9 @@
import com.concordium.sdk.responses.blocksummary.specialoutcomes.SpecialOutcome;
import com.concordium.sdk.types.AbsoluteBlockHeight;
import com.google.common.collect.ImmutableList;
import lombok.var;
import picocli.CommandLine;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -47,6 +48,12 @@ public class BlockStats implements Callable<Integer> {
defaultValue = "http://localhost:20002")
private String endpoint;

@CommandLine.Option(
names = {"--tls"},
description = "Path to the server certificate"
)
private Optional<String> tls;

@CommandLine.Option(
names = {"--timeout"},
description = "GRPC request timeout in milliseconds.",
Expand All @@ -68,12 +75,15 @@ public class BlockStats implements Callable<Integer> {
@Override
public Integer call() throws IOException, ClientInitializationException {
URL endpointUrl = new URL(this.endpoint);
Connection connection = Connection.newBuilder()
Connection.ConnectionBuilder connection = Connection.newBuilder()
.host(endpointUrl.getHost())
.port(endpointUrl.getPort())
.timeout(timeout)
.build();
ClientV2 client = ClientV2.from(connection);
.timeout(timeout);

if (tls.isPresent()) {
connection = connection.useTLS(TLSConfig.from(new File(tls.get())));
}
ClientV2 client = ClientV2.from(connection.build());

AbsoluteBlockHeight start;
if (fromString.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.concordium.sdk.ClientV2;
import com.concordium.sdk.Connection;
import com.concordium.sdk.TLSConfig;
import com.concordium.sdk.exceptions.ClientInitializationException;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.responses.FindAccountResponse;
Expand All @@ -13,6 +14,7 @@
import com.concordium.sdk.types.AccountAddress;
import picocli.CommandLine;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
Expand All @@ -32,6 +34,12 @@ public class FindAccount implements Callable<Integer> {
defaultValue = "http://localhost:20002")
private String endpoint;

@CommandLine.Option(
names = {"--tls"},
description = "Path to the server certificate"
)
private Optional<String> tls;

@CommandLine.Option(
names = {"--timeout"},
description = "GRPC request timeout in milliseconds.",
Expand All @@ -47,12 +55,15 @@ public class FindAccount implements Callable<Integer> {
@Override
public Integer call() throws MalformedURLException, ClientInitializationException {
URL endpointUrl = new URL(this.endpoint);
Connection connection = Connection.newBuilder()
Connection.ConnectionBuilder connection = Connection.newBuilder()
.host(endpointUrl.getHost())
.port(endpointUrl.getPort())
.timeout(timeout)
.build();
ClientV2 client = ClientV2.from(connection);
.timeout(timeout);

if (tls.isPresent()) {
connection = connection.useTLS(TLSConfig.from(new File(tls.get())));
}
ClientV2 client = ClientV2.from(connection.build());

Optional<FindAccountResponse> response = client.findAccountCreation(AccountAddress.from(account));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import com.concordium.sdk.ClientV2;
import com.concordium.sdk.Connection;
import com.concordium.sdk.TLSConfig;
import com.concordium.sdk.exceptions.ClientInitializationException;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.responses.BakerId;
import com.concordium.sdk.responses.DelegatorRewardPeriodInfo;
import com.concordium.sdk.responses.poolstatus.BakerPoolStatus;
import com.concordium.sdk.responses.poolstatus.CurrentPaydayStatus;
import com.concordium.sdk.transactions.Hash;
import lombok.val;
import lombok.var;
import picocli.CommandLine;

import java.io.File;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -36,6 +36,12 @@ public class ValidatorStats implements Callable<Integer> {
defaultValue = "http://localhost:20002")
private String endpoint;

@CommandLine.Option(
names = {"--tls"},
description = "Path to the server certificate"
)
private Optional<String> tls;

@CommandLine.Option(
names = {"--timeout"},
description = "GRPC request timeout in milliseconds.",
Expand All @@ -45,12 +51,15 @@ public class ValidatorStats implements Callable<Integer> {
@Override
public Integer call() throws MalformedURLException, ClientInitializationException {
URL endpointUrl = new URL(this.endpoint);
Connection connection = Connection.newBuilder()
Connection.ConnectionBuilder connection = Connection.newBuilder()
.host(endpointUrl.getHost())
.port(endpointUrl.getPort())
.timeout(timeout)
.build();
ClientV2 client = ClientV2.from(connection);
.timeout(timeout);

if (tls.isPresent()) {
connection = connection.useTLS(TLSConfig.from(new File(tls.get())));
}
ClientV2 client = ClientV2.from(connection.build());

// BigInteger to avoid overflow
BigInteger equity = BigInteger.ZERO;
Expand Down

0 comments on commit 25f223a

Please sign in to comment.