Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Start server at onInitWallet and add wallet password handler
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ManfredKarrer authored and Bernard Labno committed Sep 19, 2019
1 parent d076262 commit 31fb880
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
39 changes: 39 additions & 0 deletions api/src/main/java/bisq/api/http/app/HttpApiHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
*/
});
}
}
16 changes: 14 additions & 2 deletions api/src/main/java/bisq/api/http/app/HttpApiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
2 changes: 1 addition & 1 deletion 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;
private CorruptedDatabaseFilesHandler corruptedDatabaseFilesHandler;
private TradeManager tradeManager;

Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ default void onInitWallet() {
log.info("onInitWallet");
}

default void onRequestWalletPassword() {
log.info("onRequestWalletPassword");
}

void onSetupComplete();
}

Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
});
Expand Down

0 comments on commit 31fb880

Please sign in to comment.