diff --git a/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java b/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java index 3e9a23a3b..d9520e5b8 100644 --- a/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java +++ b/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java @@ -29,4 +29,43 @@ */ @Slf4j class HttpApiHeadlessApp extends BisqHeadlessApp implements UncaughtExceptionHandler { + + @Override + protected void setupHandlers() { + super.setupHandlers(); + + bisqSetup.setRequestWalletPasswordHandler(aesKeyHandler -> { + log.info("onRequestWalletPasswordHandler"); + + // TODO @bernard listen for users input of pw, create aseKey and call handler + // aesKeyHandler.accept(aseKey); + + // here is code from UI + /* String password = passwordTextField.getText(); + checkArgument(password.length() < 500, Res.get("password.tooLong")); + KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt(); + if (keyCrypterScrypt != null) { + busyAnimation.play(); + deriveStatusLabel.setText(Res.get("password.deriveKey")); + ScryptUtil.deriveKeyWithScrypt(keyCrypterScrypt, password, aesKey -> { + if (walletsManager.checkAESKey(aesKey)) { + if (aesKeyHandler != null) + aesKeyHandler.onAesKey(aesKey); + + hide(); + } else { + busyAnimation.stop(); + deriveStatusLabel.setText(""); + + UserThread.runAfter(() -> new Popup<>() + .warning(Res.get("password.wrongPw")) + .onClose(this::blurAgain).show(), Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS); + } + }); + } else { + log.error("wallet.getKeyCrypter() is null, that must not happen."); + } + */ + }); + } } diff --git a/api/src/main/java/bisq/api/http/app/HttpApiMain.java b/api/src/main/java/bisq/api/http/app/HttpApiMain.java index d8fea6f92..37198ff95 100644 --- a/api/src/main/java/bisq/api/http/app/HttpApiMain.java +++ b/api/src/main/java/bisq/api/http/app/HttpApiMain.java @@ -58,10 +58,22 @@ protected AppModule getModule() { } @Override - public void onSetupComplete() { - log.info("onSetupComplete"); + public void onInitWallet() { + log.info("onInitWallet: We start the http server now"); HttpApiServer httpApiServer = injector.getInstance(HttpApiServer.class); httpApiServer.startServer(); } + + @Override + public void onRequestWalletPassword() { + log.info("onRequestWalletPassword"); + + // TODO @bernard now we need to get users wallet pw + } + + @Override + public void onSetupComplete() { + log.info("onSetupComplete"); + } } diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java index 22c23decc..c77acd6d7 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java @@ -43,7 +43,7 @@ public class BisqHeadlessApp implements HeadlessApp { @Setter private GracefulShutDownHandler gracefulShutDownHandler; private boolean shutDownRequested; - private BisqSetup bisqSetup; + protected BisqSetup bisqSetup; private CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler; private TradeManager tradeManager; diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index a2bcbca7a..43d1a3545 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -119,6 +119,10 @@ default void onInitWallet() { log.info("onInitWallet"); } + default void onRequestWalletPassword() { + log.info("onRequestWalletPassword"); + } + void onSetupComplete(); } @@ -549,6 +553,8 @@ else if (displayTorNetworkSettingsHandler != null) private void initWallet() { bisqSetupListeners.forEach(BisqSetupListener::onInitWallet); Runnable walletPasswordHandler = () -> { + log.info("Wallet password required"); + bisqSetupListeners.forEach(BisqSetupListener::onRequestWalletPassword); if (p2pNetworkReady.get()) p2PNetworkSetup.setSplashP2PNetworkAnimationVisible(true); @@ -559,6 +565,9 @@ private void initWallet() { if (showFirstPopupIfResyncSPVRequestedHandler != null) showFirstPopupIfResyncSPVRequestedHandler.run(); } else { + // TODO no guarantee here that the wallet is really fully initialized + // We would need a new walletInitializedButNotEncrypted state to track + // Usually init is fast and we have our wallet initialized at that state though. walletInitialized.set(true); } });