Search in sources :

Example 1 with MixingState

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

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

the class WhirlpoolNotificationService method listenService.

private void listenService() {
    try {
        Optional<WhirlpoolWallet> whirlpoolWalletOpt = androidWhirlpoolWalletService.getWhirlpoolWallet();
        if (!whirlpoolWalletOpt.isPresent()) {
            // whirlpool wallet not opened yet
            return;
        }
        // whirlpool wallet is opened
        WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
        updateNotification();
        Disposable stateDisposable = whirlpoolWallet.getMixingState().getObservable().observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(mixingState -> updateNotification());
        Disposable repeatedChecks = Observable.fromCallable(() -> true).repeatWhen(completed -> completed.delay(3, TimeUnit.SECONDS)).subscribe(aBoolean -> {
            updateNotification();
            notifySuccessMixes(whirlpoolWallet.getMixingState());
        }, er -> {
        });
        compositeDisposable.add(repeatedChecks);
        compositeDisposable.add(stateDisposable);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Coin(org.bitcoinj.core.Coin) Intent(android.content.Intent) FormatsUtil.getBTCDecimalFormat(com.samourai.wallet.util.FormatsUtil.getBTCDecimalFormat) PendingIntent(android.app.PendingIntent) Optional(java8.util.Optional) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) ArrayList(java.util.ArrayList) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) WHIRLPOOL_CHANNEL(com.samourai.wallet.SamouraiApplication.WHIRLPOOL_CHANNEL) Log(android.util.Log) WhirlpoolUtxoStatus(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoStatus) NotificationManager(android.app.NotificationManager) WhirlpoolUtxo(com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo) Service(android.app.Service) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService) R(com.samourai.wallet.R) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) GROUP_ALERT_SUMMARY(android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) NotificationCompat(android.support.v4.app.NotificationCompat) MixingState(com.samourai.whirlpool.client.wallet.beans.MixingState) WHIRLPOOL_NOTIFICATIONS(com.samourai.wallet.SamouraiApplication.WHIRLPOOL_NOTIFICATIONS) Notification(android.app.Notification) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet)

Example 3 with MixingState

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

MixingState (com.samourai.whirlpool.client.wallet.beans.MixingState)3 WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)3 NotificationCompat (android.support.v4.app.NotificationCompat)2 WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)2 ActivityManager (android.app.ActivityManager)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 GROUP_ALERT_SUMMARY (android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY)1 Log (android.util.Log)1 R (com.samourai.wallet.R)1 WHIRLPOOL_CHANNEL (com.samourai.wallet.SamouraiApplication.WHIRLPOOL_CHANNEL)1 WHIRLPOOL_NOTIFICATIONS (com.samourai.wallet.SamouraiApplication.WHIRLPOOL_NOTIFICATIONS)1 FormatsUtil.getBTCDecimalFormat (com.samourai.wallet.util.FormatsUtil.getBTCDecimalFormat)1 AndroidWhirlpoolWalletService (com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService)1 WhirlpoolUtxoStatus (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxoStatus)1