|
50 | 50 | import java.util.logging.Level; |
51 | 51 | import java.util.logging.Logger; |
52 | 52 | import java.util.stream.Collectors; |
| 53 | +import java.util.Collections; |
53 | 54 |
|
54 | 55 | import javax.net.ssl.HostnameVerifier; |
55 | 56 | import javax.net.ssl.HttpsURLConnection; |
@@ -77,7 +78,6 @@ public class BitcoinJSONRPCClient implements BitcoindRpcClient { |
77 | 78 |
|
78 | 79 | public static final Charset QUERY_CHARSET = Charset.forName("ISO8859-1"); |
79 | 80 | public static final int CONNECT_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(1); |
80 | | - public static final int READ_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(5); |
81 | 81 |
|
82 | 82 | static { |
83 | 83 | String user = "user"; |
@@ -206,6 +206,8 @@ else if ((configFile = new File(home, "AppData" + File.separatorChar + |
206 | 206 | private URL noAuthURL; |
207 | 207 | private String authStr; |
208 | 208 |
|
| 209 | + public int readTimeout = (int) TimeUnit.MINUTES.toMillis(5); |
| 210 | + |
209 | 211 | public BitcoinJSONRPCClient(String rpcUrl) throws MalformedURLException { |
210 | 212 | this(new URL(rpcUrl)); |
211 | 213 | } |
@@ -349,7 +351,7 @@ private HttpURLConnection setConnection() { |
349 | 351 | conn.setDoInput(true); |
350 | 352 |
|
351 | 353 | conn.setConnectTimeout(CONNECT_TIMEOUT); |
352 | | - conn.setReadTimeout(READ_TIMEOUT); |
| 354 | + conn.setReadTimeout(readTimeout); |
353 | 355 |
|
354 | 356 | if (conn instanceof HttpsURLConnection) { |
355 | 357 | if (hostnameVerifier != null) |
@@ -654,6 +656,25 @@ public void importPrivKey(String bitcoinPrivKey, String label, boolean rescan) t |
654 | 656 | query("importprivkey", bitcoinPrivKey, label, rescan); |
655 | 657 | } |
656 | 658 |
|
| 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 | + |
657 | 678 | @Override |
658 | 679 | public Object importAddress(String address, String label, boolean rescan) throws GenericRpcException { |
659 | 680 | query("importaddress", address, label, rescan); |
@@ -2373,7 +2394,12 @@ public String type() { |
2373 | 2394 | @Override |
2374 | 2395 | @SuppressWarnings("unchecked") |
2375 | 2396 | 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; |
2377 | 2403 | } |
2378 | 2404 |
|
2379 | 2405 | } |
|
0 commit comments