Search in sources :

Example 6 with SegwitAddress

use of com.samourai.wallet.segwit.SegwitAddress in project samourai-wallet-android by Samourai-Wallet.

the class SweepUtil method sweep.

public void sweep(final PrivKeyReader privKeyReader, final int type) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            try {
                if (privKeyReader == null || privKeyReader.getKey() == null || !privKeyReader.getKey().hasPrivKey()) {
                    Toast.makeText(context, R.string.cannot_recognize_privkey, Toast.LENGTH_SHORT).show();
                    return;
                }
                final String address;
                UTXO utxo = null;
                if (type == TYPE_P2SH_P2WPKH) {
                    utxo = utxoP2SH_P2WPKH;
                    address = addressP2SH_P2WPKH;
                } else if (type == TYPE_P2WPKH) {
                    utxo = utxoP2WPKH;
                    address = addressP2WPKH;
                } else {
                    addressP2PKH = privKeyReader.getKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
                    Log.d("SweepUtil", "address derived P2PKH:" + addressP2PKH);
                    addressP2SH_P2WPKH = new SegwitAddress(privKeyReader.getKey(), SamouraiWallet.getInstance().getCurrentNetworkParams()).getAddressAsString();
                    Log.d("SweepUtil", "address derived P2SH_P2WPKH:" + addressP2SH_P2WPKH);
                    addressP2WPKH = new SegwitAddress(privKeyReader.getKey(), SamouraiWallet.getInstance().getCurrentNetworkParams()).getBech32AsString();
                    Log.d("SweepUtil", "address derived P2WPKH:" + addressP2WPKH);
                    utxoP2PKH = APIFactory.getInstance(context).getUnspentOutputsForSweep(addressP2PKH);
                    utxoP2SH_P2WPKH = APIFactory.getInstance(context).getUnspentOutputsForSweep(addressP2SH_P2WPKH);
                    utxoP2WPKH = APIFactory.getInstance(context).getUnspentOutputsForSweep(addressP2WPKH);
                    utxo = utxoP2PKH;
                    address = addressP2PKH;
                }
                if (utxo != null) {
                    long total_value = 0L;
                    final List<MyTransactionOutPoint> outpoints = utxo.getOutpoints();
                    for (MyTransactionOutPoint outpoint : outpoints) {
                        total_value += outpoint.getValue().longValue();
                    }
                    if (FeeUtil.getInstance().getSuggestedFee().getDefaultPerKB().longValue() <= 1000L) {
                        SuggestedFee suggestedFee = new SuggestedFee();
                        suggestedFee.setDefaultPerKB(BigInteger.valueOf(1100L));
                        Log.d("SweepUtil", "adjusted fee:" + suggestedFee.getDefaultPerKB().longValue());
                        FeeUtil.getInstance().setSuggestedFee(suggestedFee);
                    }
                    Log.d("SweepUtil", "outpoints:" + outpoints.size());
                    Log.d("SweepUtil", "type:" + type);
                    final BigInteger fee;
                    if (type == TYPE_P2SH_P2WPKH) {
                        fee = FeeUtil.getInstance().estimatedFeeSegwit(0, outpoints.size(), 1);
                    } else if (type == TYPE_P2WPKH) {
                        fee = FeeUtil.getInstance().estimatedFeeSegwit(0, 0, outpoints.size(), 1);
                    } else {
                        fee = FeeUtil.getInstance().estimatedFee(outpoints.size(), 1);
                    }
                    final long amount = total_value - fee.longValue();
                    // Log.d("BalanceActivity", "Total value:" + total_value);
                    // Log.d("BalanceActivity", "Amount:" + amount);
                    Log.d("SweepUtil", "Fee:" + fee.toString());
                    String message = "Sweep " + Coin.valueOf(amount).toPlainString() + " from " + address + " (fee:" + Coin.valueOf(fee.longValue()).toPlainString() + ")?";
                    AlertDialog.Builder builder = new AlertDialog.Builder(context);
                    builder.setTitle(R.string.app_name);
                    builder.setMessage(message);
                    builder.setCancelable(false);
                    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            final ProgressDialog progress = new ProgressDialog(context);
                            progress.setCancelable(false);
                            progress.setTitle(R.string.app_name);
                            progress.setMessage(context.getString(R.string.please_wait_sending));
                            progress.show();
                            String receive_address = null;
                            if (PrefsUtil.getInstance(context).getValue(PrefsUtil.USE_SEGWIT, true) == true) {
                                receive_address = AddressFactory.getInstance(context).getBIP84(AddressFactory.RECEIVE_CHAIN).getBech32AsString();
                            } else {
                                receive_address = AddressFactory.getInstance(context).get(AddressFactory.RECEIVE_CHAIN).getAddressString();
                            }
                            final HashMap<String, BigInteger> receivers = new HashMap<String, BigInteger>();
                            receivers.put(receive_address, BigInteger.valueOf(amount));
                            org.bitcoinj.core.Transaction tx = SendFactory.getInstance(context).makeTransaction(0, outpoints, receivers);
                            tx = SendFactory.getInstance(context).signTransactionForSweep(tx, privKeyReader);
                            Log.d("SweepUtil", "tx size:" + tx.bitcoinSerialize().length);
                            final String hexTx = new String(Hex.encode(tx.bitcoinSerialize()));
                            // Log.d("BalanceActivity", hexTx);
                            String response = null;
                            try {
                                if (PrefsUtil.getInstance(context).getValue(PrefsUtil.USE_TRUSTED_NODE, false) == true) {
                                    if (TrustedNodeUtil.getInstance().isSet()) {
                                        response = PushTx.getInstance(context).trustedNode(hexTx);
                                        JSONObject jsonObject = new org.json.JSONObject(response);
                                        if (jsonObject.has("result")) {
                                            if (jsonObject.getString("result").matches("^[A-Za-z0-9]{64}$")) {
                                                Toast.makeText(context, R.string.tx_sent, Toast.LENGTH_SHORT).show();
                                            } else {
                                                Toast.makeText(context, R.string.trusted_node_tx_error, Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    } else {
                                        Toast.makeText(context, R.string.trusted_node_not_valid, Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    response = PushTx.getInstance(context).samourai(hexTx);
                                    if (response != null) {
                                        JSONObject jsonObject = new org.json.JSONObject(response);
                                        if (jsonObject.has("status")) {
                                            if (jsonObject.getString("status").equals("ok")) {
                                                Toast.makeText(context, R.string.tx_sent, Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    } else {
                                        Toast.makeText(context, R.string.pushtx_returns_null, Toast.LENGTH_SHORT).show();
                                    }
                                }
                            } catch (JSONException je) {
                                Toast.makeText(context, "pushTx:" + je.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                            if (progress != null && progress.isShowing()) {
                                progress.dismiss();
                            }
                        }
                    });
                    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            ;
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else if (type == TYPE_P2SH_P2WPKH) {
                    sweep(privKeyReader, TYPE_P2WPKH);
                } else if (type == TYPE_P2PKH) {
                    sweep(privKeyReader, TYPE_P2SH_P2WPKH);
                } else if (type == TYPE_P2WPKH) {
                    ;
                } else {
                    ;
                }
            } catch (Exception e) {
                Toast.makeText(context, R.string.cannot_sweep_privkey, Toast.LENGTH_SHORT).show();
            }
            Looper.loop();
        }
    }).start();
}
Also used : AlertDialog(android.app.AlertDialog) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) DialogInterface(android.content.DialogInterface) HashMap(java.util.HashMap) ProgressDialog(android.app.ProgressDialog) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) BigInteger(java.math.BigInteger)

Example 7 with SegwitAddress

use of com.samourai.wallet.segwit.SegwitAddress in project samourai-wallet-android by Samourai-Wallet.

the class BatchSendActivity method processPCode.

private void processPCode(String pcode, String meta) {
    if (FormatsUtil.getInstance().isValidPaymentCode(pcode)) {
        if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_SENT_CFM) {
            try {
                PaymentCode _pcode = new PaymentCode(pcode);
                PaymentAddress paymentAddress = BIP47Util.getInstance(BatchSendActivity.this).getSendAddress(_pcode, BIP47Meta.getInstance().getOutgoingIdx(pcode));
                if (BIP47Meta.getInstance().getSegwit(pcode)) {
                    SegwitAddress segwitAddress = new SegwitAddress(paymentAddress.getSendECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
                    strDestinationBTCAddress = segwitAddress.getBech32AsString();
                } else {
                    strDestinationBTCAddress = paymentAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
                }
                strPCode = _pcode.toString();
                edAddress.setText(BIP47Meta.getInstance().getDisplayLabel(strPCode));
                edAddress.setEnabled(false);
            } catch (Exception e) {
                Toast.makeText(BatchSendActivity.this, R.string.error_payment_code, Toast.LENGTH_SHORT).show();
            }
        } else {
            if (meta != null && meta.startsWith("?") && meta.length() > 1) {
                meta = meta.substring(1);
            }
            Intent intent = new Intent(BatchSendActivity.this, PayNymDetailsActivity.class);
            intent.putExtra("pcode", pcode);
            if (meta != null && meta.length() > 0) {
                if (meta.startsWith("?") && meta.length() > 1) {
                    meta = meta.substring(1);
                    if (meta.length() > 0) {
                        String _meta = null;
                        Map<String, String> map = new HashMap<String, String>();
                        meta.length();
                        try {
                            _meta = URLDecoder.decode(meta, "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        map = Splitter.on('&').trimResults().withKeyValueSeparator("=").split(_meta);
                        intent.putExtra("label", map.containsKey("title") ? map.get("title").trim() : "");
                    }
                }
            }
            startActivity(intent);
        }
    } else {
        Toast.makeText(BatchSendActivity.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
    }
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) WriterException(com.google.zxing.WriterException) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MnemonicException(org.bitcoinj.crypto.MnemonicException) IOException(java.io.IOException)

Example 8 with SegwitAddress

use of com.samourai.wallet.segwit.SegwitAddress in project samourai-wallet-android by Samourai-Wallet.

the class PayNymCalcActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_paynym_calc);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    edPayNym = (EditText) findViewById(R.id.paynym);
    edIndex = (EditText) findViewById(R.id.index);
    edPayNym.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // final int DRAWABLE_LEFT = 0;
            // final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (edPayNym.getRight() - edPayNym.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                final List<String> entries = new ArrayList<String>();
                entries.addAll(BIP47Meta.getInstance().getSortedByLabels(true));
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PayNymCalcActivity.this, android.R.layout.select_dialog_singlechoice);
                for (int i = 0; i < entries.size(); i++) {
                    arrayAdapter.add(BIP47Meta.getInstance().getDisplayLabel(entries.get(i)));
                }
                AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this);
                dlg.setIcon(R.drawable.ic_launcher);
                dlg.setTitle(R.string.app_name);
                dlg.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        edPayNym.setText(entries.get(which));
                    }
                });
                dlg.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                dlg.show();
                return true;
            }
            return false;
        }
    });
    btOK = (Button) findViewById(R.id.ok);
    btOK.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String strPayNym = edPayNym.getText().toString();
            String strIndex = edIndex.getText().toString();
            PaymentCode pcode = new PaymentCode(strPayNym);
            if (pcode == null) {
                Toast.makeText(PayNymCalcActivity.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
                return;
            }
            if (strIndex == null || strIndex.length() < 1) {
                Toast.makeText(PayNymCalcActivity.this, R.string.invalid_index, Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                int index = Integer.parseInt(strIndex);
                String message = strPayNym;
                final ECKey receiveECKey;
                final SegwitAddress receiveSegwit;
                PaymentAddress receiveAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getReceiveAddress(new PaymentCode(strPayNym), index);
                PaymentAddress sendAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getSendAddress(new PaymentCode(strPayNym), index);
                receiveECKey = receiveAddress.getReceiveECKey();
                ECKey sendECKey = sendAddress.getSendECKey();
                receiveSegwit = new SegwitAddress(receiveECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
                SegwitAddress sendSegwit = new SegwitAddress(sendECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
                message += "\n";
                message += index + ":";
                message += "\n";
                message += "\n";
                message += PayNymCalcActivity.this.getText(R.string.receive_addresses).toString() + ":";
                message += "\n";
                message += receiveECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
                message += "\n";
                message += receiveSegwit.getAddressAsString();
                message += "\n";
                message += receiveSegwit.getBech32AsString();
                message += "\n";
                message += PayNymCalcActivity.this.getText(R.string.send_addresses).toString() + ":";
                message += "\n";
                message += sendECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
                message += "\n";
                message += sendSegwit.getAddressAsString();
                message += "\n";
                message += sendSegwit.getBech32AsString();
                message += "\n";
                final TextView tvText = new TextView(getApplicationContext());
                tvText.setTextSize(12);
                tvText.setText(message);
                tvText.setTextIsSelectable(true);
                tvText.setPadding(40, 10, 40, 10);
                tvText.setTextColor(0xffffffff);
                AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(tvText).setCancelable(true).setPositiveButton(R.string.display_receive_redeem, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        String redeemScript = org.spongycastle.util.encoders.Hex.toHexString(receiveSegwit.segWitRedeemScript().getProgram());
                        TextView showText = new TextView(PayNymCalcActivity.this);
                        showText.setText(redeemScript);
                        showText.setTextIsSelectable(true);
                        showText.setPadding(40, 10, 40, 10);
                        showText.setTextSize(18.0f);
                        new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.dismiss();
                            }
                        }).show();
                    }
                }).setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                    }
                }).setNegativeButton(R.string.display_receive_privkey, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        String strPrivKey = receiveECKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
                        ImageView showQR = new ImageView(PayNymCalcActivity.this);
                        Bitmap bitmap = null;
                        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(strPrivKey, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 500);
                        try {
                            bitmap = qrCodeEncoder.encodeAsBitmap();
                        } catch (WriterException e) {
                            e.printStackTrace();
                        }
                        showQR.setImageBitmap(bitmap);
                        TextView showText = new TextView(PayNymCalcActivity.this);
                        showText.setText(strPrivKey);
                        showText.setTextIsSelectable(true);
                        showText.setPadding(40, 10, 40, 10);
                        showText.setTextSize(18.0f);
                        LinearLayout privkeyLayout = new LinearLayout(PayNymCalcActivity.this);
                        privkeyLayout.setOrientation(LinearLayout.VERTICAL);
                        privkeyLayout.addView(showQR);
                        privkeyLayout.addView(showText);
                        new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(privkeyLayout).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                ;
                            }
                        }).show();
                    }
                });
                if (!isFinishing()) {
                    dlg.show();
                }
            } catch (Exception e) {
                Toast.makeText(PayNymCalcActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });
    btCancel = (Button) findViewById(R.id.cancel);
    btCancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            finish();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) ECKey(org.bitcoinj.core.ECKey) Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) ImageView(android.widget.ImageView) PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WriterException(com.google.zxing.WriterException) MotionEvent(android.view.MotionEvent) ArrayAdapter(android.widget.ArrayAdapter) WriterException(com.google.zxing.WriterException) LinearLayout(android.widget.LinearLayout)

