use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class SettingsActivity2 method doPrune.
private void doPrune() {
AlertDialog.Builder dlg = new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.prune_backup).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
// BIP47Meta.getInstance().pruneIncoming();
SendAddressUtil.getInstance().reset();
RicochetMeta.getInstance(SettingsActivity2.this).empty();
BatchSendUtil.getInstance().clear();
RBFUtil.getInstance().clear();
PayloadUtil.getInstance(SettingsActivity2.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(SettingsActivity2.this).getGUID() + AccessFactory.getInstance(SettingsActivity2.this).getPIN()));
} catch (JSONException je) {
je.printStackTrace();
Toast.makeText(SettingsActivity2.this, R.string.error_reading_payload, Toast.LENGTH_SHORT).show();
} catch (MnemonicException.MnemonicLengthException mle) {
;
} catch (IOException ioe) {
;
} catch (DecryptionException de) {
;
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
});
if (!isFinishing()) {
dlg.show();
}
}
use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class PinEntryActivity method doBackupRestore.
void doBackupRestore() {
File file = PayloadUtil.getInstance(PinEntryActivity.this).getBackupFile();
if (file != null && file.exists()) {
StringBuilder sb = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
String str = null;
while ((str = in.readLine()) != null) {
sb.append(str);
}
in.close();
} catch (FileNotFoundException fnfe) {
;
} catch (IOException ioe) {
;
}
final String data = sb.toString();
if (data != null && data.length() > 0) {
final EditText passphrase = new EditText(PinEntryActivity.this);
passphrase.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
passphrase.setHint(R.string.passphrase);
AlertDialog.Builder dlg = new AlertDialog.Builder(PinEntryActivity.this).setTitle(R.string.app_name).setView(passphrase).setMessage(R.string.restore_wallet_from_backup).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
final String pw = passphrase.getText().toString();
if (pw == null || pw.length() < 1) {
Toast.makeText(PinEntryActivity.this, R.string.invalid_passphrase, Toast.LENGTH_SHORT).show();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
final String decrypted = PayloadUtil.getInstance(PinEntryActivity.this).getDecryptedBackupPayload(data, new CharSequenceX(pw));
if (decrypted == null || decrypted.length() < 1) {
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
progressBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
JSONObject json = new JSONObject(decrypted);
HD_Wallet hdw = PayloadUtil.getInstance(PinEntryActivity.this).restoreWalletfromJSON(json);
HD_WalletFactory.getInstance(PinEntryActivity.this).set(hdw);
String guid = AccessFactory.getInstance(PinEntryActivity.this).createGUID();
String hash = AccessFactory.getInstance(PinEntryActivity.this).getHash(guid, new CharSequenceX(AccessFactory.getInstance(PinEntryActivity.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
PayloadUtil.getInstance(PinEntryActivity.this).saveWalletToJSON(new CharSequenceX(guid + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecoderException de) {
de.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (JSONException je) {
je.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (java.lang.NullPointerException npe) {
npe.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecryptionException de) {
de.printStackTrace();
Toast.makeText(PinEntryActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} finally {
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
new AlertDialog.Builder(PinEntryActivity.this).setTitle(R.string.app_name).setMessage(getString(R.string.pin_reminder) + "\n\n" + AccessFactory.getInstance(PinEntryActivity.this).getPIN()).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
}).show();
}
Looper.loop();
}
}).start();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
});
if (!isFinishing()) {
dlg.show();
}
}
} else {
Intent intent = new Intent(PinEntryActivity.this, PinEntryActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
if (getIntent().getExtras() != null)
intent.putExtras(getIntent().getExtras());
startActivity(intent);
finish();
}
}
use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class PinEntryActivity method initThread.
private void initThread(final boolean create, final String pin, final String passphrase, final String seed) {
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
String guid = AccessFactory.getInstance(PinEntryActivity.this).createGUID();
String hash = AccessFactory.getInstance(PinEntryActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
if (create) {
try {
HD_WalletFactory.getInstance(PinEntryActivity.this).newWallet(12, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
} else if (seed == null) {
;
} else {
try {
HD_WalletFactory.getInstance(PinEntryActivity.this).restoreWallet(seed, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} catch (AddressFormatException afe) {
afe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (MnemonicException.MnemonicChecksumException mce) {
mce.printStackTrace();
} catch (MnemonicException.MnemonicWordException mwe) {
mwe.printStackTrace();
} finally {
;
}
}
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
try {
String msg = null;
if (HD_WalletFactory.getInstance(PinEntryActivity.this).get() != null) {
if (create) {
msg = getString(R.string.wallet_created_ok);
} else {
msg = getString(R.string.wallet_restored_ok);
}
try {
AccessFactory.getInstance(PinEntryActivity.this).setPIN(pin);
PayloadUtil.getInstance(PinEntryActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(PinEntryActivity.this).getGUID() + pin));
if (create) {
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
} else {
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
PrefsUtil.getInstance(PinEntryActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
}
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
;
}
for (int i = 0; i < 2; i++) {
AddressFactory.getInstance().account2xpub().put(i, HD_WalletFactory.getInstance(PinEntryActivity.this).get().getAccount(i).xpubstr());
AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(PinEntryActivity.this).get().getAccount(i).xpubstr(), i);
}
//
if (create) {
String seed = null;
try {
seed = HD_WalletFactory.getInstance(PinEntryActivity.this).get().getMnemonic();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
}
Intent intent = new Intent(PinEntryActivity.this, RecoveryWordsActivity.class);
intent.putExtra("BIP39_WORD_LIST", seed);
startActivity(intent);
finish();
} else {
AccessFactory.getInstance(PinEntryActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
} else {
if (create) {
msg = getString(R.string.wallet_created_ko);
} else {
msg = getString(R.string.wallet_restored_ko);
}
}
Toast.makeText(PinEntryActivity.this, msg, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
progressBar.setVisibility(View.INVISIBLE);
Looper.loop();
}
}).start();
}
use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class CreateWalletActivity method initThread.
/**
* Creates new wallet account
*
* @param create
* @param pin
* @param passphrase
* @param seed
*/
private void initThread(final boolean create, final String pin, final String passphrase, final String seed) {
toggleLoading();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
String guid = AccessFactory.getInstance(CreateWalletActivity.this).createGUID();
String hash = AccessFactory.getInstance(CreateWalletActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
if (create) {
try {
HD_WalletFactory.getInstance(CreateWalletActivity.this).newWallet(12, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
} else if (seed == null) {
;
} else {
try {
HD_WalletFactory.getInstance(CreateWalletActivity.this).restoreWallet(seed, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} catch (AddressFormatException afe) {
afe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (MnemonicException.MnemonicChecksumException mce) {
mce.printStackTrace();
} catch (MnemonicException.MnemonicWordException mwe) {
mwe.printStackTrace();
} finally {
;
}
}
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
try {
String msg = null;
if (HD_WalletFactory.getInstance(CreateWalletActivity.this).get() != null) {
if (create) {
msg = getString(R.string.wallet_created_ok);
} else {
msg = getString(R.string.wallet_restored_ok);
}
try {
AccessFactory.getInstance(CreateWalletActivity.this).setPIN(pin);
PayloadUtil.getInstance(CreateWalletActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(CreateWalletActivity.this).getGUID() + pin));
if (create) {
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
} else {
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
}
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
;
}
AddressFactory.getInstance().account2xpub().put(0, HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getAccount(0).xpubstr());
AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getAccount(0).xpubstr(), 0);
//
if (create) {
String seed = null;
try {
seed = HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getMnemonic();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
}
Intent intent = new Intent(CreateWalletActivity.this, RecoveryWordsActivity.class);
intent.putExtra("BIP39_WORD_LIST", seed);
startActivity(intent);
finish();
} else {
AccessFactory.getInstance(CreateWalletActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(CreateWalletActivity.this).restartApp();
}
} else {
if (create) {
msg = getString(R.string.wallet_created_ko);
} else {
msg = getString(R.string.wallet_restored_ko);
}
}
Toast.makeText(CreateWalletActivity.this, msg, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
toggleLoading();
Looper.loop();
}
}).start();
}
use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class APIFactory method initWalletAmounts.
private synchronized void initWalletAmounts() {
APIFactory.getInstance(context).reset();
List<String> addressStrings = new ArrayList<String>();
String[] s = null;
try {
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB44REG, false) == false) {
registerXPUB(HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr(), 44, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB49REG, false) == false) {
registerXPUB(BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr(), 49, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB84REG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr(), 84, null);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBPREREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPremixAccount()).xpubstr(), 84, PrefsUtil.XPUBPREREG);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBPOSTREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()).xpubstr(), 84, PrefsUtil.XPUBPOSTREG);
}
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUBBADBANKREG, false) == false) {
registerXPUB(BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolBadBank()).xpubstr(), 84, PrefsUtil.XPUBPOSTREG);
}
xpub_txs.put(HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr(), new ArrayList<Tx>());
addressStrings.addAll(Arrays.asList(BIP47Meta.getInstance().getIncomingAddresses(false)));
for (String _s : Arrays.asList(BIP47Meta.getInstance().getIncomingLookAhead(context))) {
if (!addressStrings.contains(_s)) {
addressStrings.add(_s);
}
}
for (String pcode : BIP47Meta.getInstance().getUnspentProviders()) {
for (String addr : BIP47Meta.getInstance().getUnspentAddresses(context, pcode)) {
if (!addressStrings.contains(addr)) {
addressStrings.add(addr);
}
}
List<Integer> idxs = BIP47Meta.getInstance().getUnspent(pcode);
for (Integer idx : idxs) {
String receivePubKey = BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), idx);
BIP47Meta.getInstance().getIdx4AddrLookup().put(receivePubKey, idx);
BIP47Meta.getInstance().getPCode4AddrLookup().put(receivePubKey, pcode.toString());
if (!addressStrings.contains(receivePubKey)) {
addressStrings.add(receivePubKey);
}
}
}
if (addressStrings.size() > 0) {
s = addressStrings.toArray(new String[0]);
// info("APIFactory", addressStrings.toString());
utxoObj0 = getUnspentOutputs(s);
}
debug("APIFactory", "addresses:" + addressStrings.toString());
HD_Wallet hdw = HD_WalletFactory.getInstance(context).get();
if (hdw != null && hdw.getXPUBs() != null) {
String[] all = null;
if (s != null && s.length > 0) {
all = new String[hdw.getXPUBs().length + 2 + s.length];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
all[1] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 2, hdw.getXPUBs().length);
System.arraycopy(s, 0, all, hdw.getXPUBs().length + 2, s.length);
} else {
all = new String[hdw.getXPUBs().length + 2];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
all[1] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 2, hdw.getXPUBs().length);
}
APIFactory.getInstance(context).getXPUB(all, true);
String[] xs = new String[3];
xs[0] = HD_WalletFactory.getInstance(context).get().getAccount(0).xpubstr();
xs[1] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
xs[2] = BIP84Util.getInstance(context).getWallet().getAccount(0).xpubstr();
utxoObj1 = getUnspentOutputs(xs);
getDynamicFees();
}
try {
List<JSONObject> utxoObjs = new ArrayList<JSONObject>();
if (utxoObj0 != null) {
utxoObjs.add(utxoObj0);
}
if (utxoObj1 != null) {
utxoObjs.add(utxoObj1);
}
PayloadUtil.getInstance(context).serializeUTXO(utxoObjs);
} catch (IOException | DecryptionException e) {
;
}
//
//
//
List<String> seenOutputs = new ArrayList<String>();
List<UTXO> _utxos = getUtxos(false);
for (UTXO _u : _utxos) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputs.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : BlockedUTXO.getInstance().getNotDustedUTXO()) {
// debug("APIFactory", "not dusted:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().removeNotDusted(_s);
// debug("APIFactory", "not dusted removed:" + _s);
}
}
for (String _s : BlockedUTXO.getInstance().getBlockedUTXO().keySet()) {
// debug("APIFactory", "blocked:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().remove(_s);
// debug("APIFactory", "blocked removed:" + _s);
}
}
String strPreMix = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPremixAccount()).xpubstr();
String strPostMix = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolPostmix()).xpubstr();
String strBadBank = BIP84Util.getInstance(context).getWallet().getAccountAt(WhirlpoolMeta.getInstance(context).getWhirlpoolBadBank()).xpubstr();
JSONObject preMultiAddrObj = getRawXPUB(new String[] { strPreMix });
JSONObject preUnspentObj = getRawUnspentOutputs(new String[] { strPreMix });
debug("APIFactory", "pre-mix multi:" + preMultiAddrObj.toString(2));
debug("APIFactory", "pre-mix unspent:" + preUnspentObj.toString());
boolean parsedPreMultiAddr = parseMixXPUB(preMultiAddrObj);
boolean parsedPreUnspent = parseMixUnspentOutputs(preUnspentObj.toString());
JSONObject postMultiAddrObj = getRawXPUB(new String[] { strPostMix });
JSONObject postUnspentObj = getRawUnspentOutputs(new String[] { strPostMix });
debug("APIFactory", "post-mix multi:" + postMultiAddrObj.toString());
debug("APIFactory", "post-mix unspent:" + postUnspentObj.toString());
boolean parsedPostMultiAddr = parseMixXPUB(postMultiAddrObj);
boolean parsedPostUnspent = parseMixUnspentOutputs(postUnspentObj.toString());
// debug("APIFactory", "post-mix multi:" + parsedPostMultiAddr);
// debug("APIFactory", "post-mix unspent:" + parsedPostUnspent);
// debug("APIFactory", "post-mix multi:" + getXpubPostMixBalance());
// debug("APIFactory", "post-mix unspent:" + getUtxosPostMix().size());
JSONObject badbankMultiAddrObj = getRawXPUB(new String[] { strBadBank });
JSONObject badbankUnspentObj = getRawUnspentOutputs(new String[] { strBadBank });
debug("APIFactory", "bad bank multi:" + badbankMultiAddrObj.toString());
debug("APIFactory", "bad bank unspent:" + badbankUnspentObj.toString());
boolean parsedBadBankMultiAddr = parseMixXPUB(badbankMultiAddrObj);
boolean parsedBadBanktUnspent = parseMixUnspentOutputs(badbankUnspentObj.toString());
//
//
//
List<String> seenOutputsPostMix = new ArrayList<String>();
List<UTXO> _utxosPostMix = getUtxosPostMix(false);
for (UTXO _u : _utxosPostMix) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputsPostMix.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : UTXOUtil.getInstance().getTags().keySet()) {
if (!seenOutputsPostMix.contains(_s) && !seenOutputs.contains(_s)) {
UTXOUtil.getInstance().remove(_s);
UTXOUtil.getInstance().removeNote(_s);
}
}
List<String> seenOutputsBadBank = new ArrayList<String>();
List<UTXO> _utxosBadBank = getUtxosBadBank(false);
for (UTXO _u : _utxosBadBank) {
for (MyTransactionOutPoint _o : _u.getOutpoints()) {
seenOutputsBadBank.add(_o.getTxHash().toString() + "-" + _o.getTxOutputN());
}
}
for (String _s : UTXOUtil.getInstance().getTags().keySet()) {
if (!seenOutputsBadBank.contains(_s) && !seenOutputs.contains(_s)) {
UTXOUtil.getInstance().remove(_s);
}
}
/*
for(String _s : BlockedUTXO.getInstance().getNotDustedUTXO()) {
// debug("APIFactory", "not dusted:" + _s);
if(!seenOutputsPostMix.contains(_s)) {
BlockedUTXO.getInstance().removeNotDusted(_s);
// debug("APIFactory", "not dusted removed:" + _s);
}
}
*/
for (String _s : BlockedUTXO.getInstance().getBlockedUTXOPostMix().keySet()) {
debug("APIFactory", "blocked post-mix:" + _s);
if (!seenOutputsPostMix.contains(_s)) {
BlockedUTXO.getInstance().removePostMix(_s);
debug("APIFactory", "blocked removed:" + _s);
}
}
// refresh Whirlpool utxos
Optional<WhirlpoolWallet> whirlpoolWalletOpt = AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet();
if (whirlpoolWalletOpt.isPresent()) {
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.DEPOSIT);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.PREMIX);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.POSTMIX);
whirlpoolWalletOpt.get().clearCache(WhirlpoolAccount.BADBANK);
}
} catch (IndexOutOfBoundsException ioobe) {
ioobe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
walletInit = true;
}
Aggregations