Search in sources :

Example 11 with UTXO

use of com.samourai.wallet.send.UTXO in project samourai-wallet-android by Samourai-Wallet.

the class CahootsUtil method doSTONEWALLx2_3.

// 
// counterparty
// 
public Cahoots doSTONEWALLx2_3(STONEWALLx2 stonewall2) throws Exception {
    HashMap<String, String> utxo2Address = new HashMap<String, String>();
    List<UTXO> utxos = null;
    if (stonewall2.getCounterpartyAccount() == WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()) {
        utxos = APIFactory.getInstance(context).getUtxosPostMix(true);
    } else {
        utxos = APIFactory.getInstance(context).getUtxos(true);
    }
    for (UTXO utxo : utxos) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            utxo2Address.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getAddress());
        }
    }
    Transaction transaction = stonewall2.getTransaction();
    HashMap<String, ECKey> keyBag_A = new HashMap<String, ECKey>();
    for (TransactionInput input : transaction.getInputs()) {
        TransactionOutPoint outpoint = input.getOutpoint();
        String key = outpoint.getHash().toString() + "-" + outpoint.getIndex();
        if (utxo2Address.containsKey(key)) {
            String address = utxo2Address.get(key);
            ECKey eckey = SendFactory.getPrivKey(address, stonewall2.getCounterpartyAccount());
            keyBag_A.put(outpoint.toString(), eckey);
        }
    }
    STONEWALLx2 stonewall3 = new STONEWALLx2(stonewall2);
    stonewall3.inc(null, null, keyBag_A);
    return stonewall3;
}
Also used : UTXO(com.samourai.wallet.send.UTXO) Transaction(org.bitcoinj.core.Transaction) HashMap(java.util.HashMap) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) ECKey(org.bitcoinj.core.ECKey) TransactionInput(org.bitcoinj.core.TransactionInput) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 12 with UTXO

use of com.samourai.wallet.send.UTXO in project samourai-wallet-android by Samourai-Wallet.

the class CahootsUtil method getCahootsValue.

public long getCahootsValue(int account) {
    long ret = 0L;
    List<UTXO> _utxos = getCahootsUTXO(account);
    for (UTXO utxo : _utxos) {
        ret += utxo.getValue();
    }
    return ret;
}
Also used : UTXO(com.samourai.wallet.send.UTXO)

Example 13 with UTXO

use of com.samourai.wallet.send.UTXO in project samourai-wallet-android by Samourai-Wallet.

the class CahootsUtil method doSTONEWALLx2_4.

// 
// sender
// 
public Cahoots doSTONEWALLx2_4(STONEWALLx2 stonewall3) throws Exception {
    HashMap<String, String> utxo2Address = new HashMap<String, String>();
    List<UTXO> utxos = null;
    if (stonewall3.getAccount() == WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()) {
        utxos = APIFactory.getInstance(context).getUtxosPostMix(true);
    } else {
        utxos = APIFactory.getInstance(context).getUtxos(true);
    }
    for (UTXO utxo : utxos) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            utxo2Address.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getAddress());
        }
    }
    Transaction transaction = stonewall3.getTransaction();
    HashMap<String, ECKey> keyBag_B = new HashMap<String, ECKey>();
    for (TransactionInput input : transaction.getInputs()) {
        TransactionOutPoint outpoint = input.getOutpoint();
        String key = outpoint.getHash().toString() + "-" + outpoint.getIndex();
        if (utxo2Address.containsKey(key)) {
            String address = utxo2Address.get(key);
            ECKey eckey = SendFactory.getPrivKey(address, stonewall3.getAccount());
            keyBag_B.put(outpoint.toString(), eckey);
        }
    }
    STONEWALLx2 stonewall4 = new STONEWALLx2(stonewall3);
    stonewall4.inc(null, null, keyBag_B);
    return stonewall4;
}
Also used : UTXO(com.samourai.wallet.send.UTXO) Transaction(org.bitcoinj.core.Transaction) HashMap(java.util.HashMap) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) ECKey(org.bitcoinj.core.ECKey) TransactionInput(org.bitcoinj.core.TransactionInput) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 14 with UTXO

