Skip to content

Commit

Permalink
BitcoinClient: Deprecate waitForServer(int)
Browse files Browse the repository at this point in the history
waitForServer(Duration) should be used instead
  • Loading branch information
msgilligan committed Sep 26, 2023
1 parent 63a319d commit 81c6f07
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;

import static org.consensusj.bitcoin.jsonrpc.RpcURI.RPCPORT_REGTEST;
import static org.consensusj.bitcoin.jsonrpc.RpcURI.RPCPORT_TESTNET;
Expand Down Expand Up @@ -81,7 +82,7 @@ public BitcoinClient rpcClient(SSLContext sslContext) {
//System.out.println("Connecting to: " + getRPCConfig().getURI() + " with -rpcWait");
boolean available = false; // Wait up to 1 hour
try {
available = client.waitForServer(60*60);
available = client.waitForServer(Duration.ofMinutes(60));
} catch (JsonRpcException e) {
rpcTool.printError(this, "JSON-RPC Exception: " + e.getMessage());
throw new ToolException(1, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ public synchronized NetworkParameters getNetParams() {
* the mode of the server. However, to simplify client configuration we have added a constructor
* that doesn't require specification of a network. This changes some assumptions about how {@code BitcoinClient} works.
* Previously, no JSON-RPC I/O calls would be performed unless something was explicitly requested -- which
* also gave users of {@code BitcoinClient} the ability to call {@link #waitForServer(int)}
* also gave users of {@code BitcoinClient} the ability to call {@link #waitForServer(Duration)}
* before calling any RPCs.
* <p>
* Until further improvements/changes are made, if you use one of the constructors that does not specify a
* {@code Network} you should call {@link #getNetwork()} as soon as possible after calling the constructor
* (especially before calling any JSON-RPC I/O methods except {@link #waitForServer(int)}).
* (especially before calling any JSON-RPC I/O methods except {@link #waitForServer(Duration)}).
* @return network for the server
*/
public synchronized Network getNetwork() {
Expand Down Expand Up @@ -350,7 +350,6 @@ private Address getTestAddress() {
}
}

// TODO: This method should be deprecated in favor of the version that takes a Duration
/**
* Wait until the server is available.
* <p>
Expand All @@ -361,7 +360,9 @@ private Address getTestAddress() {
* @param timeoutSeconds Timeout in seconds
* @return true if ready, false if timeout or interrupted
* @throws JsonRpcException if an "unexpected" exception happens (i.e. an error other than what happens during normal server startup)
* @deprecated Use {@link #waitForServer(Duration)}
*/
@Deprecated
public boolean waitForServer(int timeoutSeconds) throws JsonRpcException {
return waitForServer(Duration.ofSeconds(timeoutSeconds));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.bitcoinj.base.Network;
import org.consensusj.jsonrpc.JsonRpcException;

import java.time.Duration;

/**
* Test support functions intended to be mixed-in to Spock test specs
*/
Expand All @@ -13,7 +15,7 @@ public interface BTCTestSupport extends BitcoinClientAccessor {
* @param expectedNetwork The network the server is expected to be running on
*/
default void serverReady(Network expectedNetwork) throws JsonRpcException {
Boolean ready = client().waitForServer(60); // Wait up to 1 minute
Boolean ready = client().waitForServer(Duration.ofSeconds(60)); // Wait up to 1 minute
if (!ready) {
throw new RuntimeException("Timeout waiting for server");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -35,7 +36,7 @@ private synchronized void getNotifications() {
if (notifications == null) {
try {
// TODO: We don't want to hang here for 120 seconds or so waiting for a server
client.waitForServer(1);
client.waitForServer(Duration.ofSeconds(1));
notifications = client.getZmqNotifications();
} catch (IOException e) {
// TODO: Handle this more gracefully, without runtime exception
Expand Down

0 comments on commit 81c6f07

Please sign in to comment.