Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Comparator that can handle long when sorting transactions #241

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 void reset() {
keyUsage.clear();
}

Check warning on line 891 in core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/wallet/authentication/AuthenticationGroupExtension.java#L891

Added line #L891 was not covered by tests

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
Loading