Skip to content

Commit

Permalink
fix: separate reset and rescan functions in AuthenticationGroupExtens…
Browse files Browse the repository at this point in the history
…ion (#241)

* fix: use Comparator that can handle long when sorting transactions

* separate reset and rescan functions in AuthenticationGroupExtension

* tests: update AuthenticationGroupExtensionTest to use rescanWallet instead of reset

Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
HashEngineering authored Dec 23, 2023
1 parent ef7d3cc commit b2155fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -887,14 +888,18 @@ public boolean removeAuthenticationKeyUsageEventListener(AuthenticationKeyUsageE

public void reset() {
keyUsage.clear();
}

public void rescanWallet() {
if (wallet != null) {
Set<Transaction> transactionSet = wallet.getTransactions(false);
List<Transaction> transactionList = Lists.newArrayList(transactionSet);
transactionList.sort((transaction1, transaction2) -> (int) (transaction1.getUpdateTime().getTime() - transaction2.getUpdateTime().getTime()));
keyUsage.clear();
Set<Transaction> transactionSet = wallet.getTransactions(false);
List<Transaction> 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);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b2155fb

Please sign in to comment.