Search in sources :

Example 1 with MixConfig

use of com.sparrowwallet.drongo.wallet.MixConfig in project sparrow by sparrowwallet.

the class MixConfigMapper method map.

@Override
public MixConfig map(ResultSet rs, StatementContext ctx) throws SQLException {
    String scode = rs.getString("scode");
    Boolean mixOnStartup = rs.getBoolean("mixOnStartup");
    if (rs.wasNull()) {
        mixOnStartup = null;
    }
    String indexRange = rs.getString("indexRange");
    String mixToWalletFile = rs.getString("mixToWalletFile");
    String mixToWalletName = rs.getString("mixToWalletName");
    Integer minMixes = rs.getInt("minMixes");
    if (rs.wasNull()) {
        minMixes = null;
    }
    MixConfig mixConfig = new MixConfig(scode, mixOnStartup, indexRange, mixToWalletFile == null ? null : new File(mixToWalletFile), mixToWalletName, minMixes, rs.getInt("receiveIndex"), rs.getInt("changeIndex"));
    mixConfig.setId(rs.getLong("id"));
    return mixConfig;
}
Also used : File(java.io.File) MixConfig(com.sparrowwallet.drongo.wallet.MixConfig)

Example 2 with MixConfig

use of com.sparrowwallet.drongo.wallet.MixConfig in project sparrow by sparrowwallet.

the class MixToController method initializeView.

public void initializeView(Wallet wallet) {
    mixConfig = wallet.getMasterMixConfig().copy();
    List<Wallet> allWallets = new ArrayList<>();
    allWallets.add(NONE_WALLET);
    List<Wallet> destinationWallets = AppServices.get().getOpenWallets().keySet().stream().filter(openWallet -> openWallet.isValid() && (openWallet.getScriptType() == ScriptType.P2WPKH || openWallet.getScriptType() == ScriptType.P2WSH) && openWallet != wallet && openWallet != wallet.getMasterWallet() && (openWallet.getStandardAccountType() == null || !StandardAccount.WHIRLPOOL_ACCOUNTS.contains(openWallet.getStandardAccountType()))).collect(Collectors.toList());
    allWallets.addAll(destinationWallets);
    mixToWallets.setItems(FXCollections.observableList(allWallets));
    mixToWallets.setConverter(new StringConverter<>() {

        @Override
        public String toString(Wallet wallet) {
            return wallet == null ? "" : wallet.getFullDisplayName();
        }

        @Override
        public Wallet fromString(String string) {
            return null;
        }
    });
    String mixToWalletId = null;
    try {
        mixToWalletId = AppServices.getWhirlpoolServices().getWhirlpoolMixToWalletId(mixConfig);
    } catch (NoSuchElementException e) {
    // ignore, mix to wallet is not open
    }
    if (mixToWalletId != null) {
        mixToWallets.setValue(AppServices.get().getWallet(mixToWalletId));
    } else {
        mixToWallets.setValue(NONE_WALLET);
    }
    mixToWallets.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue == NONE_WALLET) {
            mixConfig.setMixToWalletName(null);
            mixConfig.setMixToWalletFile(null);
        } else {
            mixConfig.setMixToWalletName(newValue.getName());
            mixConfig.setMixToWalletFile(AppServices.get().getOpenWallets().get(newValue).getWalletFile());
        }
        EventManager.get().post(new MixToConfigChangedEvent(wallet));
    });
    int initialMinMixes = mixConfig.getMinMixes() == null ? Whirlpool.DEFAULT_MIXTO_MIN_MIXES : mixConfig.getMinMixes();
    minMixes.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 10000, initialMinMixes));
    minMixes.valueProperty().addListener((observable, oldValue, newValue) -> {
        mixConfig.setMinMixes(newValue);
        EventManager.get().post(new MixToConfigChangedEvent(wallet));
    });
    indexRange.setConverter(new StringConverter<>() {

        @Override
        public String toString(IndexRange indexRange) {
            if (indexRange == null) {
                return "";
            }
            return indexRange.toString().charAt(0) + indexRange.toString().substring(1).toLowerCase();
        }

        @Override
        public IndexRange fromString(String string) {
            return null;
        }
    });
    indexRange.setValue(IndexRange.FULL);
    if (mixConfig.getIndexRange() != null) {
        try {
            indexRange.setValue(IndexRange.valueOf(mixConfig.getIndexRange()));
        } catch (Exception e) {
        // ignore
        }
    }
    indexRange.valueProperty().addListener((observable, oldValue, newValue) -> {
        mixConfig.setIndexRange(newValue.toString());
        EventManager.get().post(new MixToConfigChangedEvent(wallet));
    });
}
Also used : Initializable(javafx.fxml.Initializable) Whirlpool(com.sparrowwallet.sparrow.whirlpool.Whirlpool) Wallet(com.sparrowwallet.drongo.wallet.Wallet) URL(java.net.URL) FXCollections(javafx.collections.FXCollections) Spinner(javafx.scene.control.Spinner) StringConverter(javafx.util.StringConverter) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) FXML(javafx.fxml.FXML) IndexRange(com.samourai.whirlpool.client.wallet.beans.IndexRange) List(java.util.List) AppServices(com.sparrowwallet.sparrow.AppServices) MixConfig(com.sparrowwallet.drongo.wallet.MixConfig) MixToConfigChangedEvent(com.sparrowwallet.sparrow.event.MixToConfigChangedEvent) ComboBox(javafx.scene.control.ComboBox) ResourceBundle(java.util.ResourceBundle) StandardAccount(com.sparrowwallet.drongo.wallet.StandardAccount) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) EventManager(com.sparrowwallet.sparrow.EventManager) NoSuchElementException(java.util.NoSuchElementException) ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) Wallet(com.sparrowwallet.drongo.wallet.Wallet) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) IndexRange(com.samourai.whirlpool.client.wallet.beans.IndexRange) MixToConfigChangedEvent(com.sparrowwallet.sparrow.event.MixToConfigChangedEvent) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

MixConfig (com.sparrowwallet.drongo.wallet.MixConfig)2 IndexRange (com.samourai.whirlpool.client.wallet.beans.IndexRange)1 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)1 StandardAccount (com.sparrowwallet.drongo.wallet.StandardAccount)1 Wallet (com.sparrowwallet.drongo.wallet.Wallet)1 AppServices (com.sparrowwallet.sparrow.AppServices)1 EventManager (com.sparrowwallet.sparrow.EventManager)1 MixToConfigChangedEvent (com.sparrowwallet.sparrow.event.MixToConfigChangedEvent)1 Whirlpool (com.sparrowwallet.sparrow.whirlpool.Whirlpool)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 ResourceBundle (java.util.ResourceBundle)1 Collectors (java.util.stream.Collectors)1 FXCollections (javafx.collections.FXCollections)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1 ComboBox (javafx.scene.control.ComboBox)1