Search in sources :

Example 11 with MyTransactionOutPoint

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

the class APIFactory method getUtxos.

public List<UTXO> getUtxos(boolean filter) {
    long amount = 0L;
    for (String key : utxos.keySet()) {
    // for(MyTransactionOutPoint out : utxos.get(key).getOutpoints())    {
    // debug("APIFactory", "utxo:" + out.getAddress() + "," + out.getValue());
    // debug("APIFactory", "utxo:" + utxos.get(key).getPath());
    // amount += out.getValue().longValue();
    // }
    }
    debug("APIFactory", "utxos by value:" + amount);
    List<UTXO> unspents = new ArrayList<UTXO>();
    if (filter) {
        for (String key : utxos.keySet()) {
            UTXO u = new UTXO();
            for (MyTransactionOutPoint out : utxos.get(key).getOutpoints()) {
                if (!BlockedUTXO.getInstance().contains(out.getTxHash().toString(), out.getTxOutputN())) {
                    u.getOutpoints().add(out);
                    u.setPath(utxos.get(key).getPath());
                }
            }
            if (u.getOutpoints().size() > 0) {
                unspents.add(u);
            }
        }
    } else {
        unspents.addAll(utxos.values());
    }
    return unspents;
}
Also used : UTXO(com.samourai.wallet.send.UTXO) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint)

Example 12 with MyTransactionOutPoint

use of com.samourai.wallet.send.MyTransactionOutPoint 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 13 with MyTransactionOutPoint

use of com.samourai.wallet.send.MyTransactionOutPoint 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 MyTransactionOutPoint

use of com.samourai.wallet.send.MyTransactionOutPoint 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 MyTransactionOutPoint

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

the class SendActivity method markUTXOAsUnspendable.

private void markUTXOAsUnspendable(String hexTx) {
    HashMap<String, Long> utxos = new HashMap<String, Long>();
    for (UTXO utxo : APIFactory.getInstance(SendActivity.this).getUtxos(true)) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            utxos.put(outpoint.getTxHash().toString() + "-" + outpoint.getTxOutputN(), outpoint.getValue().longValue());
        }
    }
    Transaction tx = new Transaction(SamouraiWallet.getInstance().getCurrentNetworkParams(), Hex.decode(hexTx));
    for (TransactionInput input : tx.getInputs()) {
        BlockedUTXO.getInstance().add(input.getOutpoint().getHash().toString(), (int) input.getOutpoint().getIndex(), utxos.get(input.getOutpoint().getHash().toString() + "-" + (int) input.getOutpoint().getIndex()));
    }
}
Also used : UTXO(com.samourai.wallet.send.UTXO) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) Transaction(org.bitcoinj.core.Transaction) HashMap(java.util.HashMap) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) TransactionInput(org.bitcoinj.core.TransactionInput)

Aggregations

MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)31 UTXO (com.samourai.wallet.send.UTXO)28 HashMap (java.util.HashMap)19 ArrayList (java.util.ArrayList)18 Transaction (org.bitcoinj.core.Transaction)16 BlockedUTXO (com.samourai.wallet.send.BlockedUTXO)12 IOException (java.io.IOException)12 BigInteger (java.math.BigInteger)12 ECKey (org.bitcoinj.core.ECKey)12 TransactionOutPoint (org.bitcoinj.core.TransactionOutPoint)12 MnemonicException (org.bitcoinj.crypto.MnemonicException)11 JSONException (org.json.JSONException)11 JSONObject (org.json.JSONObject)11 TransactionInput (org.bitcoinj.core.TransactionInput)10 Script (org.bitcoinj.script.Script)9 Intent (android.content.Intent)8 SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)8 AlertDialog (android.app.AlertDialog)7 DecryptionException (com.samourai.wallet.crypto.DecryptionException)7 DialogInterface (android.content.DialogInterface)6