Skip to content

Commit 5b0920a

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 18535ee + 9ed8285 commit 5b0920a

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/main/java/wf/bitcoin/javabitcoindrpcclient/BitcoinJSONRPCClient.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.logging.Level;
5151
import java.util.logging.Logger;
5252
import java.util.stream.Collectors;
53+
import java.util.Collections;
5354

5455
import javax.net.ssl.HostnameVerifier;
5556
import javax.net.ssl.HttpsURLConnection;
@@ -77,7 +78,6 @@ public class BitcoinJSONRPCClient implements BitcoindRpcClient {
7778

7879
public static final Charset QUERY_CHARSET = Charset.forName("ISO8859-1");
7980
public static final int CONNECT_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(1);
80-
public static final int READ_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(5);
8181

8282
static {
8383
String user = "user";
@@ -206,6 +206,8 @@ else if ((configFile = new File(home, "AppData" + File.separatorChar +
206206
private URL noAuthURL;
207207
private String authStr;
208208

209+
public int readTimeout = (int) TimeUnit.MINUTES.toMillis(5);
210+
209211
public BitcoinJSONRPCClient(String rpcUrl) throws MalformedURLException {
210212
this(new URL(rpcUrl));
211213
}
@@ -349,7 +351,7 @@ private HttpURLConnection setConnection() {
349351
conn.setDoInput(true);
350352

351353
conn.setConnectTimeout(CONNECT_TIMEOUT);
352-
conn.setReadTimeout(READ_TIMEOUT);
354+
conn.setReadTimeout(readTimeout);
353355

354356
if (conn instanceof HttpsURLConnection) {
355357
if (hostnameVerifier != null)
@@ -654,6 +656,25 @@ public void importPrivKey(String bitcoinPrivKey, String label, boolean rescan) t
654656
query("importprivkey", bitcoinPrivKey, label, rescan);
655657
}
656658

659+
/**
660+
* Rescan the local blockchain for wallet related transactions. This method
661+
* without argument rescan all the blocks.
662+
* The read timeout is set to half a day. because this method take a while. It
663+
* depends on hardware and blockchain size. Original timeout is restore after
664+
* the query.
665+
*
666+
* @see <a href="https://bitcoincore.org/en/doc/0.20.0/rpc/wallet/rescanblockchain/">rescanblockchain</a>
667+
* */
668+
@Override
669+
public void rescanBlockchain() throws GenericRpcException {
670+
int savedReadTimeout = this.readTimeout;
671+
// Change the read timeout to restore it after
672+
this.readTimeout = (int) TimeUnit.MINUTES.toMillis(720);
673+
query("rescanblockchain");
674+
// Restore the previous timeout
675+
this.readTimeout = savedReadTimeout;
676+
}
677+
657678
@Override
658679
public Object importAddress(String address, String label, boolean rescan) throws GenericRpcException {
659680
query("importaddress", address, label, rescan);
@@ -2373,7 +2394,12 @@ public String type() {
23732394
@Override
23742395
@SuppressWarnings("unchecked")
23752396
public List<String> addresses() {
2376-
return (List<String>) m.get("addresses");
2397+
List<String> addresses = ((List<String>) m.get("addresses"));
2398+
if (addresses == null) {
2399+
final String address = mapStr("address");
2400+
return address == null? Collections.emptyList() : Collections.singletonList(address);
2401+
}
2402+
return addresses;
23772403
}
23782404

23792405
}

src/main/java/wf/bitcoin/javabitcoindrpcclient/BitcoindRpcClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,14 @@ public interface BitcoindRpcClient {
853853
*/
854854
void importPrivKey(String bitcoinPrivKey, String account, boolean rescan) throws GenericRpcException;
855855

856+
/**
857+
* Rescan the local blockchain for wallet related transactions. This method
858+
* without argument rescan all the blocks.
859+
*
860+
* @see <a href="https://bitcoincore.org/en/doc/0.20.0/rpc/wallet/rescanblockchain/">rescanblockchain</a>
861+
*/
862+
void rescanBlockchain() throws GenericRpcException;
863+
856864
/**
857865
* The importwallet RPC imports private keys from a file in wallet dump file format (see the dumpwallet RPC).
858866
* These keys will be added to the keys currently in the wallet.

0 commit comments

Comments
 (0)