From b6cc3518a95ef8a3787b9c657278c74b906f4325 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 16 Jan 2019 11:41:33 +0100 Subject: [PATCH 1/2] Add onInitP2pNetwork and onInitWallet to BisqSetupListener - Rename BisqSetupCompleteListener to BisqSetupListener - Add onInitP2pNetwork and onInitWallet to BisqSetupListener - make onInitP2pNetwork and onInitWallet default so no impl. required --- .../java/bisq/core/app/BisqExecutable.java | 4 ++-- .../java/bisq/core/app/BisqHeadlessApp.java | 2 +- .../main/java/bisq/core/app/BisqSetup.java | 20 ++++++++++++++----- .../main/java/bisq/core/app/HeadlessApp.java | 2 +- .../java/bisq/desktop/main/MainViewModel.java | 6 +++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index f5935a5406..337dc8a885 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -72,7 +72,7 @@ import static com.google.common.base.Preconditions.checkNotNull; 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; @@ -261,7 +261,7 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet 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 f7ece906fb..22c23deccf 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java @@ -54,7 +54,7 @@ public class BisqHeadlessApp implements HeadlessApp { 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 18763753fc..eb62d15cef 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -116,7 +116,15 @@ import javax.annotation.Nullable; @Slf4j @Singleton public class BisqSetup { - public interface BisqSetupCompleteListener { + public interface BisqSetupListener { + default void onInitP2pNetwork() { + log.info("onInitP2pNetwork"); + } + + default void onInitWallet() { + log.info("onInitWallet"); + } + void onSetupComplete(); } @@ -201,7 +209,7 @@ public class BisqSetup { private boolean allBasicServicesInitialized; @SuppressWarnings("FieldCanBeLocal") private MonadicBinding p2pNetworkAndWalletInitialized; - private List bisqSetupCompleteListeners = new ArrayList<>(); + private List bisqSetupListeners = new ArrayList<>(); @Inject public BisqSetup(P2PNetworkSetup p2PNetworkSetup, @@ -296,8 +304,8 @@ public class BisqSetup { // Setup /////////////////////////////////////////////////////////////////////////////////////////// - public void addBisqSetupCompleteListener(BisqSetupCompleteListener listener) { - bisqSetupCompleteListeners.add(listener); + public void addBisqSetupListener(BisqSetupListener listener) { + bisqSetupListeners.add(listener); } public void start() { @@ -328,7 +336,7 @@ public class BisqSetup { 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 @@ -524,6 +532,7 @@ public class BisqSetup { }, 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. @@ -550,6 +559,7 @@ public class BisqSetup { } private void initWallet() { + bisqSetupListeners.forEach(BisqSetupListener::onInitWallet); Runnable walletPasswordHandler = () -> { if (p2pNetworkReady.get()) p2PNetworkSetup.setSplashP2PNetworkAnimationVisible(true); diff --git a/core/src/main/java/bisq/core/app/HeadlessApp.java b/core/src/main/java/bisq/core/app/HeadlessApp.java index 8d105a9339..3808b89b1a 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 bisq.common.setup.UncaughtExceptionHandler; 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/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index b58042e59b..70726c52ac 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -95,7 +95,7 @@ import lombok.Getter; 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; @@ -191,12 +191,12 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupCompleteList GUIUtil.setPreferences(preferences); setupHandlers(); - bisqSetup.addBisqSetupCompleteListener(this); + bisqSetup.addBisqSetupListener(this); } /////////////////////////////////////////////////////////////////////////////////////////// - // BisqSetupCompleteListener + // BisqSetupListener /////////////////////////////////////////////////////////////////////////////////////////// @Override From fb9f59db9505d5bff173597cc0b1d64f90df6bdc Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 16 Jan 2019 12:09:11 +0100 Subject: [PATCH 2/2] Start server at onInitWallet and add wallet password handler - Add onInitWallet to HttpApiMain and start http server there - Add onRequestWalletPassword to BisqSetupListener - Override setupHandlers in HttpApiHeadlessApp and adjust setRequestWalletPasswordHandler (impl. missing) - Add onRequestWalletPassword to HttpApiMain --- core/src/main/java/bisq/core/app/BisqHeadlessApp.java | 2 +- core/src/main/java/bisq/core/app/BisqSetup.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java index 22c23deccf..c77acd6d7c 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 eb62d15cef..cd9a11ed63 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -125,6 +125,10 @@ public class BisqSetup { log.info("onInitWallet"); } + default void onRequestWalletPassword() { + log.info("onRequestWalletPassword"); + } + void onSetupComplete(); } @@ -561,6 +565,8 @@ public class BisqSetup { private void initWallet() { bisqSetupListeners.forEach(BisqSetupListener::onInitWallet); Runnable walletPasswordHandler = () -> { + log.info("Wallet password required"); + bisqSetupListeners.forEach(BisqSetupListener::onRequestWalletPassword); if (p2pNetworkReady.get()) p2PNetworkSetup.setSplashP2PNetworkAnimationVisible(true); @@ -571,6 +577,9 @@ public class BisqSetup { 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); } });