warm pubkey cache by deriving all public keys on wallet opening

This commit is contained in:
Craig Raw
2022-07-14 09:56:48 +02:00
parent 4217de15a3
commit fc52670b2d
2 changed files with 27 additions and 1 deletions
+1 -1
Submodule drongo updated: cd1e21ebaa...bd01cb8730
@@ -27,6 +27,7 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.ScheduledService;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.concurrent.Worker;
import javafx.fxml.FXMLLoader;
@@ -1062,6 +1063,13 @@ public class AppServices {
if(Config.get().getServerType() == ServerType.BITCOIN_CORE) {
Platform.runLater(() -> restartBwt(event.getWallet()));
}
//Ensure public key cache is warm
WalletKeyDerivationService walletKeyDerivationService = new WalletKeyDerivationService(event.getWallet());
walletKeyDerivationService.setOnFailed(workerStateEvent -> {
log.error("Error deriving public keys", workerStateEvent.getSource().getException());
});
walletKeyDerivationService.start();
}
@Subscribe
@@ -1101,4 +1109,22 @@ public class AppServices {
onlineProperty.set(true);
}
}
private static final class WalletKeyDerivationService extends Service<Boolean> {
private final Wallet wallet;
public WalletKeyDerivationService(Wallet wallet) {
this.wallet = wallet;
}
@Override
protected Task<Boolean> createTask() {
return new Task<>() {
protected Boolean call() {
wallet.derivePublicKeys();
return true;
}
};
}
}
}