mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36:45 +00:00
cormorant: avoid importing wallets when testing connection, only show prune warning once per connection
This commit is contained in:
parent
d84f3bf887
commit
41ba8455a0
4 changed files with 14 additions and 3 deletions
|
@ -361,7 +361,7 @@ public class Bwt {
|
|||
Bwt.this.start(notifier);
|
||||
} else {
|
||||
if(AppServices.get().getOpenWallets().keySet().stream().anyMatch(wallet -> wallet.getScriptType() == ScriptType.P2TR)) {
|
||||
throw new IllegalStateException("Taproot wallets are not yet supported when connecting to Bitcoin Core");
|
||||
throw new IllegalStateException("Upgrade Bitcoin Core to v24 or later for Taproot wallet support");
|
||||
}
|
||||
|
||||
Bwt.this.start(AppServices.get().getOpenWallets().keySet(), notifier);
|
||||
|
|
|
@ -1106,7 +1106,7 @@ public class ElectrumServer {
|
|||
throw new CormorantBitcoindException("Legacy wallet configured");
|
||||
}
|
||||
if(ElectrumServer.cormorant == null) {
|
||||
ElectrumServer.cormorant = new Cormorant();
|
||||
ElectrumServer.cormorant = new Cormorant(subscribe);
|
||||
ElectrumServer.coreElectrumServer = cormorant.start();
|
||||
}
|
||||
} catch(CormorantBitcoindException e) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.sparrowwallet.sparrow.net.cormorant.electrum.ElectrumServerRunnable;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
public class Cormorant {
|
||||
|
@ -26,15 +27,20 @@ public class Cormorant {
|
|||
private BitcoindClient bitcoindClient;
|
||||
private ElectrumServerRunnable electrumServer;
|
||||
|
||||
private final boolean useWallets;
|
||||
private boolean running;
|
||||
|
||||
public Cormorant(boolean useWallets) {
|
||||
this.useWallets = useWallets;
|
||||
}
|
||||
|
||||
public Server start() throws CormorantBitcoindException {
|
||||
bitcoindClient = new BitcoindClient();
|
||||
bitcoindClient.initialize();
|
||||
|
||||
Thread importThread = new Thread(() -> {
|
||||
try {
|
||||
bitcoindClient.importWallets(AppServices.get().getOpenWallets().keySet());
|
||||
bitcoindClient.importWallets(useWallets ? AppServices.get().getOpenWallets().keySet() : Collections.emptySet());
|
||||
} catch(ImportFailedException e) {
|
||||
log.debug("Failed to import wallets", e);
|
||||
} finally {
|
||||
|
|
|
@ -74,6 +74,8 @@ public class BitcoindClient {
|
|||
private final Condition initialImportCondition = initialImportLock.newCondition();
|
||||
private boolean initialImportStarted;
|
||||
|
||||
private final List<String> pruneWarnedDescriptors = new ArrayList<>();
|
||||
|
||||
public BitcoindClient() {
|
||||
BitcoindTransport bitcoindTransport;
|
||||
|
||||
|
@ -149,9 +151,11 @@ public class BitcoindClient {
|
|||
} catch(ScanDateBeforePruneException e) {
|
||||
List<Wallet> prePruneWallets = wallets.stream()
|
||||
.filter(wallet -> wallet.getBirthDate() != null && wallet.getBirthDate().before(e.getPrunedDate()) && wallet.isValid()
|
||||
&& !pruneWarnedDescriptors.contains(e.getDescriptor())
|
||||
&& OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE).toString(false, true).equals(e.getDescriptor()))
|
||||
.sorted(Comparator.comparingLong(o -> o.getBirthDate().getTime())).collect(Collectors.toList());
|
||||
if(!prePruneWallets.isEmpty()) {
|
||||
pruneWarnedDescriptors.add(e.getDescriptor());
|
||||
Platform.runLater(() -> EventManager.get().post(new CormorantPruneStatusEvent("Error: Wallet birthday earlier than Bitcoin Core prune date", prePruneWallets.get(0), e.getRescanSince(), e.getPrunedDate(), legacyWalletExists)));
|
||||
}
|
||||
throw new ImportFailedException("Wallet birthday earlier than prune date");
|
||||
|
@ -358,6 +362,7 @@ public class BitcoindClient {
|
|||
|
||||
public void stop() {
|
||||
timer.cancel();
|
||||
pruneWarnedDescriptors.clear();
|
||||
stopped = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue