Skip to content

Commit

Permalink
BitcoinClient: add getBlockChainInfoAsync() use it in getNetworkFromS…
Browse files Browse the repository at this point in the history
…erver()

The method of using a Map is not longer required because the circular dependency 
involving RpcClientModule has been fixed.
  • Loading branch information
msgilligan committed Sep 26, 2023
1 parent 3f4234d commit 55ff363
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ synchronized int getServerVersion() {
* @return A future for the server-side {@code Network}
*/
private CompletableFuture<Network> getNetworkFromServer() {
return getBlockchainInfoMap().thenApply(map -> {
return getBlockChainInfoAsync().thenApply(info -> {
Network network;
switch((String) map.get("chain")) {
switch(info.getChain()) {
case "main":
network = BitcoinNetwork.MAINNET;
break;
Expand All @@ -269,17 +269,6 @@ private CompletableFuture<Network> getNetworkFromServer() {
});
}

// TODO: I believe the circular dependency in RpcClientModule has been fixed, so this can be removed
/**
* Return {@code BlockchainInfo} as a {@link Map}. This avoids use of {@link RpcClientModule} and a circular dependency on {@link Network}
* @return {@code getblockchaininfo} response JSON as a {@link Map}
*/
private CompletableFuture<Map<String, Object>> getBlockchainInfoMap() {
JsonRpcRequest request = buildJsonRequest("getblockchaininfo");
CompletableFuture<JsonRpcResponse<Map<String, Object>>> response = sendRequestForResponseAsync(request, responseTypeFor(Map.class));
return response.thenApply(JsonRpcResponse::getResult);
}

/**
* Test if address index is enabled, caching the result of the first successful check
*
Expand Down Expand Up @@ -1017,7 +1006,11 @@ public List<BitcoinTransactionInfo> listTransactions(String label, Integer count
* @throws IOException network error
*/
public BlockChainInfo getBlockChainInfo() throws JsonRpcStatusException, IOException {
return send("getblockchaininfo", BlockChainInfo.class);
return syncGet(getBlockChainInfoAsync());
}

public CompletableFuture<BlockChainInfo> getBlockChainInfoAsync() {
return sendAsync("getblockchaininfo", BlockChainInfo.class);
}

/**
Expand Down

0 comments on commit 55ff363

Please sign in to comment.