Fix BTC spend txn building to be less aggressive about caching/checking spent keys

This commit is contained in:
catbref
2020-08-05 10:03:08 +01:00
parent 6b83499216
commit 615381ca5a
2 changed files with 26 additions and 7 deletions

View File

@@ -277,12 +277,6 @@ public class BTC {
for (; ki < keys.size(); ++ki) {
ECKey key = keys.get(ki);
if (btc.spentKeys.contains(key)) {
wallet.getActiveKeyChain().markKeyAsUsed((DeterministicKey) key);
areAllKeysUnspent = false;
continue;
}
Address address = Address.fromKey(btc.params, key, ScriptType.P2PKH);
byte[] script = ScriptBuilder.createOutputScript(address).getProgram();
@@ -299,6 +293,13 @@ public class BTC {
*/
if (unspentOutputs.isEmpty()) {
// If this is a known key that has been spent before, then we can skip asking for transaction history
if (btc.spentKeys.contains(key)) {
wallet.getActiveKeyChain().markKeyAsUsed((DeterministicKey) key);
areAllKeysUnspent = false;
continue;
}
// Ask for transaction history - if it's empty then key has never been used
List<byte[]> historicTransactionHashes = btc.electrumX.getAddressTransactions(script);
if (historicTransactionHashes == null)