Search in sources :

Example 1 with WalletsManager

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);
    }
}
Also used : TradeManager(bisq.core.trade.TradeManager) ShowWalletDataWindow(bisq.desktop.main.overlays.windows.ShowWalletDataWindow) User(bisq.core.user.User) WalletsManager(bisq.core.btc.wallet.WalletsManager) DisputeManager(bisq.core.arbitration.DisputeManager) ArrayList(java.util.ArrayList) VoteService(bisq.core.dao.vote.VoteService) P2PService(bisq.network.p2p.P2PService) Image(javafx.scene.image.Image) CachingViewLoader(bisq.desktop.common.view.CachingViewLoader) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Popup(bisq.desktop.main.overlays.popups.Popup) AddressEntryList(bisq.core.btc.AddressEntryList) Preferences(bisq.core.user.Preferences) InjectorViewFactory(bisq.desktop.common.view.guice.InjectorViewFactory) FailedTradesManager(bisq.core.trade.failed.FailedTradesManager) Navigation(bisq.desktop.Navigation) Scene(javafx.scene.Scene) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) OpenOfferManager(bisq.core.offer.OpenOfferManager) PersistedDataHost(bisq.common.proto.persistable.PersistedDataHost) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager)

Example 2 with WalletsManager

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;
}
Also used : WalletsManager(bisq.core.btc.wallet.WalletsManager) TokenRegistry(network.bisq.api.service.TokenRegistry) KeyParameter(org.spongycastle.crypto.params.KeyParameter) AuthResult(network.bisq.api.model.AuthResult) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt)

Example 3 with WalletsManager

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());
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) WalletsManager(bisq.core.btc.wallet.WalletsManager) SeedWords(network.bisq.api.model.SeedWords) KeyParameter(org.spongycastle.crypto.params.KeyParameter) LocalDate(java.time.LocalDate)

Example 4 with WalletsManager

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);
}
Also used : WalletsManager(bisq.core.btc.wallet.WalletsManager) Tuple2(bisq.common.util.Tuple2) KeyCrypterScrypt(org.bitcoinj.crypto.KeyCrypterScrypt)

Example 5 with WalletsManager

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;
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) CompletableFuture(java.util.concurrent.CompletableFuture) WalletsManager(bisq.core.btc.wallet.WalletsManager) File(java.io.File)

Aggregations

WalletsManager (bisq.core.btc.wallet.WalletsManager)5 KeyCrypterScrypt (org.bitcoinj.crypto.KeyCrypterScrypt)2 DeterministicSeed (org.bitcoinj.wallet.DeterministicSeed)2 KeyParameter (org.spongycastle.crypto.params.KeyParameter)2 PersistedDataHost (bisq.common.proto.persistable.PersistedDataHost)1 Tuple2 (bisq.common.util.Tuple2)1 DisputeManager (bisq.core.arbitration.DisputeManager)1 AddressEntryList (bisq.core.btc.AddressEntryList)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 ProposalCollectionsService (bisq.core.dao.proposal.ProposalCollectionsService)1 VoteService (bisq.core.dao.vote.VoteService)1 OpenOfferManager (bisq.core.offer.OpenOfferManager)1 TradeManager (bisq.core.trade.TradeManager)1 ClosedTradableManager (bisq.core.trade.closed.ClosedTradableManager)1 FailedTradesManager (bisq.core.trade.failed.FailedTradesManager)1 Preferences (bisq.core.user.Preferences)1 User (bisq.core.user.User)1 Navigation (bisq.desktop.Navigation)1 CachingViewLoader (bisq.desktop.common.view.CachingViewLoader)1 InjectorViewFactory (bisq.desktop.common.view.guice.InjectorViewFactory)1