cormorant: handle checking imports and stopping before started

This commit is contained in:
Craig Raw 2023-11-20 10:56:06 +02:00
parent 74c3370277
commit ef3e2ed695

View file

@ -62,6 +62,11 @@ public class Cormorant {
} }
public boolean checkWalletImport(Wallet wallet) { public boolean checkWalletImport(Wallet wallet) {
if(bitcoindClient == null) {
log.warn("Attempting to check if " + wallet.getMasterName() + " is imported, but Cormorant is not started");
return false;
}
//Will block until all wallet descriptors have been added //Will block until all wallet descriptors have been added
try { try {
bitcoindClient.importWallet(wallet); bitcoindClient.importWallet(wallet);
@ -73,6 +78,11 @@ public class Cormorant {
} }
public void checkAddressImport(Address address, Date since) throws ServerException { public void checkAddressImport(Address address, Date since) throws ServerException {
if(bitcoindClient == null) {
log.warn("Attempting to check if an address is imported, but Cormorant is not started");
throw new ServerException("Server is not connected");
}
//Will block until address descriptor has been added //Will block until address descriptor has been added
try { try {
bitcoindClient.importAddress(address, since); bitcoindClient.importAddress(address, since);
@ -86,7 +96,9 @@ public class Cormorant {
} }
public void stop() { public void stop() {
bitcoindClient.stop(); if(bitcoindClient != null) {
bitcoindClient.stop();
}
if(electrumServer != null) { if(electrumServer != null) {
electrumServer.stop(); electrumServer.stop();
} }