From cef8b77e477d66908984492a7291f2d0d7a89d76 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 2 Sep 2024 16:18:44 +0200 Subject: [PATCH] Wallet: remove references to deprecated autosaveToFile() --- core/src/main/java/org/bitcoinj/wallet/Wallet.java | 8 ++++---- core/src/test/java/org/bitcoinj/wallet/WalletTest.java | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/wallet/Wallet.java b/core/src/main/java/org/bitcoinj/wallet/Wallet.java index de3a03009..39d3bf40e 100644 --- a/core/src/main/java/org/bitcoinj/wallet/Wallet.java +++ b/core/src/main/java/org/bitcoinj/wallet/Wallet.java @@ -178,7 +178,7 @@ import static org.bitcoinj.base.internal.Preconditions.checkState; * auto-save feature that simplifies this for you although you're still responsible for manually triggering a save when * your app is about to quit because the auto-save feature waits a moment before actually committing to disk to avoid IO * thrashing when the wallet is changing very fast (e.g. due to a block chain sync). See - * {@link Wallet#autosaveToFile(File, long, TimeUnit, WalletFiles.Listener)} + * {@link Wallet#autosaveToFile(File, Duration, WalletFiles.Listener)} * for more information about this.

*/ public class Wallet extends BaseTaggableObject @@ -1051,7 +1051,7 @@ public class Wallet extends BaseTaggableObject /** * Imports the given keys to the wallet. - * If {@link Wallet#autosaveToFile(File, long, TimeUnit, WalletFiles.Listener)} + * If {@link Wallet#autosaveToFile(File, Duration, WalletFiles.Listener)} * has been called, triggers an auto save bypassing the normal coalescing delay and event handlers. * Returns the number of keys added, after duplicates are ignored. The onKeyAdded event will be called for each key * in the list that was not already present. @@ -1834,7 +1834,7 @@ public class Wallet extends BaseTaggableObject * In this way disk IO can be rate limited. It's a good idea to set this as otherwise the wallet can change very * frequently, e.g. if there are a lot of transactions in it or during block sync, and there will be a lot of redundant * writes. Note that when a new key is added, that always results in an immediate save regardless of - * delayTime. You should still save the wallet manually using {@link Wallet#saveToFile(File)} when your program + * delay. You should still save the wallet manually using {@link Wallet#saveToFile(File)} when your program * is about to shut down as the JVM will not wait for the background thread.

* *

An event listener can be provided. It will be called on a background thread @@ -1868,7 +1868,7 @@ public class Wallet extends BaseTaggableObject /** *

* Disables auto-saving, after it had been enabled with - * {@link Wallet#autosaveToFile(File, long, TimeUnit, WalletFiles.Listener)} + * {@link Wallet#autosaveToFile(File, Duration, WalletFiles.Listener)} * before. This method blocks until finished. *

*/ diff --git a/core/src/test/java/org/bitcoinj/wallet/WalletTest.java b/core/src/test/java/org/bitcoinj/wallet/WalletTest.java index f16439287..9382988b3 100644 --- a/core/src/test/java/org/bitcoinj/wallet/WalletTest.java +++ b/core/src/test/java/org/bitcoinj/wallet/WalletTest.java @@ -101,7 +101,6 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -1708,7 +1707,7 @@ public class WalletTest extends TestWithWallet { File f = File.createTempFile("bitcoinj-unit-test", null); Sha256Hash hash1 = Sha256Hash.of(f); // Start with zero delay and ensure the wallet file changes after adding a key. - wallet.autosaveToFile(f, 0, TimeUnit.SECONDS, null); + wallet.autosaveToFile(f, Duration.ZERO, null); ECKey key = wallet.freshReceiveKey(); Sha256Hash hash2 = Sha256Hash.of(f); assertFalse("Wallet not saved after generating fresh key", hash1.equals(hash2)); // File has changed. @@ -1729,7 +1728,7 @@ public class WalletTest extends TestWithWallet { final CountDownLatch latch = new CountDownLatch(3); File f = File.createTempFile("bitcoinj-unit-test", null); Sha256Hash hash1 = Sha256Hash.of(f); - wallet.autosaveToFile(f, 1, TimeUnit.SECONDS, + wallet.autosaveToFile(f, Duration.ofSeconds(1), new WalletFiles.Listener() { @Override public void onBeforeAutoSave(File tempFile) {