Search in sources :

Example 6 with WhirlpoolWallet

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

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

the class NewPoolActivity method beginTx0.

private Completable beginTx0(List<UTXOCoin> coins) {
    return Completable.fromCallable(() -> {
        Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
        if (!whirlpoolWalletOpt.isPresent()) {
            return true;
        }
        WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
        Collection<UnspentOutputWithKey> spendFroms = new ArrayList<UnspentOutputWithKey>();
        for (UTXOCoin coin : coins) {
            UnspentResponse.UnspentOutput unspentOutput = new UnspentResponse.UnspentOutput();
            unspentOutput.addr = coin.address;
            unspentOutput.script = Hex.toHexString(coin.getOutPoint().getScriptBytes());
            unspentOutput.confirmations = coin.getOutPoint().getConfirmations();
            unspentOutput.tx_hash = coin.getOutPoint().getTxHash().toString();
            unspentOutput.tx_output_n = coin.getOutPoint().getTxOutputN();
            unspentOutput.value = coin.amount;
            unspentOutput.xpub = new UnspentResponse.UnspentOutput.Xpub();
            unspentOutput.xpub.path = "M/0/0";
            ECKey eckey = SendFactory.getPrivKey(coin.address, account);
            UnspentOutputWithKey spendFrom = new UnspentOutputWithKey(unspentOutput, eckey.getPrivKeyBytes());
            spendFroms.add(spendFrom);
        }
        if (selectedPoolPriority == PoolCyclePriority.HIGH) {
            tx0FeeTarget = Tx0FeeTarget.BLOCKS_2;
        } else if (selectedPoolPriority == PoolCyclePriority.NORMAL) {
            tx0FeeTarget = Tx0FeeTarget.BLOCKS_6;
        } else if (selectedPoolPriority == PoolCyclePriority.LOW) {
            tx0FeeTarget = Tx0FeeTarget.BLOCKS_24;
        }
        com.samourai.whirlpool.client.whirlpool.beans.Pool pool = whirlpoolWallet.findPoolById(selectedPoolViewModel.getPoolId());
        Tx0Config tx0Config;
        if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
            tx0Config = whirlpoolWallet.getTx0Config().setChangeWallet(WhirlpoolWalletAccount.POSTMIX);
        } else {
            tx0Config = whirlpoolWallet.getTx0Config().setChangeWallet(WhirlpoolWalletAccount.DEPOSIT);
        }
        Tx0 tx0 = null;
        try {
            tx0 = whirlpoolWallet.tx0(pool, spendFroms, tx0Config, tx0FeeTarget);
            final String txHash = tx0.getTx().getHashAsString();
            // tx0 success
            if (tx0.getChangeOutput() != null) {
                Log.i("NewPoolActivity", "change:" + tx0.getChangeOutput().toString());
                Log.i("NewPoolActivity", "change index:" + tx0.getChangeOutput().getIndex());
                UTXOUtil.getInstance().add(txHash + "-" + tx0.getChangeOutput().getIndex(), "\u2623 tx0 change\u2623");
                UTXOUtil.getInstance().addNote(txHash, "tx0");
                if (blockChangeOutput) {
                    if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
                        BlockedUTXO.getInstance().addPostMix(txHash, tx0.getChangeOutput().getIndex(), tx0.getChangeValue());
                    } else {
                        BlockedUTXO.getInstance().add(txHash, tx0.getChangeOutput().getIndex(), tx0.getChangeValue());
                    }
                }
            }
            NewPoolActivity.this.runOnUiThread(new Runnable() {

                public void run() {
                    Toast.makeText(NewPoolActivity.this, txHash, Toast.LENGTH_SHORT).show();
                }
            });
            Log.i("NewPoolActivity", "result:" + txHash);
        } catch (Exception e) {
            // tx0 failed
            NewPoolActivity.this.runOnUiThread(new Runnable() {

                public void run() {
                    Toast.makeText(NewPoolActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
            Log.i("NewPoolActivity", "result:" + e.getMessage());
        }
        return true;
    });
}
Also used : ArrayList(java.util.ArrayList) ECKey(org.bitcoinj.core.ECKey) SpannableString(android.text.SpannableString) UnspentOutputWithKey(com.samourai.whirlpool.client.tx0.UnspentOutputWithKey) Tx0(com.samourai.whirlpool.client.tx0.Tx0) WhirlpoolTx0(com.samourai.wallet.whirlpool.WhirlpoolTx0) UnspentResponse(com.samourai.wallet.api.backend.beans.UnspentResponse) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Tx0Config(com.samourai.whirlpool.client.tx0.Tx0Config)

Example 8 with WhirlpoolWallet

use of com.samourai.whirlpool.client.wallet.WhirlpoolWallet 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 9 with WhirlpoolWallet

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

the class WhirlpoolMain method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == NEWPOOL_REQ_CODE && resultCode == Activity.RESULT_OK) {
        Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
        if (!whirlpoolWalletOpt.isPresent()) {
            return;
        }
        WhirlpoolWallet whirlpoolWallet = whirlpoolWalletOpt.get();
        try {
            whirlpoolWallet.getUtxosPremix(true);
            whirlpoolWallet.getUtxosPostmix(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        new Handler().postDelayed(() -> {
            Intent intent = new Intent(this, JobRefreshService.class);
            intent.putExtra("notifTx", false);
            intent.putExtra("dragged", true);
            intent.putExtra("launch", false);
            JobRefreshService.enqueueWork(getApplicationContext(), intent);
        }, 800);
        progressBar.setVisibility(View.VISIBLE);
    }
    super.onActivityResult(requestCode, resultCode, data);
}
Also used : WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Handler(android.os.Handler) Intent(android.content.Intent)

Aggregations

WhirlpoolWallet (com.samourai.whirlpool.client.wallet.WhirlpoolWallet)9 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)4 Disposable (io.reactivex.disposables.Disposable)4 ArrayList (java.util.ArrayList)4 WhirlpoolUtxo (com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo)3 Intent (android.content.Intent)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 MixingState (com.samourai.whirlpool.client.wallet.beans.MixingState)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 Handler (android.os.Handler)1 IBinder (android.os.IBinder)1 GROUP_ALERT_SUMMARY (android.support.v4.app.NotificationCompat.GROUP_ALERT_SUMMARY)1 SpannableString (android.text.SpannableString)1 Log (android.util.Log)1 R (com.samourai.wallet.R)1