diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java index 05daca3a..6b89dfc1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/BitcoindClient.java @@ -61,7 +61,6 @@ public class BitcoindClient { private Exception lastPollException; private boolean pruned; - private boolean prunedWarningShown = false; private boolean legacyWalletExists; private final Lock syncingLock = new ReentrantLock(); @@ -148,7 +147,10 @@ public class BitcoindClient { try { importDescriptors(getWalletDescriptors(wallets)); } catch(ScanDateBeforePruneException e) { - List prePruneWallets = wallets.stream().filter(wallet -> wallet.getBirthDate() != null && wallet.getBirthDate().before(e.getPrunedDate()) && wallet.isValid()).sorted(Comparator.comparingLong(o -> o.getBirthDate().getTime())).collect(Collectors.toList()); + List prePruneWallets = wallets.stream() + .filter(wallet -> wallet.getBirthDate() != null && wallet.getBirthDate().before(e.getPrunedDate()) && wallet.isValid() + && OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE).toString(false, true).equals(e.getDescriptor())) + .sorted(Comparator.comparingLong(o -> o.getBirthDate().getTime())).collect(Collectors.toList()); if(!prePruneWallets.isEmpty()) { Platform.runLater(() -> EventManager.get().post(new CormorantPruneStatusEvent("Error: Wallet birthday earlier than Bitcoin Core prune date", prePruneWallets.get(0), e.getRescanSince(), e.getPrunedDate(), legacyWalletExists))); } @@ -175,19 +177,18 @@ public class BitcoindClient { private Map getWalletDescriptors(Collection wallets) throws ImportFailedException { List validWallets = wallets.stream().filter(Wallet::isValid).collect(Collectors.toList()); - Date earliestBirthDate = validWallets.stream().map(Wallet::getBirthDate).filter(Objects::nonNull).sorted().findFirst().orElse(null); Map outputDescriptors = new LinkedHashMap<>(); for(Wallet wallet : validWallets) { String receiveOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE).toString(false, false); - addOutputDescriptor(outputDescriptors, receiveOutputDescriptor, wallet, KeyPurpose.RECEIVE, earliestBirthDate); + addOutputDescriptor(outputDescriptors, receiveOutputDescriptor, wallet, KeyPurpose.RECEIVE, wallet.getBirthDate()); String changeOutputDescriptor = OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.CHANGE).toString(false, false); - addOutputDescriptor(outputDescriptors, changeOutputDescriptor, wallet, KeyPurpose.CHANGE, earliestBirthDate); + addOutputDescriptor(outputDescriptors, changeOutputDescriptor, wallet, KeyPurpose.CHANGE, wallet.getBirthDate()); if(wallet.isMasterWallet() && wallet.hasPaymentCode()) { Wallet notificationWallet = wallet.getNotificationWallet(); WalletNode notificationNode = notificationWallet.getNode(KeyPurpose.NOTIFICATION); String notificationOutputDescriptor = OutputDescriptor.toDescriptorString(notificationNode.getAddress()); - addOutputDescriptor(outputDescriptors, notificationOutputDescriptor, wallet, null, earliestBirthDate); + addOutputDescriptor(outputDescriptors, notificationOutputDescriptor, wallet, null, wallet.getBirthDate()); for(Wallet childWallet : wallet.getChildWallets()) { if(childWallet.isNested()) { @@ -199,7 +200,7 @@ public class BitcoindClient { purposeNode.fillToIndex(gapLimit - 1); for(WalletNode addressNode : purposeNode.getChildren()) { String addressOutputDescriptor = OutputDescriptor.toDescriptorString(addressNode.getAddress()); - addOutputDescriptor(outputDescriptors, addressOutputDescriptor, copyChildWallet, null, earliestBirthDate); + addOutputDescriptor(outputDescriptors, addressOutputDescriptor, copyChildWallet, null, wallet.getBirthDate()); } } } @@ -305,10 +306,10 @@ public class BitcoindClient { Optional optPrunedDate = getPrunedDate(); if(optPrunedDate.isPresent()) { Date prunedDate = optPrunedDate.get(); - Optional prePruneImport = importingDescriptors.values().stream().filter(scanDate -> scanDate.rescanSince != null && scanDate.rescanSince.before(prunedDate)).findFirst(); - if(prePruneImport.isPresent()) { - ScanDate scanDate = prePruneImport.get(); - throw new ScanDateBeforePruneException(scanDate.rescanSince, prunedDate); + Optional> optPrePruneImport = importingDescriptors.entrySet().stream().filter(entry -> entry.getValue().rescanSince != null && entry.getValue().rescanSince.before(prunedDate)).findFirst(); + if(optPrePruneImport.isPresent()) { + Map.Entry prePruneImport = optPrePruneImport.get(); + throw new ScanDateBeforePruneException(prePruneImport.getKey(), prePruneImport.getValue().rescanSince, prunedDate); } } } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/ScanDateBeforePruneException.java b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/ScanDateBeforePruneException.java index b9bfffac..c8d1494e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/ScanDateBeforePruneException.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/cormorant/bitcoind/ScanDateBeforePruneException.java @@ -3,14 +3,20 @@ package com.sparrowwallet.sparrow.net.cormorant.bitcoind; import java.util.Date; public class ScanDateBeforePruneException extends Exception { + private final String descriptor; private final Date rescanSince; private final Date prunedDate; - public ScanDateBeforePruneException(Date rescanSince, Date prunedDate) { + public ScanDateBeforePruneException(String descriptor, Date rescanSince, Date prunedDate) { + this.descriptor = descriptor; this.rescanSince = rescanSince; this.prunedDate = prunedDate; } + public String getDescriptor() { + return descriptor; + } + public Date getRescanSince() { return rescanSince; }