Search in sources :

Example 76 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class WalletAddressFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.fragmentManager = getChildFragmentManager();
    activityViewModel = new ViewModelProvider(activity).get(WalletActivityViewModel.class);
    viewModel = new ViewModelProvider(this).get(WalletAddressViewModel.class);
    viewModel.qrCode.observe(this, qrCode -> {
        final BitmapDrawable qrDrawable = new BitmapDrawable(getResources(), qrCode);
        qrDrawable.setFilterBitmap(false);
        currentAddressQrView.setImageDrawable(qrDrawable);
        currentAddressQrCardView.setOnClickListener(v -> viewModel.showWalletAddressDialog.setValue(Event.simple()));
    });
    viewModel.bitcoinUri.observe(this, bitcoinUri -> {
        final NfcAdapter nfcAdapter = WalletAddressFragment.this.nfcAdapter;
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(createNdefMessage(bitcoinUri.toString()), activity);
        activityViewModel.addressLoadingFinished();
    });
    viewModel.showWalletAddressDialog.observe(this, new Event.Observer<Void>() {

        @Override
        protected void onEvent(final Void v) {
            final Address address = viewModel.currentAddress.getValue();
            WalletAddressDialogFragment.show(fragmentManager);
            log.info("Current address enlarged: {}", address);
        }
    });
}
Also used : Address(org.bitcoinj.core.Address) NfcAdapter(android.nfc.NfcAdapter) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 77 with Address

use of org.bitcoinj.core.Address in project samourai-wallet-android by Samourai-Wallet.

the class RBFTask method doInBackground.

