Search in sources :

Example 1 with WhirlpoolUtxoViewModel

use of com.samourai.wallet.whirlpool.models.WhirlpoolUtxoViewModel in project samourai-wallet-android by Samourai-Wallet.

the class WhirlpoolMain method filter.

private Observable<List<WhirlpoolUtxoViewModel>> filter(WhirlpoolWallet wallet, List<WhirlpoolUtxo> mixingUtxos) {
    return Observable.fromCallable(() -> {
        List<WhirlpoolUtxoViewModel> list = new ArrayList<>();
        List<WhirlpoolUtxo> utxoPremix = new ArrayList<>(wallet.getUtxosPremix());
        WhirlpoolUtxoViewModel section = WhirlpoolUtxoViewModel.section("Mixing");
        list.add(section);
        for (WhirlpoolUtxo mixUtxo : mixingUtxos) {
            WhirlpoolUtxoViewModel whirlpoolUtxoViewModel = WhirlpoolUtxoViewModel.copy(mixingUtxos.get(mixingUtxos.indexOf(mixUtxo)));
            list.add(whirlpoolUtxoViewModel);
        }
        if (list.size() == 1) {
            list.remove(section);
        }
        WhirlpoolUtxoViewModel queueSection = WhirlpoolUtxoViewModel.section("Unmixed");
        list.add(queueSection);
        for (WhirlpoolUtxo utxo : utxoPremix) {
            WhirlpoolUtxoViewModel whirlpoolUtxoViewModel = null;
            for (WhirlpoolUtxo mixUtxo : mixingUtxos) {
                if (mixUtxo.getUtxo().tx_hash.equals(utxo.getUtxo().tx_hash) && mixUtxo.getUtxo().tx_output_n == utxo.getUtxo().tx_output_n)
                    whirlpoolUtxoViewModel = WhirlpoolUtxoViewModel.copy(mixingUtxos.get(mixingUtxos.indexOf(utxo)));
            }
            if (whirlpoolUtxoViewModel == null) {
                whirlpoolUtxoViewModel = WhirlpoolUtxoViewModel.copy(utxo);
            }
            if (whirlpoolUtxoViewModel.getUtxoState().getStatus() == WhirlpoolUtxoStatus.MIX_QUEUE) {
                list.add(whirlpoolUtxoViewModel);
            }
        }
        if (list.get(list.size() - 1).isSection()) {
            list.remove(queueSection);
        }
        for (WhirlpoolUtxoViewModel utxo : list) {
            list.get(list.indexOf(utxo)).setId(list.indexOf(utxo));
        }
        listenPoolState(mixingUtxos);
        return list;
    });
}
Also used : WhirlpoolUtxoViewModel(com.samourai.wallet.whirlpool.models.WhirlpoolUtxoViewModel) ArrayList(java.util.ArrayList) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)

Aggregations

WhirlpoolUtxoViewModel (com.samourai.wallet.whirlpool.models.WhirlpoolUtxoViewModel)1 WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)1 ArrayList (java.util.ArrayList)1