Search in sources :

Example 1 with WhirlpoolUtxo

use of com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo in project samourai-wallet-android by Samourai-Wallet.

the class WhirlpoolNotificationService method setMixState.

private void setMixState(NotificationCompat.Builder builder) {
    Optional<WhirlpoolWallet> whirlpoolWalletOpt = androidWhirlpoolWalletService.getWhirlpoolWallet();
    if (whirlpoolWalletOpt.isPresent()) {
        MixingState mixingState = whirlpoolWalletOpt.get().getMixingState();
        builder.setContentTitle("Whirlpool online: ".concat(String.valueOf(mixingState.getNbMixing())).concat(" MIXING :").concat(String.valueOf(mixingState.getNbQueued())).concat(" QUEUED"));
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        for (WhirlpoolUtxo whirlpoolUtxo : mixingState.getUtxosMixing()) {
            if (whirlpoolUtxo.getUtxoState().getMessage() != null && whirlpoolUtxo.getUtxoConfig().getPoolId() != null)
                inboxStyle.addLine(whirlpoolUtxo.getUtxoConfig().getPoolId().concat(" : ").concat(whirlpoolUtxo.getUtxoState().getMessage()));
        }
        builder.setStyle(inboxStyle);
    } else {
        builder.setContentText("Whirlpool");
    }
}
Also used : WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) NotificationCompat(android.support.v4.app.NotificationCompat) MixingState(com.samourai.whirlpool.client.wallet.beans.MixingState) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)

Example 2 with WhirlpoolUtxo

use of com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo in project samourai-wallet-android by Samourai-Wallet.

the class CycleDetail method setMixStatus.

private void setMixStatus() {
    Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
    if (!whirlpoolWalletOpt.isPresent()) {
        // wallet not opened
        return;
    }
    WhirlpoolWallet wallet = whirlpoolWalletOpt.get();
    try {
        for (WhirlpoolUtxo utxo : wallet.getUtxosPremix()) {
            if (utxo.getUtxo().toString().equals(hash)) {
                getSupportActionBar().setTitle(utxo.getUtxoConfig().getPoolId());
                whirlpoolUtxo = utxo;
                makeTxNetworkRequest();
                transactionId.setText(utxo.getUtxo().tx_hash);
                updateState(whirlpoolUtxo.getUtxoState());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)

Example 3 with WhirlpoolUtxo

use of com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo 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)

Example 4 with WhirlpoolUtxo

use of com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo in project samourai-wallet-android by Samourai-Wallet.

the class WhirlpoolMain method listenPoolState.

private void listenPoolState(List<WhirlpoolUtxo> list) {
    List<Observable<WhirlpoolUtxoState>> state = new ArrayList<>();
    for (WhirlpoolUtxo utxo : list) {
        state.add(utxo.getUtxoState().getObservable());
    }
    Disposable disposable = Observable.merge(state).subscribeOn(Schedulers.single()).observeOn(AndroidSchedulers.mainThread()).subscribe(whirlpoolUtxoState -> {
        loadMixes(true);
    });
    compositeDisposable.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ArrayList(java.util.ArrayList) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) Observable(io.reactivex.Observable)

Example 5 with WhirlpoolUtxo

use of com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo in project samourai-wallet-android by Samourai-Wallet.

the class WhirlpoolWalletTest method testStart.

@Test
public void testStart() throws Exception {
    // start whirlpool wallet
    whirlpoolWallet.start();
    // list pools
    Collection<Pool> pools = whirlpoolWallet.getPools();
    Assert.assertTrue(!pools.isEmpty());
    // find pool by poolId
    Pool pool = whirlpoolWallet.findPoolById("0.01btc");
    Assert.assertNotNull(pool);
    // list premix utxos
    Collection<WhirlpoolUtxo> utxosPremix = whirlpoolWallet.getUtxosPremix();
    log.info(utxosPremix.size() + " PREMIX utxos:");
    ClientUtils.logWhirlpoolUtxos(utxosPremix, whirlpoolWallet.getConfig().getMixsTarget());
    // list postmix utxos
    Collection<WhirlpoolUtxo> utxosPostmix = whirlpoolWallet.getUtxosPremix();
    log.info(utxosPostmix.size() + " POSTMIX utxos:");
    ClientUtils.logWhirlpoolUtxos(utxosPostmix, whirlpoolWallet.getConfig().getMixsTarget());
    // keep running
    for (int i = 0; i < 50; i++) {
        MixingState mixingState = whirlpoolWallet.getMixingState();
        log.debug("WHIRLPOOL: " + mixingState.getNbQueued() + " queued, " + mixingState.getNbMixing() + " mixing: " + mixingState.getUtxosMixing());
        synchronized (this) {
            wait(10000);
        }
    }
}
Also used : Pool(com.samourai.whirlpool.client.whirlpool.beans.Pool) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) MixingState(com.samourai.whirlpool.client.wallet.beans.MixingState) Test(org.junit.Test)

Aggregations

WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)5 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)2 MixingState (com.samourai.whirlpool.client.wallet.beans.MixingState)2 ArrayList (java.util.ArrayList)2 NotificationCompat (android.support.v4.app.NotificationCompat)1 WhirlpoolUtxoViewModel (com.samourai.wallet.whirlpool.models.WhirlpoolUtxoViewModel)1 Pool (com.samourai.whirlpool.client.whirlpool.beans.Pool)1 Observable (io.reactivex.Observable)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Test (org.junit.Test)1