use of bisq.core.btc.wallet.WalletsManager in project bisq-desktop by bisq-network.
the class BisqApp method start.
@SuppressWarnings("PointlessBooleanExpression")
@Override
public void start(Stage stage) throws IOException {
BisqApp.primaryStage = stage;
try {
// Guice
bisqAppModule = new BisqAppModule(bisqEnvironment, primaryStage);
injector = Guice.createInjector(bisqAppModule);
injector.getInstance(InjectorViewFactory.class).setInjector(injector);
// All classes which are persisting objects need to be added here
// Maintain order!
ArrayList<PersistedDataHost> persistedDataHosts = new ArrayList<>();
final Preferences preferences = injector.getInstance(Preferences.class);
persistedDataHosts.add(preferences);
persistedDataHosts.add(injector.getInstance(User.class));
persistedDataHosts.add(injector.getInstance(Navigation.class));
persistedDataHosts.add(injector.getInstance(AddressEntryList.class));
persistedDataHosts.add(injector.getInstance(OpenOfferManager.class));
persistedDataHosts.add(injector.getInstance(TradeManager.class));
persistedDataHosts.add(injector.getInstance(ClosedTradableManager.class));
persistedDataHosts.add(injector.getInstance(FailedTradesManager.class));
persistedDataHosts.add(injector.getInstance(DisputeManager.class));
persistedDataHosts.add(injector.getInstance(P2PService.class));
persistedDataHosts.add(injector.getInstance(ProposalCollectionsService.class));
persistedDataHosts.add(injector.getInstance(VoteService.class));
// we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
persistedDataHosts.forEach(e -> {
try {
log.debug("call readPersisted at " + e.getClass().getSimpleName());
e.readPersisted();
} catch (Throwable e1) {
log.error("readPersisted error", e1);
}
});
boolean useDevMode = injector.getInstance(Key.get(Boolean.class, Names.named(AppOptionKeys.USE_DEV_MODE)));
DevEnv.setDevMode(useDevMode);
Version.setBaseCryptoNetworkId(BisqEnvironment.getBaseCurrencyNetwork().ordinal());
Version.printVersion();
if (Utilities.isLinux())
System.setProperty("prism.lcdtext", "false");
Storage.setDatabaseCorruptionHandler((String fileName) -> {
corruptedDatabaseFiles.add(fileName);
if (mainView != null)
mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
});
// load the main view and create the main scene
CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
mainView = (MainView) viewLoader.load(MainView.class);
mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
scene = new Scene(mainView.getRoot(), INITIAL_SCENE_WIDTH, INITIAL_SCENE_HEIGHT);
scene.getStylesheets().setAll("/bisq/desktop/bisq.css", "/bisq/desktop/images.css", "/bisq/desktop/CandleStickChart.css");
// configure the system tray
SystemTray.create(primaryStage, shutDownHandler);
primaryStage.setOnCloseRequest(event -> {
event.consume();
stop();
});
scene.addEventHandler(KeyEvent.KEY_RELEASED, keyEvent -> {
Utilities.isAltOrCtrlPressed(KeyCode.W, keyEvent);
if (Utilities.isCtrlPressed(KeyCode.W, keyEvent) || Utilities.isCtrlPressed(KeyCode.Q, keyEvent)) {
stop();
} else {
if (Utilities.isAltOrCtrlPressed(KeyCode.E, keyEvent)) {
showEmptyWalletPopup(injector.getInstance(BtcWalletService.class));
} else if (Utilities.isAltOrCtrlPressed(KeyCode.M, keyEvent)) {
showSendAlertMessagePopup();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.F, keyEvent)) {
showFilterPopup();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.J, keyEvent)) {
WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
if (walletsManager.areWalletsAvailable())
new ShowWalletDataWindow(walletsManager).show();
else
new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.G, keyEvent)) {
if (injector.getInstance(BtcWalletService.class).isWalletReady())
injector.getInstance(ManualPayoutTxWindow.class).show();
else
new Popup<>().warning(Res.get("popup.warning.walletNotInitialized")).show();
} else if (DevEnv.isDevMode()) {
// dev ode only
if (Utilities.isAltOrCtrlPressed(KeyCode.B, keyEvent)) {
// BSQ empty wallet not public yet
showEmptyWalletPopup(injector.getInstance(BsqWalletService.class));
} else if (Utilities.isAltOrCtrlPressed(KeyCode.P, keyEvent)) {
showFPSWindow();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.Z, keyEvent)) {
showDebugWindow();
}
}
}
});
// configure the primary stage
primaryStage.setTitle(bisqEnvironment.getRequiredProperty(AppOptionKeys.APP_NAME_KEY));
primaryStage.setScene(scene);
primaryStage.setMinWidth(1020);
primaryStage.setMinHeight(620);
// on windows the title icon is also used as task bar icon in a larger size
// on Linux no title icon is supported but also a large task bar icon is derived from that title icon
String iconPath;
if (Utilities.isOSX())
iconPath = ImageUtil.isRetina() ? "/images/window_icon@2x.png" : "/images/window_icon.png";
else if (Utilities.isWindows())
iconPath = "/images/task_bar_icon_windows.png";
else
iconPath = "/images/task_bar_icon_linux.png";
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
// make the UI visible
primaryStage.show();
if (!Utilities.isCorrectOSArchitecture()) {
String osArchitecture = Utilities.getOSArchitecture();
// We don't force a shutdown as the osArchitecture might in strange cases return a wrong value.
// Needs at least more testing on different machines...
new Popup<>().warning(Res.get("popup.warning.wrongVersion", osArchitecture, Utilities.getJVMArchitecture(), osArchitecture)).show();
}
UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES);
} catch (Throwable throwable) {
log.error("Error during app init", throwable);
showErrorPopup(throwable, false);
}
}
use of bisq.core.btc.wallet.WalletsManager in project bisq-api by mrosseel.
the class BisqProxy method changePassword.
public AuthResult changePassword(String oldPassword, String newPassword) {
if (!btcWalletService.isWalletReady())
throw new WalletNotReadyException("Wallet not ready yet");
final WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
if (btcWalletService.isEncrypted()) {
final KeyParameter aesKey = null == oldPassword ? null : getAESKey(oldPassword);
if (!isWalletPasswordValid(aesKey))
throw new UnauthorizedException();
walletsManager.decryptWallets(aesKey);
}
if (null != newPassword && newPassword.length() > 0) {
final Tuple2<KeyParameter, KeyCrypterScrypt> aesKeyAndScrypt = getAESKeyAndScrypt(newPassword);
walletsManager.encryptWallets(aesKeyAndScrypt.second, aesKeyAndScrypt.first);
final TokenRegistry tokenRegistry = injector.getInstance(TokenRegistry.class);
tokenRegistry.clear();
return new AuthResult(tokenRegistry.generateToken());
}
return null;
}
use of bisq.core.btc.wallet.WalletsManager in project bisq-api by mrosseel.
the class BisqProxy method getSeedWords.
public SeedWords getSeedWords(String password) {
final DeterministicSeed keyChainSeed = btcWalletService.getKeyChainSeed();
final WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
final LocalDate walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
DeterministicSeed seed = keyChainSeed;
if (keyChainSeed.isEncrypted()) {
if (null == password)
throw new UnauthorizedException();
final KeyParameter aesKey = getAESKey(password);
if (!isWalletPasswordValid(aesKey))
throw new UnauthorizedException();
seed = walletsManager.getDecryptedSeed(aesKey, btcWalletService.getKeyChainSeed(), btcWalletService.getKeyCrypter());
}
return new SeedWords(seed.getMnemonicCode(), walletCreationDate.toString());
}
use of bisq.core.btc.wallet.WalletsManager in project bisq-api by mrosseel.
the class BisqProxy method getAESKeyAndScrypt.
private Tuple2<KeyParameter, KeyCrypterScrypt> getAESKeyAndScrypt(String password) {
final WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
final KeyCrypterScrypt keyCrypterScrypt = walletsManager.getKeyCrypterScrypt();
return new Tuple2<>(keyCrypterScrypt.deriveKey(password), keyCrypterScrypt);
}
use of bisq.core.btc.wallet.WalletsManager in project bisq-api by mrosseel.
the class BisqProxy method restoreWalletFromSeedWords.
public CompletableFuture<Void> restoreWalletFromSeedWords(List<String> mnemonicCode, String walletCreationDate, String password) {
if (btcWalletService.isEncrypted() && (null == password || !isWalletPasswordValid(password)))
throw new UnauthorizedException();
final CompletableFuture<Void> futureResult = new CompletableFuture<>();
final long date = walletCreationDate != null ? LocalDate.parse(walletCreationDate).atStartOfDay().toEpochSecond(ZoneOffset.UTC) : 0;
final DeterministicSeed seed = new DeterministicSeed(mnemonicCode, null, "", date);
// TODO this logic comes from GUIUtils
final File storageDir = injector.getInstance(Key.get(File.class, Names.named(Storage.STORAGE_DIR)));
final WalletsManager walletsManager = injector.getInstance(WalletsManager.class);
try {
FileUtil.renameFile(new File(storageDir, "AddressEntryList"), new File(storageDir, "AddressEntryList_wallet_restore_" + System.currentTimeMillis()));
} catch (Throwable t) {
return failFuture(futureResult, t);
}
walletsManager.restoreSeedWords(seed, () -> futureResult.complete(null), throwable -> failFuture(futureResult, throwable));
if (null != shutdown)
futureResult.thenRunAsync(shutdown::run);
return futureResult;
}
Aggregations