From 3073388403f18247a3479b2a4518319a4096aae9 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Sat, 31 Jul 2021 18:10:24 +0100 Subject: [PATCH] Fix for missing transactions in getWalletTransactions() response 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. --- .../java/org/qortal/crosschain/Bitcoiny.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/qortal/crosschain/Bitcoiny.java b/src/main/java/org/qortal/crosschain/Bitcoiny.java index 5aed404c..d4693818 100644 --- a/src/main/java/org/qortal/crosschain/Bitcoiny.java +++ b/src/main/java/org/qortal/crosschain/Bitcoiny.java @@ -351,6 +351,10 @@ public abstract class Bitcoiny implements ForeignBlockchain { Set walletTransactions = new HashSet<>(); Set 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; @@ -374,9 +378,19 @@ public abstract class Bitcoiny implements ForeignBlockchain { } } - 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));