diff --git a/core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java b/core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java index d63192b10..0628efd83 100644 --- a/core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java +++ b/core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java @@ -75,6 +75,7 @@ import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -887,14 +888,18 @@ public boolean removeAuthenticationKeyUsageEventListener(AuthenticationKeyUsageE public void reset() { keyUsage.clear(); + } + + public void rescanWallet() { if (wallet != null) { - Set transactionSet = wallet.getTransactions(false); - List transactionList = Lists.newArrayList(transactionSet); - transactionList.sort((transaction1, transaction2) -> (int) (transaction1.getUpdateTime().getTime() - transaction2.getUpdateTime().getTime())); + keyUsage.clear(); + Set transactionSet = wallet.getTransactions(false); + List transactionList = Lists.newArrayList(transactionSet); + transactionList.sort(Comparator.comparingLong(transaction -> transaction.getUpdateTime().getTime())); - for (Transaction tx : transactionList) { + for (Transaction tx : transactionList) { processTransaction(tx, null, AbstractBlockChain.NewBlockType.BEST_CHAIN); - } + } } } } diff --git a/core/src/test/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtensionTest.java b/core/src/test/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtensionTest.java index b037fa3e8..9228bfc64 100644 --- a/core/src/test/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtensionTest.java +++ b/core/src/test/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtensionTest.java @@ -228,9 +228,9 @@ public void loadWallet() throws IOException, UnreadableWalletException { // make sure this wallet has an authenticationGroupExtension assertTrue(wallet.getKeyChainExtensions().containsKey(AuthenticationGroupExtension.EXTENSION_ID)); - // check that reset() preserves the usage count + // check that rescanWallet() preserves the usage count int usageBefore = authenticationGroupExtension.getKeyUsage().size(); - authenticationGroupExtension.reset(); + authenticationGroupExtension.rescanWallet(); int usageAfter = authenticationGroupExtension.getKeyUsage().size(); assertEquals(usageBefore, usageAfter); }