org.bitcoinj.core.VersionMessage Java Examples

The following examples show how to use org.bitcoinj.core.VersionMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalletAppSetup.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
          @Nullable Consumer<String> spvFileCorruptedHandler,
          @Nullable Runnable showFirstPopupIfResyncSPVRequestedHandler,
          @Nullable Runnable showPopupIfInvalidBtcConfigHandler,
          Runnable walletPasswordHandler,
          Runnable downloadCompleteHandler,
          Runnable walletInitializedHandler) {
    log.info("Initialize WalletAppSetup with BitcoinJ version {} and hash of BitcoinJ commit {}",
            VersionMessage.BITCOINJ_VERSION, "cd30ad5b");

    ObjectProperty<Throwable> walletServiceException = new SimpleObjectProperty<>();
    btcInfoBinding = EasyBind.combine(walletsSetup.downloadPercentageProperty(),
            walletsSetup.numPeersProperty(),
            walletServiceException,
            (downloadPercentage, numPeers, exception) -> {
                String result;
                if (exception == null) {
                    double percentage = (double) downloadPercentage;
                    int peers = (int) numPeers;
                    btcSyncProgress.set(percentage);
                    if (percentage == 1) {
                        result = Res.get("mainView.footer.btcInfo",
                                peers,
                                Res.get("mainView.footer.btcInfo.synchronizedWith"),
                                getBtcNetworkAsString());
                        getBtcSplashSyncIconId().set("image-connection-synced");

                        downloadCompleteHandler.run();
                    } else if (percentage > 0.0) {
                        result = Res.get("mainView.footer.btcInfo",
                                peers,
                                Res.get("mainView.footer.btcInfo.synchronizingWith"),
                                getBtcNetworkAsString() + ": " + FormattingUtils.formatToPercentWithSymbol(percentage));
                    } else {
                        result = Res.get("mainView.footer.btcInfo",
                                peers,
                                Res.get("mainView.footer.btcInfo.connectingTo"),
                                getBtcNetworkAsString());
                    }
                } else {
                    result = Res.get("mainView.footer.btcInfo",
                            getNumBtcPeers(),
                            Res.get("mainView.footer.btcInfo.connectionFailed"),
                            getBtcNetworkAsString());
                    log.error(exception.toString());
                    if (exception instanceof TimeoutException) {
                        getWalletServiceErrorMsg().set(Res.get("mainView.walletServiceErrorMsg.timeout"));
                    } else if (exception.getCause() instanceof BlockStoreException) {
                        if (exception.getCause().getCause() instanceof ChainFileLockedException && chainFileLockedExceptionHandler != null) {
                            chainFileLockedExceptionHandler.accept(Res.get("popup.warning.startupFailed.twoInstances"));
                        } else if (spvFileCorruptedHandler != null) {
                            spvFileCorruptedHandler.accept(Res.get("error.spvFileCorrupted", exception.getMessage()));
                        }
                    } else if (exception instanceof RejectedTxException) {
                        rejectedTxException.set((RejectedTxException) exception);
                        getWalletServiceErrorMsg().set(Res.get("mainView.walletServiceErrorMsg.rejectedTxException", exception.getMessage()));
                    } else {
                        getWalletServiceErrorMsg().set(Res.get("mainView.walletServiceErrorMsg.connectionError", exception.toString()));
                    }
                }
                return result;

            });
    btcInfoBinding.subscribe((observable, oldValue, newValue) -> getBtcInfo().set(newValue));

    walletsSetup.initialize(null,
            () -> {
                numBtcPeers = walletsSetup.numPeersProperty().get();

                // We only check one wallet as we apply encryption to all or none
                if (walletsManager.areWalletsEncrypted()) {
                    walletPasswordHandler.run();
                } else {
                    if (preferences.isResyncSpvRequested()) {
                        if (showFirstPopupIfResyncSPVRequestedHandler != null)
                            showFirstPopupIfResyncSPVRequestedHandler.run();
                    } else {
                        walletInitializedHandler.run();
                    }
                }
            },
            exception -> {
                if (exception instanceof InvalidHostException && showPopupIfInvalidBtcConfigHandler != null) {
                    showPopupIfInvalidBtcConfigHandler.run();
                } else {
                    walletServiceException.set(exception);
                }
            });
}