Skip to content

Commit b99d1fe

Browse files
committed
More updates for CLI client commands
1 parent e114188 commit b99d1fe

File tree

8 files changed

+14
-45
lines changed

8 files changed

+14
-45
lines changed

convex-cli/src/main/java/convex/cli/account/AAccountCommand.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package convex.cli.account;
22

3-
import java.io.IOException;
4-
import java.util.concurrent.TimeoutException;
5-
63
import convex.api.Convex;
74
import convex.cli.ACommand;
8-
import convex.cli.CLIError;
95
import convex.cli.Main;
106
import convex.cli.mixins.RemotePeerMixin;
117
import picocli.CommandLine.Mixin;
@@ -20,13 +16,7 @@ public abstract class AAccountCommand extends ACommand {
2016
protected RemotePeerMixin peerMixin;
2117

2218
protected Convex connect() {
23-
try {
24-
return peerMixin.connect();
25-
} catch (IOException e) {
26-
throw new CLIError("Unable to connect to Convex network",e);
27-
} catch (TimeoutException e) {
28-
throw new CLIError("Timout connecting to Convex network",e);
29-
}
19+
return peerMixin.connect();
3020
}
3121

3222
@Override

convex-cli/src/main/java/convex/cli/account/AccountBalance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void run() {
6060
Convex convex = peerMixin.connect();
6161
String queryCommand = "(balance "+address+")";
6262
ACell message = Reader.read(queryCommand);
63-
Result result = convex.querySync(message, timeout);
63+
Result result = convex.querySync(message);
6464
mainParent.printResult(result);
6565
} catch (Exception e) {
6666
throw new CLIError("Error executing query",e);

convex-cli/src/main/java/convex/cli/account/AccountInformation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void run() {
6464
ACell message = Reader.read(queryCommand);
6565
Result result;
6666
try {
67-
result = convex.querySync(message, timeout);
67+
result = convex.querySync(message);
6868
mainParent.printResult(result);
6969
} catch (TimeoutException e) {
7070
throw new CLIError("Timeout",e);

convex-cli/src/main/java/convex/cli/client/AClientCommand.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,16 @@ public abstract class AClientCommand extends ATopCommand {
3232
description="Timeout in miliseconds.")
3333
protected Long timeout;
3434

35-
3635
/**
3736
* Connect as a client to the convex network
3837
* @return
3938
*/
4039
protected Convex clientConnect() {
41-
try {
42-
Convex convex= peerMixin.connect();
43-
if (timeout!=null) {
44-
convex.setTimeout(timeout);
45-
}
46-
return convex;
47-
} catch (Exception ex) {
48-
throw new CLIError("Unable to connect to Convex: "+ex.getMessage(),ex);
40+
Convex convex= peerMixin.connect();
41+
if (timeout!=null) {
42+
convex.setTimeout(timeout);
4943
}
44+
return convex;
5045
}
5146

5247
/**

convex-cli/src/main/java/convex/cli/client/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void run() {
4040
Convex convex = connectQuery();
4141
for (int i=0; i<commands.length; i++) {
4242
ACell message = Reader.read(commands[i]);
43-
Result result = convex.querySync(message, timeout);
43+
Result result = convex.querySync(message);
4444
printResult(result);
4545
if (result.isError()) {
4646
break;

convex-cli/src/main/java/convex/cli/mixins/RemotePeerMixin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ public class RemotePeerMixin extends AMixin {
2929
* @throws IOException
3030
* @throws TimeoutException
3131
*/
32-
public convex.api.Convex connect() throws IOException,TimeoutException {
32+
public convex.api.Convex connect() {
3333
if (port==null) port=convex.core.Constants.DEFAULT_PEER_PORT;
3434
if (hostname==null) hostname=convex.cli.Constants.HOSTNAME_PEER;
35+
InetSocketAddress sa=new InetSocketAddress(hostname,port);
3536
try {
36-
InetSocketAddress sa=new InetSocketAddress(hostname,port);
3737
Convex c;
3838
c=Convex.connect(sa);
3939

4040
return c;
4141
} catch (ConnectException ce) {
42-
throw new CLIError("Cannot connect to: "+hostname+" on port "+port,ce);
42+
throw new CLIError("Cannot connect to: "+sa,ce);
4343
} catch (TimeoutException e) {
4444
throw new CLIError("Timeout while attempting to connect to peer: "+hostname,e);
45+
} catch (IOException e) {
46+
throw new CLIError("IO Error: "+e.getMessage(),e);
4547
}
4648
}
4749

convex-peer/src/main/java/convex/api/Convex.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -811,20 +811,6 @@ public Result querySync(String query) throws TimeoutException, IOException {
811811
return querySync(form, getAddress());
812812
}
813813

814-
/**
815-
* Executes a query synchronously and waits for the Result
816-
*
817-
* @param timeoutMillis Timeout to wait for query result. Will throw
818-
* TimeoutException if not received in this time
819-
* @param query Query to execute, as a Form or Op
820-
* @return Result of query
821-
* @throws TimeoutException If the synchronous request timed out
822-
* @throws IOException In case of network error
823-
*/
824-
public Result querySync(ACell query, long timeoutMillis) throws IOException, TimeoutException {
825-
return querySync(query, getAddress(), timeoutMillis);
826-
}
827-
828814
/**
829815
* Executes a query synchronously and waits for the Result
830816
*
@@ -849,7 +835,7 @@ public Result querySync(ACell query, Address address) throws IOException, Timeou
849835
* @throws TimeoutException If the synchronous request timed out
850836
* @throws IOException In case of network error
851837
*/
852-
public Result querySync(ACell query, Address address, long timeoutMillis) throws TimeoutException, IOException {
838+
protected Result querySync(ACell query, Address address, long timeoutMillis) throws TimeoutException, IOException {
853839
Future<Result> cf = query(query, address);
854840
Result result;
855841
try {

convex-restapi/src/main/java/convex/restapi/api/ChainAPI.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public ChainAPI(RESTServer restServer) {
5656

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

59-
6059
@Override
6160
public void addRoutes(Javalin app) {
6261
String prefix=ROUTE;
@@ -171,9 +170,6 @@ public void queryAccount(Context ctx) {
171170
}
172171

173172
boolean isUser=!as.isActor();
174-
// TODO: consider if isLibrary is useful?
175-
// boolean isLibrary=as.getCallableFunctions().isEmpty();
176-
177173

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

0 commit comments

Comments
 (0)