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 877bc6be807..ed8b342f4b5 100644 --- a/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java +++ b/api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java @@ -2,6 +2,8 @@ import bisq.core.app.BisqHeadlessApp; +import bisq.common.Timer; +import bisq.common.UserThread; import bisq.common.setup.UncaughtExceptionHandler; import lombok.extern.slf4j.Slf4j; @@ -12,4 +14,52 @@ */ @Slf4j class HttpApiHeadlessApp extends BisqHeadlessApp implements UncaughtExceptionHandler { + + @Override + protected void setupHandlers() { + super.setupHandlers(); + + bisqSetup.setRequestWalletPasswordHandler(aesKeyHandler -> { + log.info("onRequestWalletPasswordHandler"); + + // Add a periodic log so that users get reminded to enter the pw + Timer reminder = UserThread.runPeriodically(() -> { + log.info("Awaiting user's wallet password to be entered via API call"); + }, 10); + + + // TODO @bernard listen for users input of pw, create aseKey and call handler + // aesKeyHandler.accept(aseKey); + // Once pw is entered we stop periodic log + // reminder.stop(); + + + // 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 d8fea6f9248..37198ff9594 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/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 9ccaf0b7ae6..1cdd2549f8f 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -75,7 +75,7 @@ import static java.lang.String.format; @Slf4j -public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupCompleteListener { +public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener { private final String fullName; private final String scriptName; @@ -271,7 +271,7 @@ protected void onApplicationStarted() { protected void startAppSetup() { BisqSetup bisqSetup = injector.getInstance(BisqSetup.class); - bisqSetup.addBisqSetupCompleteListener(this); + bisqSetup.addBisqSetupListener(this); bisqSetup.start(); } diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java index 3bb23f40f2b..7dca30fa24e 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; @@ -54,7 +54,7 @@ public BisqHeadlessApp() { public void startApplication() { try { bisqSetup = injector.getInstance(BisqSetup.class); - bisqSetup.addBisqSetupCompleteListener(this); + bisqSetup.addBisqSetupListener(this); corruptedDatabaseFilesHandler = injector.getInstance(CorruptedDatabaseFilesHandler.class); tradeManager = injector.getInstance(TradeManager.class); diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 295a3bbd838..bb96e3c26cc 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -110,7 +110,19 @@ @Slf4j public class BisqSetup { - public interface BisqSetupCompleteListener { + public interface BisqSetupListener { + default void onInitP2pNetwork() { + log.info("onInitP2pNetwork"); + } + + default void onInitWallet() { + log.info("onInitWallet"); + } + + default void onRequestWalletPassword() { + log.info("onRequestWalletPassword"); + } + void onSetupComplete(); } @@ -189,7 +201,7 @@ public interface BisqSetupCompleteListener { private boolean allBasicServicesInitialized; @SuppressWarnings("FieldCanBeLocal") private MonadicBinding p2pNetworkAndWalletInitialized; - private List bisqSetupCompleteListeners = new ArrayList<>(); + private List bisqSetupListeners = new ArrayList<>(); @Inject public BisqSetup(P2PNetworkSetup p2PNetworkSetup, @@ -272,8 +284,8 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup, // Setup /////////////////////////////////////////////////////////////////////////////////////////// - public void addBisqSetupCompleteListener(BisqSetupCompleteListener listener) { - bisqSetupCompleteListeners.add(listener); + public void addBisqSetupListener(BisqSetupListener listener) { + bisqSetupListeners.add(listener); } public void start() { @@ -298,7 +310,7 @@ private void step4() { private void step5() { initDomainServices(); - bisqSetupCompleteListeners.forEach(BisqSetupCompleteListener::onSetupComplete); + bisqSetupListeners.forEach(BisqSetupListener::onSetupComplete); // We set that after calling the setupCompleteHandler to not trigger a popup from the dev dummy accounts // in MainViewModel @@ -492,6 +504,7 @@ else if (displayTorNetworkSettingsHandler != null) }, STARTUP_TIMEOUT_MINUTES, TimeUnit.MINUTES); + bisqSetupListeners.forEach(BisqSetupListener::onInitP2pNetwork); p2pNetworkReady = p2PNetworkSetup.init(this::initWallet, displayTorNetworkSettingsHandler); // We only init wallet service here if not using Tor for bitcoinj. @@ -518,7 +531,10 @@ 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); @@ -529,6 +545,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); } }); diff --git a/core/src/main/java/bisq/core/app/HeadlessApp.java b/core/src/main/java/bisq/core/app/HeadlessApp.java index 8d105a93398..3808b89b1a0 100644 --- a/core/src/main/java/bisq/core/app/HeadlessApp.java +++ b/core/src/main/java/bisq/core/app/HeadlessApp.java @@ -22,7 +22,7 @@ import com.google.inject.Injector; -public interface HeadlessApp extends UncaughtExceptionHandler, BisqSetup.BisqSetupCompleteListener { +public interface HeadlessApp extends UncaughtExceptionHandler, BisqSetup.BisqSetupListener { void setGracefulShutDownHandler(GracefulShutDownHandler gracefulShutDownHandler); void setInjector(Injector injector); diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index a7f2d2292fd..10d4ee72cdf 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -61,7 +61,7 @@ public static void main(String[] args) throws Exception { @Override public void onSetupComplete() { - log.debug("onSetupComplete"); + log.info("onSetupComplete"); } diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 92a568c2b71..7178970db12 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -81,7 +81,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteListener { +public class MainViewModel implements ViewModel, BisqSetup.BisqSetupListener { private final BisqSetup bisqSetup; private final WalletsSetup walletsSetup; private final User user; @@ -171,12 +171,12 @@ public MainViewModel(BisqSetup bisqSetup, GUIUtil.setFeeService(feeService); setupHandlers(); - bisqSetup.addBisqSetupCompleteListener(this); + bisqSetup.addBisqSetupListener(this); } /////////////////////////////////////////////////////////////////////////////////////////// - // BisqSetupCompleteListener + // BisqSetupListener /////////////////////////////////////////////////////////////////////////////////////////// @Override