Example 9 with SegwitAddress

use of com.samourai.wallet.segwit.SegwitAddress in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity method redeem.

private void redeem() {
    ECKey ecKey = SendFactory.getPrivKey(addr, account);
    SegwitAddress segwitAddress = new SegwitAddress(ecKey.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
    if (ecKey != null && segwitAddress != null) {
        String redeemScript = Hex.toHexString(segwitAddress.segWitRedeemScript().getProgram());
        TextView showText = new TextView(this);
        showText.setText(redeemScript);
        showText.setTextIsSelectable(true);
        showText.setPadding(40, 10, 40, 10);
        showText.setTextSize(18.0f);
        new AlertDialog.Builder(this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, (dialog, whichButton) -> {
        }).show();
    }
}
Also used : 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) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) ECKey(org.bitcoinj.core.ECKey) TextView(android.widget.TextView)

Example 10 with SegwitAddress

use of com.samourai.wallet.segwit.SegwitAddress in project samourai-wallet-android by Samourai-Wallet.

the class AddressFactory method getBIP49.

public SegwitAddress getBIP49(int chain) {
    int idx = 0;
    HD_Address addr = null;
    SegwitAddress p2shp2wpkh = null;
    // try	{
    HD_Wallet hdw = BIP49Util.getInstance(context).getWallet();
    if (hdw != null) {
        idx = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddrIdx();
        addr = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddressAt(idx);
        p2shp2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
        if (chain == RECEIVE_CHAIN && canIncBIP49ReceiveAddress(idx)) {
            BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).incAddrIdx();
        // PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
        }
    }
    return p2shp2wpkh;
}
Also used : HD_Wallet(com.samourai.wallet.hd.HD_Wallet) HD_Address(com.samourai.wallet.hd.HD_Address) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress)

Aggregations

SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)30 ECKey (org.bitcoinj.core.ECKey)17 HashMap (java.util.HashMap)12 JSONException (org.json.JSONException)12 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)11 HD_Address (com.samourai.wallet.hd.HD_Address)10 IOException (java.io.IOException)10 MnemonicException (org.bitcoinj.crypto.MnemonicException)10 JSONObject (org.json.JSONObject)9 Triple (org.apache.commons.lang3.tuple.Triple)8 Script (org.bitcoinj.script.Script)8 ArrayList (java.util.ArrayList)7 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)7 AlertDialog (android.app.AlertDialog)6 DialogInterface (android.content.DialogInterface)5 WriterException (com.google.zxing.WriterException)5 PaymentAddress (com.samourai.wallet.bip47.rpc.PaymentAddress)5 PaymentCode (com.samourai.wallet.bip47.rpc.PaymentCode)5 UTXO (com.samourai.wallet.send.UTXO)5 TransactionSignature (org.bitcoinj.crypto.TransactionSignature)5