@Override
protected String doInBackground(final String... params) {
    Looper.prepare();
    Log.d("RBF", "hash:" + params[0]);
    rbf = RBFUtil.getInstance().get(params[0]);
    Log.d("RBF", "rbf:" + rbf.toJSON().toString());
    final Transaction tx = new Transaction(SamouraiWallet.getInstance().getCurrentNetworkParams(), Hex.decode(rbf.getSerializedTx()));
    Log.d("RBF", "tx serialized:" + rbf.getSerializedTx());
    Log.d("RBF", "tx inputs:" + tx.getInputs().size());
    Log.d("RBF", "tx outputs:" + tx.getOutputs().size());
    JSONObject txObj = APIFactory.getInstance(activity).getTxInfo(params[0]);
    if (tx != null && txObj.has("inputs") && txObj.has("outputs")) {
        try {
            JSONArray inputs = txObj.getJSONArray("inputs");
            JSONArray outputs = txObj.getJSONArray("outputs");
            int p2pkh = 0;
            int p2sh_p2wpkh = 0;
            int p2wpkh = 0;
            for (int i = 0; i < inputs.length(); i++) {
                if (inputs.getJSONObject(i).has("outpoint") && inputs.getJSONObject(i).getJSONObject("outpoint").has("scriptpubkey")) {
                    String scriptpubkey = inputs.getJSONObject(i).getJSONObject("outpoint").getString("scriptpubkey");
                    Script script = new Script(Hex.decode(scriptpubkey));
                    String address = null;
                    if (Bech32Util.getInstance().isBech32Script(scriptpubkey)) {
                        try {
                            address = Bech32Util.getInstance().getAddressFromScript(scriptpubkey);
                        } catch (Exception e) {
                            ;
                        }
                    } else {
                        address = script.getToAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
                    }
                    if (FormatsUtil.getInstance().isValidBech32(address)) {
                        p2wpkh++;
                    } else if (Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress()) {
                        p2sh_p2wpkh++;
                    } else {
                        p2pkh++;
                    }
                }
            }
            SuggestedFee suggestedFee = FeeUtil.getInstance().getSuggestedFee();
            FeeUtil.getInstance().setSuggestedFee(FeeUtil.getInstance().getHighFee());
            BigInteger estimatedFee = FeeUtil.getInstance().estimatedFeeSegwit(p2pkh, p2sh_p2wpkh, p2wpkh, outputs.length());
            long total_inputs = 0L;
            long total_outputs = 0L;
            long fee = 0L;
            long total_change = 0L;
            List<String> selfAddresses = new ArrayList<String>();
            for (int i = 0; i < inputs.length(); i++) {
                JSONObject obj = inputs.getJSONObject(i);
                if (obj.has("outpoint")) {
                    JSONObject objPrev = obj.getJSONObject("outpoint");
                    if (objPrev.has("value")) {
                        total_inputs += objPrev.getLong("value");
                        String key = objPrev.getString("txid") + ":" + objPrev.getLong("vout");
                        input_values.put(key, objPrev.getLong("value"));
                    }
                }
            }
            for (int i = 0; i < outputs.length(); i++) {
                JSONObject obj = outputs.getJSONObject(i);
                if (obj.has("value")) {
                    total_outputs += obj.getLong("value");
                    String _addr = null;
                    if (obj.has("address")) {
                        _addr = obj.getString("address");
                    }
                    selfAddresses.add(_addr);
                    if (_addr != null && rbf.getChangeAddrs().contains(_addr.toString())) {
                        total_change += obj.getLong("value");
                    }
                }
            }
            boolean feeWarning = false;
            fee = total_inputs - total_outputs;
            if (fee > estimatedFee.longValue()) {
                feeWarning = true;
            }
            long remainingFee = (estimatedFee.longValue() > fee) ? estimatedFee.longValue() - fee : 0L;
            Log.d("RBF", "total inputs:" + total_inputs);
            Log.d("RBF", "total outputs:" + total_outputs);
            Log.d("RBF", "total change:" + total_change);
            Log.d("RBF", "fee:" + fee);
            Log.d("RBF", "estimated fee:" + estimatedFee.longValue());
            Log.d("RBF", "fee warning:" + feeWarning);
            Log.d("RBF", "remaining fee:" + remainingFee);
            List<TransactionOutput> txOutputs = new ArrayList<TransactionOutput>();
            txOutputs.addAll(tx.getOutputs());
            long remainder = remainingFee;
            if (total_change > remainder) {
                for (TransactionOutput output : txOutputs) {
                    Script script = output.getScriptPubKey();
                    String scriptPubKey = Hex.toHexString(script.getProgram());
                    Address _p2sh = output.getAddressFromP2SH(SamouraiWallet.getInstance().getCurrentNetworkParams());
                    Address _p2pkh = output.getAddressFromP2PKHScript(SamouraiWallet.getInstance().getCurrentNetworkParams());
                    try {
                        if ((Bech32Util.getInstance().isBech32Script(scriptPubKey) && rbf.getChangeAddrs().contains(Bech32Util.getInstance().getAddressFromScript(scriptPubKey))) || (_p2sh != null && rbf.getChangeAddrs().contains(_p2sh.toString())) || (_p2pkh != null && rbf.getChangeAddrs().contains(_p2pkh.toString()))) {
                            if (output.getValue().longValue() >= (remainder + SamouraiWallet.bDust.longValue())) {
                                output.setValue(Coin.valueOf(output.getValue().longValue() - remainder));
                                remainder = 0L;
                                break;
                            } else {
                                remainder -= output.getValue().longValue();
                                // output will be discarded later
                                output.setValue(Coin.valueOf(0L));
                            }
                        }
                    } catch (Exception e) {
                        ;
                    }
                }
            }
            // 
            // original inputs are not modified
            // 
            List<MyTransactionInput> _inputs = new ArrayList<MyTransactionInput>();
            List<TransactionInput> txInputs = tx.getInputs();
            for (TransactionInput input : txInputs) {
                MyTransactionInput _input = new MyTransactionInput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, new byte[0], input.getOutpoint(), input.getOutpoint().getHash().toString(), (int) input.getOutpoint().getIndex());
                _input.setSequenceNumber(SamouraiWallet.RBF_SEQUENCE_VAL.longValue());
                _inputs.add(_input);
                Log.d("RBF", "add outpoint:" + _input.getOutpoint().toString());
            }
            Triple<Integer, Integer, Integer> outpointTypes = null;
            if (remainder > 0L) {
                List<UTXO> selectedUTXO = new ArrayList<UTXO>();
                long selectedAmount = 0L;
                int selected = 0;
                long _remainingFee = remainder;
                Collections.sort(utxos, new UTXO.UTXOComparator());
                for (UTXO _utxo : utxos) {
                    Log.d("RBF", "utxo value:" + _utxo.getValue());
                    // 
                    // do not select utxo that are change outputs in current rbf tx
                    // 
                    boolean isChange = false;
                    boolean isSelf = false;
                    for (MyTransactionOutPoint outpoint : _utxo.getOutpoints()) {
                        if (rbf.containsChangeAddr(outpoint.getAddress())) {
                            Log.d("RBF", "is change:" + outpoint.getAddress());
                            Log.d("RBF", "is change:" + outpoint.getValue().longValue());
                            isChange = true;
                            break;
                        }
                        if (selfAddresses.contains(outpoint.getAddress())) {
                            Log.d("RBF", "is self:" + outpoint.getAddress());
                            Log.d("RBF", "is self:" + outpoint.getValue().longValue());
                            isSelf = true;
                            break;
                        }
                    }
                    if (isChange || isSelf) {
                        continue;
                    }
                    selectedUTXO.add(_utxo);
                    selected += _utxo.getOutpoints().size();
                    Log.d("RBF", "selected utxo:" + selected);
                    selectedAmount += _utxo.getValue();
                    Log.d("RBF", "selected utxo value:" + _utxo.getValue());
                    outpointTypes = FeeUtil.getInstance().getOutpointCount(new Vector(_utxo.getOutpoints()));
                    p2pkh += outpointTypes.getLeft();
                    p2sh_p2wpkh += outpointTypes.getMiddle();
                    p2wpkh += outpointTypes.getRight();
                    _remainingFee = FeeUtil.getInstance().estimatedFeeSegwit(p2pkh, p2sh_p2wpkh, p2wpkh, outputs.length() == 1 ? 2 : outputs.length()).longValue();
                    Log.d("RBF", "_remaining fee:" + _remainingFee);
                    if (selectedAmount >= (_remainingFee + SamouraiWallet.bDust.longValue())) {
                        break;
                    }
                }
                long extraChange = 0L;
                if (selectedAmount < (_remainingFee + SamouraiWallet.bDust.longValue())) {
                    handler.post(new Runnable() {

                        public void run() {
                            Toast.makeText(activity, R.string.insufficient_funds, Toast.LENGTH_SHORT).show();
                        }
                    });
                    return "KO";
                } else {
                    extraChange = selectedAmount - _remainingFee;
                    Log.d("RBF", "extra change:" + extraChange);
                }
                boolean addedChangeOutput = false;
                // parent tx didn't have change output
                if (outputs.length() == 1 && extraChange > 0L) {
                    try {
                        boolean isSegwitChange = (FormatsUtil.getInstance().isValidBech32(outputs.getJSONObject(0).getString("address")) || Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), outputs.getJSONObject(0).getString("address")).isP2SHAddress()) || PrefsUtil.getInstance(activity).getValue(PrefsUtil.USE_LIKE_TYPED_CHANGE, true) == false;
                        String change_address = null;
                        if (isSegwitChange) {
                            int changeIdx = BIP49Util.getInstance(activity).getWallet().getAccount(0).getChange().getAddrIdx();
                            change_address = BIP49Util.getInstance(activity).getAddressAt(AddressFactory.CHANGE_CHAIN, changeIdx).getAddressAsString();
                        } else {
                            int changeIdx = HD_WalletFactory.getInstance(activity).get().getAccount(0).getChange().getAddrIdx();
                            change_address = HD_WalletFactory.getInstance(activity).get().getAccount(0).getChange().getAddressAt(changeIdx).getAddressString();
                        }
                        Script toOutputScript = ScriptBuilder.createOutputScript(Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), change_address));
                        TransactionOutput output = new TransactionOutput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, Coin.valueOf(extraChange), toOutputScript.getProgram());
                        txOutputs.add(output);
                        addedChangeOutput = true;
                    } catch (MnemonicException.MnemonicLengthException | IOException e) {
                        handler.post(new Runnable() {

                            public void run() {
                                Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
                                Toast.makeText(activity, R.string.cannot_create_change_output, Toast.LENGTH_SHORT).show();
                            }
                        });
                        return "KO";
                    }
                } else // parent tx had change output
                {
                    for (TransactionOutput output : txOutputs) {
                        Script script = output.getScriptPubKey();
                        String scriptPubKey = Hex.toHexString(script.getProgram());
                        String _addr = null;
                        if (Bech32Util.getInstance().isBech32Script(scriptPubKey)) {
                            try {
                                _addr = Bech32Util.getInstance().getAddressFromScript(scriptPubKey);
                            } catch (Exception e) {
                                ;
                            }
                        }
                        if (_addr == null) {
                            Address _address = output.getAddressFromP2PKHScript(SamouraiWallet.getInstance().getCurrentNetworkParams());
                            if (_address == null) {
                                _address = output.getAddressFromP2SH(SamouraiWallet.getInstance().getCurrentNetworkParams());
                            }
                            _addr = _address.toString();
                        }
                        Log.d("RBF", "checking for change:" + _addr);
                        if (rbf.containsChangeAddr(_addr)) {
                            Log.d("RBF", "before extra:" + output.getValue().longValue());
                            output.setValue(Coin.valueOf(extraChange + output.getValue().longValue()));
                            Log.d("RBF", "after extra:" + output.getValue().longValue());
                            addedChangeOutput = true;
                            break;
                        }
                    }
                }
                // sanity check
                if (extraChange > 0L && !addedChangeOutput) {
                    handler.post(new Runnable() {

                        public void run() {
                            Toast.makeText(activity, R.string.cannot_create_change_output, Toast.LENGTH_SHORT).show();
                        }
                    });
                    return "KO";
                }
                // 
                // update keyBag w/ any new paths
                // 
                final HashMap<String, String> keyBag = rbf.getKeyBag();
                for (UTXO _utxo : selectedUTXO) {
                    for (MyTransactionOutPoint outpoint : _utxo.getOutpoints()) {
                        MyTransactionInput _input = new MyTransactionInput(SamouraiWallet.getInstance().getCurrentNetworkParams(), null, new byte[0], outpoint, outpoint.getTxHash().toString(), outpoint.getTxOutputN());
                        _input.setSequenceNumber(SamouraiWallet.RBF_SEQUENCE_VAL.longValue());
                        _inputs.add(_input);
                        Log.d("RBF", "add selected outpoint:" + _input.getOutpoint().toString());
                        String path = APIFactory.getInstance(activity).getUnspentPaths().get(outpoint.getAddress());
                        if (path != null) {
                            if (FormatsUtil.getInstance().isValidBech32(outpoint.getAddress())) {
                                rbf.addKey(outpoint.toString(), path + "/84");
                            } else if (Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), outpoint.getAddress()) != null && Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), outpoint.getAddress()).isP2SHAddress()) {
                                rbf.addKey(outpoint.toString(), path + "/49");
                            } else {
                                rbf.addKey(outpoint.toString(), path);
                            }
                            Log.d("RBF", "outpoint address:" + outpoint.getAddress());
                        } else {
                            String pcode = BIP47Meta.getInstance().getPCode4Addr(outpoint.getAddress());
                            int idx = BIP47Meta.getInstance().getIdx4Addr(outpoint.getAddress());
                            rbf.addKey(outpoint.toString(), pcode + "/" + idx);
                        }
                    }
                }
                rbf.setKeyBag(keyBag);
            }
            // 
            // BIP69 sort of outputs/inputs
            // 
            final Transaction _tx = new Transaction(SamouraiWallet.getInstance().getCurrentNetworkParams());
            List<TransactionOutput> _txOutputs = new ArrayList<TransactionOutput>();
            _txOutputs.addAll(txOutputs);
            Collections.sort(_txOutputs, new BIP69OutputComparator());
            for (TransactionOutput to : _txOutputs) {
                // zero value outputs discarded here
                if (to.getValue().longValue() > 0L) {
                    _tx.addOutput(to);
                }
            }
            List<MyTransactionInput> __inputs = new ArrayList<MyTransactionInput>();
            __inputs.addAll(_inputs);
            Collections.sort(__inputs, new SendFactory.BIP69InputComparator());
            for (TransactionInput input : __inputs) {
                _tx.addInput(input);
            }
            FeeUtil.getInstance().setSuggestedFee(suggestedFee);
            String message = "";
            if (feeWarning) {
                message += activity.getString(R.string.fee_bump_not_necessary);
                message += "\n\n";
            }
            message += activity.getString(R.string.bump_fee) + " " + Coin.valueOf(remainingFee).toPlainString() + " BTC";
            AlertDialog.Builder dlg = new AlertDialog.Builder(activity).setTitle(R.string.app_name).setMessage(message).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    Transaction __tx = signTx(_tx);
                    final String hexTx = new String(Hex.encode(__tx.bitcoinSerialize()));
                    Log.d("RBF", "hex tx:" + hexTx);
                    final String strTxHash = __tx.getHashAsString();
                    Log.d("RBF", "tx hash:" + strTxHash);
                    if (__tx != null) {
                        boolean isOK = false;
                        try {
                            isOK = PushTx.getInstance(activity).pushTx(hexTx);
                            if (isOK) {
                                handler.post(new Runnable() {

                                    public void run() {
                                        Toast.makeText(activity, R.string.rbf_spent, Toast.LENGTH_SHORT).show();
                                        // includes updated 'keyBag'
                                        RBFSpend _rbf = rbf;
                                        _rbf.setSerializedTx(hexTx);
                                        _rbf.setHash(strTxHash);
                                        _rbf.setPrevHash(params[0]);
                                        RBFUtil.getInstance().add(_rbf);
                                        Intent _intent = new Intent(activity, MainActivity2.class);
                                        _intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                                        activity.startActivity(_intent);
                                    }
                                });
                            } else {
                                handler.post(new Runnable() {

                                    public void run() {
                                        Toast.makeText(activity, R.string.tx_failed, Toast.LENGTH_SHORT).show();
                                    }
                                });
                            }
                        } catch (final DecoderException de) {
                            handler.post(new Runnable() {

                                public void run() {
                                    Toast.makeText(activity, "pushTx:" + de.getMessage(), Toast.LENGTH_SHORT).show();
                                }
                            });
                        } finally {
                            ;
                        }
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            });
            if (!activity.isFinishing()) {
                dlg.show();
            }
        } catch (final JSONException je) {
            handler.post(new Runnable() {

                public void run() {
                    Toast.makeText(activity, "rbf:" + je.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    } else {
        Toast.makeText(activity, R.string.cpfp_cannot_retrieve_tx, Toast.LENGTH_SHORT).show();
    }
    Looper.loop();
    return "OK";
}
Also used : AlertDialog(android.app.AlertDialog) TransactionOutput(org.bitcoinj.core.TransactionOutput) Address(org.bitcoinj.core.Address) HD_Address(com.samourai.wallet.hd.HD_Address) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) MyTransactionInput(com.samourai.wallet.send.MyTransactionInput) TransactionInput(org.bitcoinj.core.TransactionInput) MainActivity2(com.samourai.wallet.MainActivity2) BIP69OutputComparator(com.samourai.wallet.bip69.BIP69OutputComparator) RBFSpend(com.samourai.wallet.send.RBFSpend) Vector(java.util.Vector) Script(org.bitcoinj.script.Script) SendFactory(com.samourai.wallet.send.SendFactory) SuggestedFee(com.samourai.wallet.send.SuggestedFee) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) JSONException(org.json.JSONException) DecoderException(org.bouncycastle.util.encoders.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) IOException(java.io.IOException) BigInteger(java.math.BigInteger) UTXO(com.samourai.wallet.send.UTXO) DecoderException(org.bouncycastle.util.encoders.DecoderException) Transaction(org.bitcoinj.core.Transaction) JSONObject(org.json.JSONObject) MyTransactionInput(com.samourai.wallet.send.MyTransactionInput) BigInteger(java.math.BigInteger)

Example 78 with Address

use of org.bitcoinj.core.Address in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_utxodetails);
    setSupportActionBar(findViewById(R.id.toolbar_utxo_activity));
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    addressTextView = findViewById(R.id.utxo_details_address);
    amountTextView = findViewById(R.id.utxo_details_amount);
    statusTextView = findViewById(R.id.utxo_details_spendable_status);
    hashTextView = findViewById(R.id.utxo_details_hash);
    addNote = findViewById(R.id.add_note_button);
    notesTextView = findViewById(R.id.utxo_details_note);
    deleteButton = findViewById(R.id.delete_note);
    paynymLayout = findViewById(R.id.utxo_details_paynym_container);
    paynymLayout.setVisibility(View.GONE);
    df.setMinimumIntegerDigits(1);
    df.setMinimumFractionDigits(8);
    df.setMaximumFractionDigits(8);
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("hashIdx")) {
        hashIdx = getIntent().getExtras().getString("hashIdx");
    } else {
        finish();
    }
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        account = getIntent().getExtras().getInt("_account");
    } else {
        finish();
    }
    List<UTXO> utxos = new ArrayList<>();
    if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
        utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxosPostMix(false));
    } else {
        utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxos(false));
    }
    utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxos(false));
    for (UTXO utxo : utxos) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            if (outpoint.getTxHash() != null) {
                String hashWithIdx = outpoint.getTxHash().toString().concat("-").concat(String.valueOf(outpoint.getTxOutputN()));
                if (hashWithIdx.equals(hashIdx)) {
                    idx = outpoint.getTxOutputN();
                    amount = outpoint.getValue().longValue();
                    hash = outpoint.getTxHash().toString();
                    addr = outpoint.getAddress();
                    utxoCoin = new UTXOCoin(outpoint, utxo);
                    if (BlockedUTXO.getInstance().contains(outpoint.getTxHash().toString(), outpoint.getTxOutputN())) {
                        utxoCoin.doNotSpend = true;
                    }
                    setUTXOState();
                }
            }
        }
    }
    deleteButton.setOnClickListener(view -> {
        if (UTXOUtil.getInstance().getNote(hash) != null) {
            UTXOUtil.getInstance().removeNote(hash);
        }
        setNoteState();
        saveWalletState();
    });
    addNote.setOnClickListener(view -> {
        View dialogView = getLayoutInflater().inflate(R.layout.bottom_sheet_note, null);
        BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.bottom_sheet_note);
        dialog.setContentView(dialogView);
        dialog.show();
        Button submitButton = dialog.findViewById(R.id.submit_note);
        if (UTXOUtil.getInstance().getNote(hash) != null) {
            ((EditText) dialog.findViewById(R.id.utxo_details_note)).setText(UTXOUtil.getInstance().getNote(hash));
            submitButton.setText("Save");
        } else {
            submitButton.setText("Add");
        }
        dialog.findViewById(R.id.submit_note).setOnClickListener((View view1) -> {
            dialog.dismiss();
            addNote(((EditText) dialog.findViewById(R.id.utxo_details_note)).getText().toString());
        });
    });
    setNoteState();
    addressTextView.setOnClickListener((event) -> new AlertDialog.Builder(UTXODetailsActivity.this).setTitle(R.string.app_name).setMessage(R.string.receive_address_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, (dialog, whichButton) -> {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) UTXODetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = null;
        clip = android.content.ClipData.newPlainText("address", addr);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(UTXODetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
    }).setNegativeButton(R.string.no, (dialog, whichButton) -> {
    }).show());
    hashTextView.setOnClickListener(view -> {
        new android.app.AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.txid_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, (dialog, whichButton) -> {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) UTXODetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            clip = android.content.ClipData.newPlainText("tx id", hash);
            if (clipboard != null) {
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(UTXODetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
        }).setNegativeButton(R.string.no, (dialog, whichButton) -> {
        }).show();
    });
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Completable(io.reactivex.Completable) Uri(android.net.Uri) ImageView(android.widget.ImageView) TransitionManager(android.transition.TransitionManager) WriterException(com.google.zxing.WriterException) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) WhirlpoolMeta(com.samourai.wallet.whirlpool.WhirlpoolMeta) Picasso(com.squareup.picasso.Picasso) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) View(android.view.View) Button(android.widget.Button) SendActivity(com.samourai.wallet.send.SendActivity) UTXO(com.samourai.wallet.send.UTXO) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) AccessFactory(com.samourai.wallet.access.AccessFactory) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) WebUtil(com.samourai.wallet.bip47.paynym.WebUtil) UUID(java.util.UUID) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) ECKey(org.bitcoinj.core.ECKey) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) Contents(com.google.zxing.client.android.Contents) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Address(org.bitcoinj.core.Address) BIP47Meta(com.samourai.wallet.bip47.BIP47Meta) Snackbar(android.support.design.widget.Snackbar) BarcodeFormat(com.google.zxing.BarcodeFormat) FormatsUtil(com.samourai.wallet.util.FormatsUtil) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) Intent(android.content.Intent) PayloadUtil(com.samourai.wallet.payload.PayloadUtil) MnemonicException(org.bitcoinj.crypto.MnemonicException) MenuItem(android.view.MenuItem) Hex(org.bouncycastle.util.encoders.Hex) ArrayList(java.util.ArrayList) BIP47Add(com.samourai.wallet.bip47.BIP47Add) SamouraiWallet(com.samourai.wallet.SamouraiWallet) SendFactory(com.samourai.wallet.send.SendFactory) Toast(android.widget.Toast) Menu(android.view.Menu) Observable(io.reactivex.Observable) DecryptionException(com.samourai.wallet.crypto.DecryptionException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) MessageSignUtil(com.samourai.wallet.util.MessageSignUtil) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) PayNymDetailsActivity(com.samourai.wallet.paynym.paynymDetails.PayNymDetailsActivity) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) R(com.samourai.wallet.R) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) Bitmap(android.graphics.Bitmap) WhirlpoolMain(com.samourai.wallet.whirlpool.WhirlpoolMain) APIFactory(com.samourai.wallet.api.APIFactory) LogUtil(com.samourai.wallet.util.LogUtil) EditText(android.widget.EditText) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) UTXO(com.samourai.wallet.send.UTXO) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) Button(android.widget.Button)

Aggregations

Address (org.bitcoinj.core.Address)78 Transaction (org.bitcoinj.core.Transaction)32 Coin (org.bitcoinj.core.Coin)28 TransactionOutput (org.bitcoinj.core.TransactionOutput)15 TransactionInput (org.bitcoinj.core.TransactionInput)13 ArrayList (java.util.ArrayList)12 AddressEntry (bisq.core.btc.AddressEntry)11 Wallet (org.bitcoinj.wallet.Wallet)11 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)10 AddressFormatException (org.bitcoinj.core.AddressFormatException)10 TransactionConfidence (org.bitcoinj.core.TransactionConfidence)10 IOException (java.io.IOException)9 SendRequest (org.bitcoinj.wallet.SendRequest)9 WalletService (io.bitsquare.btc.WalletService)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Nullable (javax.annotation.Nullable)8 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)8 Script (org.bitcoinj.script.Script)8 Intent (android.content.Intent)7