Skip to content

Commit

Permalink
More updates for CLI client commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 6, 2024
1 parent e114188 commit b99d1fe
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 45 deletions.
12 changes: 1 addition & 11 deletions convex-cli/src/main/java/convex/cli/account/AAccountCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package convex.cli.account;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import convex.api.Convex;
import convex.cli.ACommand;
import convex.cli.CLIError;
import convex.cli.Main;
import convex.cli.mixins.RemotePeerMixin;
import picocli.CommandLine.Mixin;
Expand All @@ -20,13 +16,7 @@ public abstract class AAccountCommand extends ACommand {
protected RemotePeerMixin peerMixin;

protected Convex connect() {
try {
return peerMixin.connect();
} catch (IOException e) {
throw new CLIError("Unable to connect to Convex network",e);
} catch (TimeoutException e) {
throw new CLIError("Timout connecting to Convex network",e);
}
return peerMixin.connect();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void run() {
Convex convex = peerMixin.connect();
String queryCommand = "(balance "+address+")";
ACell message = Reader.read(queryCommand);
Result result = convex.querySync(message, timeout);
Result result = convex.querySync(message);
mainParent.printResult(result);
} catch (Exception e) {
throw new CLIError("Error executing query",e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void run() {
ACell message = Reader.read(queryCommand);
Result result;
try {
result = convex.querySync(message, timeout);
result = convex.querySync(message);
mainParent.printResult(result);
} catch (TimeoutException e) {
throw new CLIError("Timeout",e);
Expand Down
13 changes: 4 additions & 9 deletions convex-cli/src/main/java/convex/cli/client/AClientCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,16 @@ public abstract class AClientCommand extends ATopCommand {
description="Timeout in miliseconds.")
protected Long timeout;


/**
* Connect as a client to the convex network
* @return
*/
protected Convex clientConnect() {
try {
Convex convex= peerMixin.connect();
if (timeout!=null) {
convex.setTimeout(timeout);
}
return convex;
} catch (Exception ex) {
throw new CLIError("Unable to connect to Convex: "+ex.getMessage(),ex);
Convex convex= peerMixin.connect();
if (timeout!=null) {
convex.setTimeout(timeout);
}
return convex;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion convex-cli/src/main/java/convex/cli/client/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run() {
Convex convex = connectQuery();
for (int i=0; i<commands.length; i++) {
ACell message = Reader.read(commands[i]);
Result result = convex.querySync(message, timeout);
Result result = convex.querySync(message);
printResult(result);
if (result.isError()) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ public class RemotePeerMixin extends AMixin {
* @throws IOException
* @throws TimeoutException
*/
public convex.api.Convex connect() throws IOException,TimeoutException {
public convex.api.Convex connect() {
if (port==null) port=convex.core.Constants.DEFAULT_PEER_PORT;
if (hostname==null) hostname=convex.cli.Constants.HOSTNAME_PEER;
InetSocketAddress sa=new InetSocketAddress(hostname,port);
try {
InetSocketAddress sa=new InetSocketAddress(hostname,port);
Convex c;
c=Convex.connect(sa);

return c;
} catch (ConnectException ce) {
throw new CLIError("Cannot connect to: "+hostname+" on port "+port,ce);
throw new CLIError("Cannot connect to: "+sa,ce);
} catch (TimeoutException e) {
throw new CLIError("Timeout while attempting to connect to peer: "+hostname,e);
} catch (IOException e) {
throw new CLIError("IO Error: "+e.getMessage(),e);
}
}

Expand Down
16 changes: 1 addition & 15 deletions convex-peer/src/main/java/convex/api/Convex.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,20 +811,6 @@ public Result querySync(String query) throws TimeoutException, IOException {
return querySync(form, getAddress());
}

/**
* Executes a query synchronously and waits for the Result
*
* @param timeoutMillis Timeout to wait for query result. Will throw
* TimeoutException if not received in this time
* @param query Query to execute, as a Form or Op
* @return Result of query
* @throws TimeoutException If the synchronous request timed out
* @throws IOException In case of network error
*/
public Result querySync(ACell query, long timeoutMillis) throws IOException, TimeoutException {
return querySync(query, getAddress(), timeoutMillis);
}

/**
* Executes a query synchronously and waits for the Result
*
Expand All @@ -849,7 +835,7 @@ public Result querySync(ACell query, Address address) throws IOException, Timeou
* @throws TimeoutException If the synchronous request timed out
* @throws IOException In case of network error
*/
public Result querySync(ACell query, Address address, long timeoutMillis) throws TimeoutException, IOException {
protected Result querySync(ACell query, Address address, long timeoutMillis) throws TimeoutException, IOException {
Future<Result> cf = query(query, address);
Result result;
try {
Expand Down
4 changes: 0 additions & 4 deletions convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public ChainAPI(RESTServer restServer) {

private static final String ROUTE = "/api/v1/";


@Override
public void addRoutes(Javalin app) {
String prefix=ROUTE;
Expand Down Expand Up @@ -171,9 +170,6 @@ public void queryAccount(Context ctx) {
}

boolean isUser=!as.isActor();
// TODO: consider if isLibrary is useful?
// boolean isLibrary=as.getCallableFunctions().isEmpty();


HashMap<String,Object> hm=new HashMap<>();
hm.put("address",addr.longValue());
Expand Down

0 comments on commit b99d1fe

Please sign in to comment.