use of com.samourai.wallet.send.UTXO in project samourai-wallet-android by Samourai-Wallet.

the class CahootsUtil method doStowaway3.

// 
// receiver
// 
public Cahoots doStowaway3(Stowaway stowaway2) throws Exception {
    debug("CahootsUtil", "sender account (3):" + stowaway2.getAccount());
    HashMap<String, String> utxo2Address = new HashMap<String, String>();
    List<UTXO> utxos = APIFactory.getInstance(context).getUtxos(true);
    for (UTXO utxo : utxos) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            utxo2Address.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getAddress());
            debug("CahootsUtil", "outpoint address:" + outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN() + "," + outpoint.getAddress());
        }
    }
    Transaction transaction = stowaway2.getPSBT().getTransaction();
    HashMap<String, ECKey> keyBag_A = new HashMap<String, ECKey>();
    for (TransactionInput input : transaction.getInputs()) {
        TransactionOutPoint outpoint = input.getOutpoint();
        String key = outpoint.getHash().toString() + "-" + outpoint.getIndex();
        if (utxo2Address.containsKey(key)) {
            String address = utxo2Address.get(key);
            ECKey eckey = SendFactory.getPrivKey(address, 0);
            keyBag_A.put(outpoint.toString(), eckey);
        }
    }
    Stowaway stowaway3 = new Stowaway(stowaway2);
    stowaway3.inc(null, null, keyBag_A);
    return stowaway3;
}
Also used : UTXO(com.samourai.wallet.send.UTXO) Transaction(org.bitcoinj.core.Transaction) HashMap(java.util.HashMap) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) ECKey(org.bitcoinj.core.ECKey) TransactionInput(org.bitcoinj.core.TransactionInput) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 15 with UTXO

use of com.samourai.wallet.send.UTXO in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity method sendUTXOtoWhirlpool.

private void sendUTXOtoWhirlpool() {
    new AlertDialog.Builder(this).setMessage("Send utxo to whirlpool").setCancelable(false).setPositiveButton(R.string.ok, (dialog, whichButton) -> {
        ArrayList<UTXOCoin> list = new ArrayList<>();
        list.add(utxoCoin);
        String id = UUID.randomUUID().toString();
        PreSelectUtil.getInstance().clear();
        PreSelectUtil.getInstance().add(id, list);
        if (account == WhirlpoolMeta.getInstance(getApplication()).getWhirlpoolPostmix()) {
            if (!utxoCoin.path.startsWith("M/1/")) {
                Snackbar.make(paynymLayout.getRootView(), R.string.only_change_utxos_allowed, Snackbar.LENGTH_LONG).show();
                return;
            }
        }
        if (utxoCoin.doNotSpend) {
            Snackbar.make(paynymLayout.getRootView(), R.string.selection_contains_blocked_utxo, Snackbar.LENGTH_LONG).show();
            return;
        }
        if (id != null) {
            Intent intent = new Intent(getApplicationContext(), WhirlpoolMain.class);
            intent.putExtra("preselected", id);
            intent.putExtra("_account", account);
            startActivity(intent);
        }
    }).setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
    }).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) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

UTXO (com.samourai.wallet.send.UTXO)35 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)33 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)19 Transaction (org.bitcoinj.core.Transaction)17 IOException (java.io.IOException)14 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)14 BlockedUTXO (com.samourai.wallet.send.BlockedUTXO)13 BigInteger (java.math.BigInteger)13 MnemonicException (org.bitcoinj.crypto.MnemonicException)13 JSONException (org.json.JSONException)13 JSONObject (org.json.JSONObject)13 ECKey (org.bitcoinj.core.ECKey)12 TransactionInput (org.bitcoinj.core.TransactionInput)10 Intent (android.content.Intent)9 SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)9 Script (org.bitcoinj.script.Script)9 AlertDialog (android.app.AlertDialog)8 DecryptionException (com.samourai.wallet.crypto.DecryptionException)8 DialogInterface (android.content.DialogInterface)6