Commit c7481004 authored by zeroleak's avatar zeroleak
Browse files

remove confusing getP2PKHClean/Toxic(), getP2SH_P2WPKHClean/Toxic(), getP2WPKHClean/Toxic()

parent c8193fda
......@@ -468,7 +468,7 @@ class PayNymDetailsActivity : SamouraiActivity() {
var utxos: MutableList<UTXO?>? = null
if (UTXOFactory.getInstance().totalP2SH_P2WPKH > amount + FeeUtil.getInstance().estimatedFeeSegwit(0, 1, 0, 4).toLong()) {
utxos = ArrayList()
utxos.addAll(UTXOFactory.getInstance().allP2SH_P2WPKH.values)
utxos.addAll(UTXOFactory.getInstance().p2SH_P2WPKH.values)
} else {
utxos = APIFactory.getInstance(this@PayNymDetailsActivity).getUtxos(true)
}
......
package com.samourai.wallet.send;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
......@@ -97,8 +96,6 @@ import com.samourai.xmanager.protocol.XManagerService;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.script.Script;
......@@ -130,8 +127,6 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import ch.boye.httpclientandroidlib.protocol.HttpProcessorBuilder;
import io.matthewnelson.topl_service.TorServiceController;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Observer;
......@@ -1260,9 +1255,9 @@ public class SendActivity extends SamouraiActivity {
utxos = SpendUtil.getUTXOS(SendActivity.this, address, neededAmount, account);
}
List<UTXO> utxosP2WPKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2WPKH().values());
List<UTXO> utxosP2SH_P2WPKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2SH_P2WPKH().values());
List<UTXO> utxosP2PKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2PKH().values());
List<UTXO> utxosP2WPKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2WPKH().values());
List<UTXO> utxosP2SH_P2WPKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2SH_P2WPKH().values());
List<UTXO> utxosP2PKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2PKH().values());
if ((preselectedUTXOs == null || preselectedUTXOs.size() == 0) && account == WhirlpoolMeta.getInstance(SendActivity.this).getWhirlpoolPostmix()) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllPostMix().values());
utxosP2WPKH = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllPostMix().values());
......
......@@ -37,14 +37,14 @@ public class SpendUtil {
} else {
return null;
}
} else if (FormatsUtil.getInstance().isValidBech32(address) && (UTXOFactory.getInstance().getAllP2WPKH().size() > 0 && UTXOFactory.getInstance().getTotalP2WPKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2WPKH().values());
} else if (FormatsUtil.getInstance().isValidBech32(address) && (UTXOFactory.getInstance().getP2WPKH().size() > 0 && UTXOFactory.getInstance().getTotalP2WPKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2WPKH().values());
// Log.d("SendActivity", "segwit utxos:" + utxos.size());
} else if (!FormatsUtil.getInstance().isValidBech32(address) && Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress() && (UTXOFactory.getInstance().getAllP2SH_P2WPKH().size() > 0 && UTXOFactory.getInstance().getTotalP2SH_P2WPKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2SH_P2WPKH().values());
} else if (!FormatsUtil.getInstance().isValidBech32(address) && Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress() && (UTXOFactory.getInstance().getP2SH_P2WPKH().size() > 0 && UTXOFactory.getInstance().getTotalP2SH_P2WPKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2SH_P2WPKH().values());
// Log.d("SendActivity", "segwit utxos:" + utxos.size());
} else if ((!FormatsUtil.getInstance().isValidBech32(address) && !Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress()) && (UTXOFactory.getInstance().getAllP2PKH().size() > 0) && (UTXOFactory.getInstance().getTotalP2PKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getAllP2PKH().values());
} else if ((!FormatsUtil.getInstance().isValidBech32(address) && !Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress()) && (UTXOFactory.getInstance().getP2PKH().size() > 0) && (UTXOFactory.getInstance().getTotalP2PKH() > neededAmount)) {
utxos = new ArrayList<UTXO>(UTXOFactory.getInstance().getP2PKH().values());
// Log.d("SendActivity", "p2pkh utxos:" + utxos.size());
} else {
utxos = APIFactory.getInstance(context).getUtxos(true);
......
......@@ -4,7 +4,6 @@ import android.content.Context;
import com.samourai.wallet.SamouraiWallet;
import com.samourai.wallet.api.APIFactory;
import com.samourai.wallet.util.LogUtil;
import com.samourai.wallet.whirlpool.WhirlpoolMeta;
import org.bitcoinj.core.Transaction;
......@@ -20,13 +19,10 @@ public class UTXOFactory {
private static UTXOFactory instance = null;
private static HashMap<String, UTXO> p2pkh_clean = null;
private static HashMap<String, UTXO> p2sh_p2wpkh_clean = null;
private static HashMap<String, UTXO> p2wpkh_clean = null;
private static HashMap<String, UTXO> p2pkh = null;
private static HashMap<String, UTXO> p2sh_p2wpkh = null;
private static HashMap<String, UTXO> p2wpkh = null;
private static HashMap<String, UTXO> postMix_clean = null;
private static HashMap<String, UTXO> p2pkh_toxic = null;
private static HashMap<String, UTXO> p2sh_p2wpkh_toxic = null;
private static HashMap<String, UTXO> p2wpkh_toxic = null;
private static HashMap<String, UTXO> postMix_toxic = null;
private static HashMap<String, UTXO> preMix = null;
private static HashMap<String, UTXO> badBank = null;
......@@ -41,13 +37,10 @@ public class UTXOFactory {
if (instance == null) {
instance = new UTXOFactory();
p2pkh_clean = new HashMap<String, UTXO>();
p2sh_p2wpkh_clean = new HashMap<String, UTXO>();
p2wpkh_clean = new HashMap<String, UTXO>();
p2pkh = new HashMap<String, UTXO>();
p2sh_p2wpkh = new HashMap<String, UTXO>();
p2wpkh = new HashMap<String, UTXO>();
postMix_clean = new HashMap<String, UTXO>();
p2pkh_toxic = new HashMap<String, UTXO>();
p2sh_p2wpkh_toxic = new HashMap<String, UTXO>();
p2wpkh_toxic = new HashMap<String, UTXO>();
postMix_toxic = new HashMap<String, UTXO>();
preMix = new HashMap<String, UTXO>();
badBank = new HashMap<String, UTXO>();
......@@ -63,13 +56,10 @@ public class UTXOFactory {
if (instance == null) {
instance = new UTXOFactory();
p2pkh_clean = new HashMap<String, UTXO>();
p2sh_p2wpkh_clean = new HashMap<String, UTXO>();
p2wpkh_clean = new HashMap<String, UTXO>();
p2pkh = new HashMap<String, UTXO>();
p2sh_p2wpkh = new HashMap<String, UTXO>();
p2wpkh = new HashMap<String, UTXO>();
postMix_clean = new HashMap<String, UTXO>();
p2pkh_toxic = new HashMap<String, UTXO>();
p2sh_p2wpkh_toxic = new HashMap<String, UTXO>();
p2wpkh_toxic = new HashMap<String, UTXO>();
postMix_toxic = new HashMap<String, UTXO>();
preMix = new HashMap<String, UTXO>();
badBank = new HashMap<String, UTXO>();
......@@ -79,46 +69,19 @@ public class UTXOFactory {
}
public void clear() {
p2pkh_clean.clear();
p2sh_p2wpkh_clean.clear();
p2wpkh_clean.clear();
p2pkh.clear();
p2sh_p2wpkh.clear();
p2wpkh.clear();
postMix_clean.clear();
p2pkh_toxic.clear();
p2sh_p2wpkh_toxic.clear();
p2wpkh_toxic.clear();
postMix_toxic.clear();
preMix.clear();
badBank.clear();
}
public HashMap<String, UTXO> getP2PKHClean() {
return p2pkh_clean;
}
public HashMap<String, UTXO> getP2SH_P2WPKHClean() {
return p2sh_p2wpkh_clean;
}
public HashMap<String, UTXO> getP2WPKHClean() {
return p2wpkh_clean;
}
public HashMap<String, UTXO> getPostMixClean() {
return postMix_clean;
}
public HashMap<String, UTXO> getP2PKHToxic() {
return p2pkh_toxic;
}
public HashMap<String, UTXO> getP2SH_P2WPKHToxic() {
return p2sh_p2wpkh_toxic;
}
public HashMap<String, UTXO> getP2WPKHToxic() {
return p2wpkh_toxic;
}
public HashMap<String, UTXO> getPostMixToxic() {
return postMix_toxic;
}
......@@ -131,25 +94,16 @@ public class UTXOFactory {
return badBank;
}
public HashMap<String, UTXO> getAllP2PKH() {
HashMap<String, UTXO> ret = new HashMap<String, UTXO>();
ret.putAll(p2pkh_clean);
ret.putAll(p2pkh_toxic);
return ret;
public HashMap<String, UTXO> getP2PKH() {
return p2pkh;
}
public HashMap<String, UTXO> getAllP2SH_P2WPKH() {
HashMap<String, UTXO> ret = new HashMap<String, UTXO>();
ret.putAll(p2sh_p2wpkh_clean);
ret.putAll(p2sh_p2wpkh_toxic);
return ret;
public HashMap<String, UTXO> getP2SH_P2WPKH() {
return p2sh_p2wpkh;
}
public HashMap<String, UTXO> getAllP2WPKH() {
HashMap<String, UTXO> ret = new HashMap<String, UTXO>();
ret.putAll(p2wpkh_clean);
ret.putAll(p2wpkh_toxic);
return ret;
public HashMap<String, UTXO> getP2WPKH() {
return p2wpkh;
}
public HashMap<String, UTXO> getAllPostMix() {
......@@ -161,46 +115,34 @@ public class UTXOFactory {
public void addP2PKH(String hash, int id, String script, UTXO utxo) {
if (!BlockedUTXO.getInstance().contains(hash, id)) {
if (isToxic(utxo)) {
p2pkh_toxic.put(script, utxo);
} else {
p2pkh_clean.put(script, utxo);
}
p2pkh.put(script, utxo);
onChange();
}
onChange();
}
public void addP2SH_P2WPKH(String hash, int id, String script, UTXO utxo) {
if (!BlockedUTXO.getInstance().contains(hash, id)) {
if (isToxic(utxo)) {
p2sh_p2wpkh_toxic.put(script, utxo);
} else {
p2sh_p2wpkh_clean.put(script, utxo);
}
p2sh_p2wpkh.put(script, utxo);
onChange();
}
onChange();
}
public void addP2WPKH(String hash, int id, String script, UTXO utxo) {
if (!BlockedUTXO.getInstance().contains(hash, id)) {
if (isToxic(utxo)) {
p2wpkh_toxic.put(script, utxo);
} else {
p2wpkh_clean.put(script, utxo);
}
p2wpkh.put(script, utxo);
onChange();
}
onChange();
}
public void addPostMix(String hash, int id, String script, UTXO utxo) {
if (!BlockedUTXO.getInstance().containsPostMix(hash, id)) {
if (isToxic(utxo)) {
if (isPostmixToxic(utxo)) {
postMix_toxic.put(script, utxo);
} else {
postMix_clean.put(script, utxo);
}
onChange();
}
onChange();
}
public void addPreMix(String hash, int id, String script, UTXO utxo) {
......@@ -213,8 +155,8 @@ public class UTXOFactory {
onChange();
}
public long getTotalP2PKHClean() {
HashMap<String, UTXO> utxos = getP2PKHClean();
public long getTotalP2PKH() {
HashMap<String, UTXO> utxos = getP2PKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
......@@ -224,8 +166,8 @@ public class UTXOFactory {
return ret;
}
public long getTotalP2SH_P2WPKHClean() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKHClean();
public long getTotalP2SH_P2WPKH() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
......@@ -235,8 +177,8 @@ public class UTXOFactory {
return ret;
}
public long getTotalP2WPKHClean() {
HashMap<String, UTXO> utxos = getP2WPKHClean();
public long getTotalP2WPKH() {
HashMap<String, UTXO> utxos = getP2WPKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
......@@ -257,8 +199,8 @@ public class UTXOFactory {
return ret;
}
public int getCountP2PKHClean() {
HashMap<String, UTXO> utxos = getP2PKHClean();
public int getCountP2PKH() {
HashMap<String, UTXO> utxos = getP2PKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
......@@ -268,8 +210,8 @@ public class UTXOFactory {
return ret;
}
public int getCountP2SH_P2WPKHClean() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKHClean();
public int getCountP2SH_P2WPKH() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
......@@ -279,8 +221,8 @@ public class UTXOFactory {
return ret;
}
public int getCountP2WPKHClean() {
HashMap<String, UTXO> utxos = getP2WPKHClean();
public int getCountP2WPKH() {
HashMap<String, UTXO> utxos = getP2WPKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
......@@ -301,39 +243,6 @@ public class UTXOFactory {
return ret;
}
public long getTotalP2PKHToxic() {
HashMap<String, UTXO> utxos = getP2PKHToxic();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalP2SH_P2WPKHToxic() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKHToxic();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalP2WPKHToxic() {
HashMap<String, UTXO> utxos = getP2WPKHToxic();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalPostMixToxic() {
HashMap<String, UTXO> utxos = getPostMixToxic();
long ret = 0L;
......@@ -356,39 +265,6 @@ public class UTXOFactory {
return ret;
}
public int getCountP2PKHToxic() {
HashMap<String, UTXO> utxos = getP2PKHToxic();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountP2SH_P2WPKHToxic() {
HashMap<String, UTXO> utxos = getP2SH_P2WPKHToxic();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountP2WPKHToxic() {
HashMap<String, UTXO> utxos = getP2WPKHToxic();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountPostMixToxic() {
HashMap<String, UTXO> utxos = getPostMixToxic();
int ret = 0;
......@@ -411,39 +287,6 @@ public class UTXOFactory {
return ret;
}
public long getTotalP2PKH() {
HashMap<String, UTXO> utxos = getAllP2PKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalP2SH_P2WPKH() {
HashMap<String, UTXO> utxos = getAllP2SH_P2WPKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalP2WPKH() {
HashMap<String, UTXO> utxos = getAllP2WPKH();
long ret = 0L;
for (UTXO utxo : utxos.values()) {
ret += utxo.getValue();
}
return ret;
}
public long getTotalPostMix() {
HashMap<String, UTXO> utxos = getAllPostMix();
long ret = 0L;
......@@ -455,39 +298,6 @@ public class UTXOFactory {
return ret;
}
public int getCountP2PKH() {
HashMap<String, UTXO> utxos = getAllP2PKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountP2SH_P2WPKH() {
HashMap<String, UTXO> utxos = getAllP2SH_P2WPKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountP2WPKH() {
HashMap<String, UTXO> utxos = getAllP2WPKH();
int ret = 0;
for (UTXO utxo : utxos.values()) {
ret += utxo.getOutpoints().size();
}
return ret;
}
public int getCountPostMix() {
HashMap<String, UTXO> utxos = getAllPostMix();
int ret = 0;
......@@ -499,7 +309,7 @@ public class UTXOFactory {
return ret;
}
private boolean isToxic(UTXO utxo) {
private boolean isPostmixToxic(UTXO utxo) {
String path = utxo.getPath();
......@@ -514,7 +324,6 @@ public class UTXOFactory {
// assume starts with "M/1/"
// any account change
else {
LogUtil.debug("UTXOFactory", "Toxic utxo: path="+utxo.getPath()+", value="+utxo.getValue());
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment