Search in sources :

Example 1 with Whirlpool

use of com.sparrowwallet.sparrow.whirlpool.Whirlpool in project sparrow by sparrowwallet.

the class UtxosController method initializeView.

@Override
public void initializeView() {
    balance.valueProperty().addListener((observable, oldValue, newValue) -> {
        setFiatBalance(fiatBalance, AppServices.getFiatCurrencyExchangeRate(), newValue.longValue());
    });
    mempoolBalance.valueProperty().addListener((observable, oldValue, newValue) -> {
        setFiatBalance(fiatMempoolBalance, AppServices.getFiatCurrencyExchangeRate(), newValue.longValue());
    });
    WalletUtxosEntry walletUtxosEntry = getWalletForm().getWalletUtxosEntry();
    updateFields(walletUtxosEntry);
    utxosTable.initialize(walletUtxosEntry);
    utxosChart.initialize(walletUtxosEntry);
    mixButtonsBox.managedProperty().bind(mixButtonsBox.visibleProperty());
    mixButtonsBox.setVisible(getWalletForm().getWallet().isWhirlpoolMixWallet());
    startMix.managedProperty().bind(startMix.visibleProperty());
    startMix.setDisable(!AppServices.isConnected());
    stopMix.managedProperty().bind(stopMix.visibleProperty());
    startMix.visibleProperty().bind(stopMix.visibleProperty().not());
    stopMix.visibleProperty().addListener((observable, oldValue, newValue) -> {
        stopMix.setDisable(!newValue);
    });
    mixTo.managedProperty().bind(mixTo.visibleProperty());
    mixTo.setVisible(getWalletForm().getWallet().getStandardAccountType() == StandardAccount.WHIRLPOOL_POSTMIX);
    if (mixButtonsBox.isVisible()) {
        Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWalletForm().getWallet());
        if (whirlpool != null) {
            stopMix.visibleProperty().bind(whirlpool.mixingProperty());
            if (whirlpool.startingProperty().getValue()) {
                mixingStartingListener.changed(whirlpool.startingProperty(), null, whirlpool.startingProperty().getValue());
            }
            whirlpool.startingProperty().addListener(new WeakChangeListener<>(mixingStartingListener));
            if (whirlpool.stoppingProperty().getValue()) {
                mixingStoppingListener.changed(whirlpool.stoppingProperty(), null, whirlpool.stoppingProperty().getValue());
            }
            whirlpool.stoppingProperty().addListener(new WeakChangeListener<>(mixingStoppingListener));
            whirlpool.mixingProperty().addListener(new WeakChangeListener<>(mixingListener));
            updateMixToButton();
        }
    }
    sendSelected.setDisable(true);
    sendSelected.setTooltip(new Tooltip("Send selected UTXOs. Use " + (org.controlsfx.tools.Platform.getCurrent() == org.controlsfx.tools.Platform.OSX ? "Cmd" : "Ctrl") + "+click to select multiple."));
    mixSelected.managedProperty().bind(mixSelected.visibleProperty());
    mixSelected.setVisible(canWalletMix());
    mixSelected.setDisable(true);
    AppServices.onlineProperty().addListener(new WeakChangeListener<>(mixingOnlineListener));
    utxosTable.getSelectionModel().getSelectedIndices().addListener((ListChangeListener<Integer>) c -> {
        List<Entry> selectedEntries = utxosTable.getSelectionModel().getSelectedCells().stream().filter(tp -> tp.getTreeItem() != null).map(tp -> tp.getTreeItem().getValue()).collect(Collectors.toList());
        utxosChart.select(selectedEntries);
        updateButtons(Config.get().getBitcoinUnit());
    });
}
Also used : WeakChangeListener(javafx.beans.value.WeakChangeListener) Button(javafx.scene.control.Button) Address(com.sparrowwallet.drongo.address.Address) Initializable(javafx.fxml.Initializable) java.util(java.util) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) com.sparrowwallet.drongo.wallet(com.sparrowwallet.drongo.wallet) ButtonType(javafx.scene.control.ButtonType) TreeItem(javafx.scene.control.TreeItem) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) com.sparrowwallet.drongo.crypto(com.sparrowwallet.drongo.crypto) Config(com.sparrowwallet.sparrow.io.Config) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) WhirlpoolDialog(com.sparrowwallet.sparrow.whirlpool.WhirlpoolDialog) AppServices.showErrorDialog(com.sparrowwallet.sparrow.AppServices.showErrorDialog) ExchangeSource(com.sparrowwallet.sparrow.net.ExchangeSource) ListChangeListener(javafx.collections.ListChangeListener) Glyph(org.controlsfx.glyphfont.Glyph) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) Subscribe(com.google.common.eventbus.Subscribe) Tooltip(javafx.scene.control.Tooltip) Transaction(com.sparrowwallet.drongo.protocol.Transaction) Storage(com.sparrowwallet.sparrow.io.Storage) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) Tx0Preview(com.samourai.whirlpool.client.tx0.Tx0Preview) SecureString(com.sparrowwallet.drongo.SecureString) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) WhirlpoolServices(com.sparrowwallet.sparrow.whirlpool.WhirlpoolServices) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) BitcoinUnit(com.sparrowwallet.drongo.BitcoinUnit) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Stage(javafx.stage.Stage) CsvWriter(com.csvreader.CsvWriter) EventManager(com.sparrowwallet.sparrow.EventManager) ChangeListener(javafx.beans.value.ChangeListener) com.sparrowwallet.sparrow.control(com.sparrowwallet.sparrow.control) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) Tooltip(javafx.scene.control.Tooltip)

Example 2 with Whirlpool

use of com.sparrowwallet.sparrow.whirlpool.Whirlpool in project sparrow by sparrowwallet.

the class UtxosController method stopMixing.

public void stopMixing(ActionEvent event) {
    stopMix.setDisable(true);
    startMix.setDisable(!AppServices.onlineProperty().get());
    getWalletForm().getWallet().getMasterMixConfig().setMixOnStartup(Boolean.FALSE);
    EventManager.get().post(new WalletMasterMixConfigChangedEvent(getWalletForm().getWallet()));
    Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWalletForm().getWallet());
    if (whirlpool.isStarted()) {
        AppServices.getWhirlpoolServices().stopWhirlpool(whirlpool, true);
    } else {
        // Ensure http clients are shutdown
        whirlpool.shutdown();
    }
}
Also used : Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool)

Example 3 with Whirlpool

use of com.sparrowwallet.sparrow.whirlpool.Whirlpool in project sparrow by sparrowwallet.

the class SendController method broadcastPremix.

public void broadcastPremix(ActionEvent event) {
    // Ensure all child wallets have been saved
    Wallet masterWallet = getWalletForm().getWallet().isMasterWallet() ? getWalletForm().getWallet() : getWalletForm().getWallet().getMasterWallet();
    for (Wallet childWallet : masterWallet.getChildWallets()) {
        if (!childWallet.isNested()) {
            Storage storage = AppServices.get().getOpenWallets().get(childWallet);
            if (!storage.isPersisted(childWallet)) {
                try {
                    storage.saveWallet(childWallet);
                } catch (Exception e) {
                    AppServices.showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
                }
            }
        }
    }
    // The WhirlpoolWallet has already been configured for the tx0 preview
    Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWalletForm().getStorage().getWalletId(masterWallet));
    Map<BlockTransactionHashIndex, WalletNode> utxos = walletTransactionProperty.get().getSelectedUtxos();
    Whirlpool.Tx0BroadcastService tx0BroadcastService = new Whirlpool.Tx0BroadcastService(whirlpool, whirlpoolProperty.get(), utxos.keySet());
    tx0BroadcastService.setOnRunning(workerStateEvent -> {
        premixButton.setDisable(true);
        addWalletTransactionNodes();
    });
    tx0BroadcastService.setOnSucceeded(workerStateEvent -> {
        premixButton.setDisable(false);
        Sha256Hash txid = tx0BroadcastService.getValue();
        clear(null);
    });
    tx0BroadcastService.setOnFailed(workerStateEvent -> {
        premixButton.setDisable(false);
        Throwable exception = workerStateEvent.getSource().getException();
        while (exception.getCause() != null) {
            exception = exception.getCause();
        }
        AppServices.showErrorDialog("Error broadcasting premix transaction", exception.getMessage());
    });
    ServiceProgressDialog progressDialog = new ServiceProgressDialog("Whirlpool", "Broadcast Premix Transaction", "/image/whirlpool.png", tx0BroadcastService);
    AppServices.moveToActiveWindowScreen(progressDialog);
    tx0BroadcastService.start();
}
Also used : Storage(com.sparrowwallet.sparrow.io.Storage) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) Sha256Hash(com.sparrowwallet.drongo.protocol.Sha256Hash) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) IOException(java.io.IOException)

Example 4 with Whirlpool

use of com.sparrowwallet.sparrow.whirlpool.Whirlpool in project sparrow by sparrowwallet.

the class WalletUtxosEntry method updateMixProgress.

public void updateMixProgress() {
    Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWallet());
    if (whirlpool != null) {
        for (Entry entry : getChildren()) {
            UtxoEntry utxoEntry = (UtxoEntry) entry;
            MixProgress mixProgress = whirlpool.getMixProgress(utxoEntry.getHashIndex());
            if (mixProgress != null || utxoEntry.getMixStatus() == null || (utxoEntry.getMixStatus().getMixFailReason() == null && utxoEntry.getMixStatus().getNextMixUtxo() == null)) {
                utxoEntry.setMixProgress(mixProgress);
            }
        }
    }
}
Also used : MixProgress(com.samourai.whirlpool.client.wallet.beans.MixProgress) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool)

Example 5 with Whirlpool

use of com.sparrowwallet.sparrow.whirlpool.Whirlpool in project sparrow by sparrowwallet.

the class UtxosController method startMixing.

public void startMixing(ActionEvent event) {
    startMix.setDisable(true);
    stopMix.setDisable(false);
    getWalletForm().getWallet().getMasterMixConfig().setMixOnStartup(Boolean.TRUE);
    EventManager.get().post(new WalletMasterMixConfigChangedEvent(getWalletForm().getWallet()));
    Whirlpool whirlpool = AppServices.getWhirlpoolServices().getWhirlpool(getWalletForm().getWallet());
    if (whirlpool != null && !whirlpool.isStarted() && AppServices.isConnected()) {
        AppServices.getWhirlpoolServices().startWhirlpool(getWalletForm().getWallet(), whirlpool, true);
    }
}
Also used : Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool)

Aggregations

Whirlpool (com.sparrowwallet.sparrow.whirlpool.Whirlpool)7 SecureString (com.sparrowwallet.drongo.SecureString)2 InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)2 Storage (com.sparrowwallet.sparrow.io.Storage)2 IOException (java.io.IOException)2 CsvWriter (com.csvreader.CsvWriter)1 Subscribe (com.google.common.eventbus.Subscribe)1 Tx0Preview (com.samourai.whirlpool.client.tx0.Tx0Preview)1 MixProgress (com.samourai.whirlpool.client.wallet.beans.MixProgress)1 BitcoinUnit (com.sparrowwallet.drongo.BitcoinUnit)1 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)1 Address (com.sparrowwallet.drongo.address.Address)1 com.sparrowwallet.drongo.crypto (com.sparrowwallet.drongo.crypto)1 Sha256Hash (com.sparrowwallet.drongo.protocol.Sha256Hash)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 com.sparrowwallet.drongo.wallet (com.sparrowwallet.drongo.wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 AppServices.showErrorDialog (com.sparrowwallet.sparrow.AppServices.showErrorDialog)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 com.sparrowwallet.sparrow.control (com.sparrowwallet.sparrow.control)1