Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes needed for minimal api #3348

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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;
Expand Down Expand Up @@ -261,7 +261,7 @@ protected void onApplicationStarted() {

protected void startAppSetup() {
BisqSetup bisqSetup = injector.getInstance(BisqSetup.class);
bisqSetup.addBisqSetupCompleteListener(this);
bisqSetup.addBisqSetupListener(this);
bisqSetup.start();
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/app/BisqHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BisqHeadlessApp implements HeadlessApp {
@Setter
private GracefulShutDownHandler gracefulShutDownHandler;
private boolean shutDownRequested;
private BisqSetup bisqSetup;
protected BisqSetup bisqSetup;
ripcurlx marked this conversation as resolved.
Show resolved Hide resolved
private CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
private TradeManager tradeManager;

Expand All @@ -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);
Expand Down
29 changes: 24 additions & 5 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@
@Slf4j
@Singleton
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();
}

Expand Down Expand Up @@ -201,7 +213,7 @@ public interface BisqSetupCompleteListener {
private boolean allBasicServicesInitialized;
@SuppressWarnings("FieldCanBeLocal")
private MonadicBinding<Boolean> p2pNetworkAndWalletInitialized;
private List<BisqSetupCompleteListener> bisqSetupCompleteListeners = new ArrayList<>();
private List<BisqSetupListener> bisqSetupListeners = new ArrayList<>();

@Inject
public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
Expand Down Expand Up @@ -296,8 +308,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() {
Expand Down Expand Up @@ -328,7 +340,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
Expand Down Expand Up @@ -524,6 +536,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.
Expand All @@ -550,7 +563,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);

Expand All @@ -561,6 +577,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);
}
});
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/app/HeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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;
Expand Down Expand Up @@ -191,12 +191,12 @@ public MainViewModel(BisqSetup bisqSetup,
GUIUtil.setPreferences(preferences);

setupHandlers();
bisqSetup.addBisqSetupCompleteListener(this);
bisqSetup.addBisqSetupListener(this);
}


///////////////////////////////////////////////////////////////////////////////////////////
// BisqSetupCompleteListener
// BisqSetupListener
///////////////////////////////////////////////////////////////////////////////////////////

@Override
Expand Down