mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +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);
|
Bwt.this.start(notifier);
|
||||||
} else {
|
} else {
|
||||||
if(AppServices.get().getOpenWallets().keySet().stream().anyMatch(wallet -> wallet.getScriptType() == ScriptType.P2TR)) {
|
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);
|
Bwt.this.start(AppServices.get().getOpenWallets().keySet(), notifier);
|
||||||
|
|
|
@ -1106,7 +1106,7 @@ public class ElectrumServer {
|
||||||
throw new CormorantBitcoindException("Legacy wallet configured");
|
throw new CormorantBitcoindException("Legacy wallet configured");
|
||||||
}
|
}
|
||||||
if(ElectrumServer.cormorant == null) {
|
if(ElectrumServer.cormorant == null) {
|
||||||
ElectrumServer.cormorant = new Cormorant();
|
ElectrumServer.cormorant = new Cormorant(subscribe);
|
||||||
ElectrumServer.coreElectrumServer = cormorant.start();
|
ElectrumServer.coreElectrumServer = cormorant.start();
|
||||||
}
|
}
|
||||||
} catch(CormorantBitcoindException e) {
|
} catch(CormorantBitcoindException e) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.sparrowwallet.sparrow.net.cormorant.electrum.ElectrumServerRunnable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Cormorant {
|
public class Cormorant {
|
||||||
|
@ -26,15 +27,20 @@ public class Cormorant {
|
||||||
private BitcoindClient bitcoindClient;
|
private BitcoindClient bitcoindClient;
|
||||||
private ElectrumServerRunnable electrumServer;
|
private ElectrumServerRunnable electrumServer;
|
||||||
|
|
||||||
|
private final boolean useWallets;
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
||||||
|
public Cormorant(boolean useWallets) {
|
||||||
|
this.useWallets = useWallets;
|
||||||
|
}
|
||||||
|
|
||||||
public Server start() throws CormorantBitcoindException {
|
public Server start() throws CormorantBitcoindException {
|
||||||
bitcoindClient = new BitcoindClient();
|
bitcoindClient = new BitcoindClient();
|
||||||
bitcoindClient.initialize();
|
bitcoindClient.initialize();
|
||||||
|
|
||||||
Thread importThread = new Thread(() -> {
|
Thread importThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
bitcoindClient.importWallets(AppServices.get().getOpenWallets().keySet());
|
bitcoindClient.importWallets(useWallets ? AppServices.get().getOpenWallets().keySet() : Collections.emptySet());
|
||||||
} catch(ImportFailedException e) {
|
} catch(ImportFailedException e) {
|
||||||
log.debug("Failed to import wallets", e);
|
log.debug("Failed to import wallets", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -74,6 +74,8 @@ public class BitcoindClient {
|
||||||
private final Condition initialImportCondition = initialImportLock.newCondition();
|
private final Condition initialImportCondition = initialImportLock.newCondition();
|
||||||
private boolean initialImportStarted;
|
private boolean initialImportStarted;
|
||||||
|
|
||||||
|
private final List<String> pruneWarnedDescriptors = new ArrayList<>();
|
||||||
|
|
||||||
public BitcoindClient() {
|
public BitcoindClient() {
|
||||||
BitcoindTransport bitcoindTransport;
|
BitcoindTransport bitcoindTransport;
|
||||||
|
|
||||||
|
@ -149,9 +151,11 @@ public class BitcoindClient {
|
||||||
} catch(ScanDateBeforePruneException e) {
|
} catch(ScanDateBeforePruneException e) {
|
||||||
List<Wallet> prePruneWallets = wallets.stream()
|
List<Wallet> prePruneWallets = wallets.stream()
|
||||||
.filter(wallet -> wallet.getBirthDate() != null && wallet.getBirthDate().before(e.getPrunedDate()) && wallet.isValid()
|
.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()))
|
&& OutputDescriptor.getOutputDescriptor(wallet, KeyPurpose.RECEIVE).toString(false, true).equals(e.getDescriptor()))
|
||||||
.sorted(Comparator.comparingLong(o -> o.getBirthDate().getTime())).collect(Collectors.toList());
|
.sorted(Comparator.comparingLong(o -> o.getBirthDate().getTime())).collect(Collectors.toList());
|
||||||
if(!prePruneWallets.isEmpty()) {
|
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)));
|
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");
|
throw new ImportFailedException("Wallet birthday earlier than prune date");
|
||||||
|
@ -358,6 +362,7 @@ public class BitcoindClient {
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
|
pruneWarnedDescriptors.clear();
|
||||||
stopped = true;
|
stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue