Search in sources :

Example 11 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class ChooseUTXOsFragment method selectOrDeselect.

private void selectOrDeselect(int position) {
    utxos.get(position).isSelected = !utxos.get(position).isSelected;
    utxoRecyclerView.post(() -> utxoAdapter.notifyItemChanged(position));
    List<UTXOCoin> selectedList = new ArrayList<>();
    for (UTXOCoin model : utxos) {
        if (model.isSelected) {
            selectedList.add(model);
        }
    }
    if (onUTXOSelectionListener != null)
        onUTXOSelectionListener.onSelect(selectedList);
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList)

Example 12 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class NewPoolActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_whirlpool_cycle);
    Toolbar toolbar = findViewById(R.id.toolbar_new_whirlpool);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    cycleTotalAmount = findViewById(R.id.cycle_total_amount);
    cycleTotalAmount.setText(MonetaryUtil.getInstance().getBTCFormat().format(((double) getCycleTotalAmount(new ArrayList<UTXOCoin>())) / 1e8) + " BTC");
    fees.add(FeeUtil.getInstance().getLowFee().getDefaultPerKB().longValue() / 1000L);
    fees.add(FeeUtil.getInstance().getNormalFee().getDefaultPerKB().longValue() / 1000L);
    fees.add(FeeUtil.getInstance().getHighFee().getDefaultPerKB().longValue() / 1000L);
    String preselectId = null;
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("preselected")) {
        preselectId = getIntent().getExtras().getString("preselected");
    }
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        account = getIntent().getExtras().getInt("_account");
    }
    chooseUTXOsFragment = ChooseUTXOsFragment.newInstance(preselectId);
    selectPoolFragment = new SelectPoolFragment();
    reviewPoolFragment = new ReviewPoolFragment();
    selectPoolFragment.setFees(this.fees);
    tx0Progress = findViewById(R.id.new_pool_tx0_progress);
    newPoolViewPager = findViewById(R.id.new_pool_viewpager);
    setUpStepper();
    newPoolViewPager.setAdapter(new NewPoolStepsPager(getSupportFragmentManager()));
    newPoolViewPager.enableSwipe(false);
    confirmButton = findViewById(R.id.utxo_selection_confirm_btn);
    confirmButton.setVisibility(View.VISIBLE);
    enableConfirmButton(false);
    // Disable selection from fragment since post mix utxo's are populated by the activity
    if (account != WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix())
        chooseUTXOsFragment.setOnUTXOSelectionListener(this::onUTXOSelected);
    selectPoolFragment.setOnPoolSelectionComplete((poolViewModel, priority) -> {
        selectedPoolViewModel = poolViewModel;
        selectedPoolPriority = priority;
        if (tx0 != null && poolViewModel != null) {
            tx0.setPool(poolViewModel.getDenomination());
        }
        enableConfirmButton(selectedPoolViewModel != null);
    });
    confirmButton.setOnClickListener(view -> {
        switch(newPoolViewPager.getCurrentItem()) {
            case 0:
                {
                    newPoolViewPager.setCurrentItem(1);
                    initUTXOReviewButton(selectedCoins);
                    enableConfirmButton(selectedPoolViewModel != null);
                    break;
                }
            case 1:
                {
                    try {
                        tx0.make();
                    } catch (Exception ex) {
                        Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
                        return;
                    }
                    calculateTx0(selectedPoolViewModel.getDenomination(), selectedPoolViewModel.getMinerFee() / 1000L);
                    newPoolViewPager.setCurrentItem(2);
                    confirmButton.setText(getString(R.string.begin_cycle));
                    confirmButton.setBackgroundResource(R.drawable.button_green);
                    reviewPoolFragment.setTx0(tx0);
                    break;
                }
            case 2:
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage(R.string.block_tx0_change).setCancelable(false);
                    AlertDialog alert = builder.create();
                    alert.setTitle(R.string.doxxic_change_warning);
                    alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), (dialog, id) -> {
                        dialog.dismiss();
                        blockChangeOutput = true;
                        processWhirlPool();
                    });
                    alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                            blockChangeOutput = false;
                            processWhirlPool();
                        }
                    });
                    if (!isFinishing()) {
                        alert.show();
                    }
                    break;
                }
        }
    });
    setUpViewPager();
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        if (account == WhirlpoolMeta.getInstance(getApplication()).getWhirlpoolPostmix()) {
            selectedCoins.clear();
            List<UTXOCoin> coinList = PreSelectUtil.getInstance().getPreSelected(preselectId);
            try {
                onUTXOSelected(coinList);
                newPoolViewPager.setCurrentItem(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) MonetaryUtil(com.samourai.wallet.util.MonetaryUtil) PoolViewModel(com.samourai.wallet.whirlpool.models.PoolViewModel) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Spannable(android.text.Spannable) Completable(io.reactivex.Completable) ImageView(android.widget.ImageView) UnspentOutputWithKey(com.samourai.whirlpool.client.tx0.UnspentOutputWithKey) Optional(java8.util.Optional) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) WhirlpoolMeta(com.samourai.wallet.whirlpool.WhirlpoolMeta) SelectPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.SelectPoolFragment) Tx0(com.samourai.whirlpool.client.tx0.Tx0) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) WhirlpoolWallet(com.samourai.whirlpool.client.wallet.WhirlpoolWallet) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) ReviewPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.ReviewPoolFragment) Schedulers(io.reactivex.schedulers.Schedulers) UTXOUtil(com.samourai.wallet.utxos.UTXOUtil) Log(android.util.Log) BOLD(android.graphics.Typeface.BOLD) PreSelectUtil(com.samourai.wallet.utxos.PreSelectUtil) FeeUtil(com.samourai.wallet.send.FeeUtil) AndroidWhirlpoolWalletService(com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService) Collection(java.util.Collection) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) ChooseUTXOsFragment(com.samourai.wallet.whirlpool.newPool.fragments.ChooseUTXOsFragment) AppCompatActivity(android.support.v7.app.AppCompatActivity) ECKey(org.bitcoinj.core.ECKey) AlertDialog(android.app.AlertDialog) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Tx0FeeTarget(com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget) WhirlpoolTx0(com.samourai.wallet.whirlpool.WhirlpoolTx0) Snackbar(android.support.design.widget.Snackbar) WhirlpoolWalletAccount(com.samourai.whirlpool.client.wallet.beans.WhirlpoolWalletAccount) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) UnspentResponse(com.samourai.wallet.api.backend.beans.UnspentResponse) MenuItem(android.view.MenuItem) Hex(org.bouncycastle.util.encoders.Hex) ArrayList(java.util.ArrayList) SendFactory(com.samourai.wallet.send.SendFactory) PoolCyclePriority(com.samourai.wallet.whirlpool.models.PoolCyclePriority) Toast(android.widget.Toast) DialogInterface(android.content.DialogInterface) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) SpannableString(android.text.SpannableString) Tx0Config(com.samourai.whirlpool.client.tx0.Tx0Config) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) R(com.samourai.wallet.R) ViewPager(com.samourai.wallet.widgets.ViewPager) FragmentManager(android.support.v4.app.FragmentManager) Toolbar(android.support.v7.widget.Toolbar) WhirlpoolNotificationService(com.samourai.wallet.whirlpool.service.WhirlpoolNotificationService) Activity(android.app.Activity) LogUtil(com.samourai.wallet.util.LogUtil) DialogInterface(android.content.DialogInterface) ReviewPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.ReviewPoolFragment) SpannableString(android.text.SpannableString) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) SelectPoolFragment(com.samourai.wallet.whirlpool.newPool.fragments.SelectPoolFragment) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin 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 14 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class UTXOSActivity method markAsSpendable.

private void markAsSpendable() {
    for (UTXOCoin model : filteredUTXOs) {
        if (model.isSelected) {
            if (model.amount < BlockedUTXO.BLOCKED_UTXO_THRESHOLD && BlockedUTXO.getInstance().contains(model.hash, model.idx)) {
                BlockedUTXO.getInstance().remove(model.hash, model.idx);
                BlockedUTXO.getInstance().addNotDusted(model.hash, model.idx);
            } else if (BlockedUTXO.getInstance().contains(model.hash, model.idx)) {
                BlockedUTXO.getInstance().remove(model.hash, model.idx);
            } else if (BlockedUTXO.getInstance().containsPostMix(model.hash, model.idx)) {
                BlockedUTXO.getInstance().removePostMix(model.hash, model.idx);
            }
            utxoList.post(() -> loadUTXOs(true));
            setResult(RESULT_OK);
        }
    }
    saveWalletState();
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin)

Example 15 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class UTXOSActivity method calculateSelectedAmount.

private void calculateSelectedAmount() {
    long amount = 0L;
    for (UTXOCoin model : this.filteredUTXOs) {
        if (model.isSelected) {
            amount = amount + model.amount;
        }
    }
    toolbarActionMode.setTitle(df.format(((double) (amount) / 1e8)) + " BTC");
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin)

Aggregations

UTXOCoin (com.samourai.wallet.utxos.models.UTXOCoin)20 ArrayList (java.util.ArrayList)16 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)7 Disposable (io.reactivex.disposables.Disposable)7 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)6 List (java.util.List)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 IOException (java.io.IOException)5 MnemonicException (org.bitcoinj.crypto.MnemonicException)5 AlertDialog (android.app.AlertDialog)4 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)4 MenuItem (android.view.MenuItem)4 Toast (android.widget.Toast)4 R (com.samourai.wallet.R)4 UTXO (com.samourai.wallet.send.UTXO)4 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)4