Skip to content

Commit

Permalink
Fix for missing transactions in getWalletTransactions() response
Browse files Browse the repository at this point in the history
The previous criteria was to stop searching for more leaf keys as soon as we found a batch of keys with no transactions, but it seems that there are occasions when subsequent batches do actually contain transactions. The solution/workaround is to require 5 consecutive empty batches before giving up. There may be ways to improve this further by copying approaches from other BIP32 implementations, but this is a quick fix that should solve the problem for now.
  • Loading branch information
archived-2 committed Jul 31, 2021
1 parent 67f856c commit 3073388
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/org/qortal/crosschain/Bitcoiny.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ public List<SimpleTransaction> getWalletTransactions(String key58) throws Foreig
Set<BitcoinyTransaction> walletTransactions = new HashSet<>();
Set<String> keySet = new HashSet<>();

// Set the number of consecutive empty batches required before giving up
final int numberOfAdditionalBatchesToSearch = 5;

int unusedCounter = 0;
int ki = 0;
do {
boolean areAllKeysUnused = true;
Expand All @@ -374,9 +378,19 @@ public List<SimpleTransaction> getWalletTransactions(String key58) throws Foreig
}
}

if (areAllKeysUnused)
// No transactions for this batch of keys so assume we're done searching.
break;
if (areAllKeysUnused) {
// No transactions
if (unusedCounter >= numberOfAdditionalBatchesToSearch) {
// ... and we've hit our search limit
break;
}
// We haven't hit our search limit yet so increment the counter and keep looking
unusedCounter++;
}
else {
// Some keys in this batch were used, so reset the counter
unusedCounter = 0;
}

// Generate some more keys
keys.addAll(generateMoreKeys(keyChain));
Expand Down

0 comments on commit 3073388

Please sign in to comment.