use of org.spongycastle.util.encoders.DecoderException in project samourai-wallet-android by Samourai-Wallet.
the class TxAnimUIActivity method handleResult.
private void handleResult(boolean isOK, RBFSpend rbf, String strTxHash, String hexTx, Transaction _tx) {
try {
if (isOK) {
if (PrefsUtil.getInstance(TxAnimUIActivity.this).getValue(PrefsUtil.USE_TRUSTED_NODE, false) == false) {
Toast.makeText(TxAnimUIActivity.this, R.string.tx_sent, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(TxAnimUIActivity.this, R.string.trusted_node_tx_sent, Toast.LENGTH_SHORT).show();
}
if (SendParams.getInstance().getChangeAmount() > 0L && SendParams.getInstance().getSpendType() == SendActivity.SPEND_SIMPLE) {
if (SendParams.getInstance().getAccount() != 0) {
BIP84Util.getInstance(TxAnimUIActivity.this).getWallet().getAccountAt(SendParams.getInstance().getAccount()).getChange().incAddrIdx();
AddressFactory.getInstance(TxAnimUIActivity.this).setHighestPostChangeIdx(SendParams.getInstance().getChangeIdx() + 1);
} else if (SendParams.getInstance().getChangeType() == 84) {
BIP84Util.getInstance(TxAnimUIActivity.this).getWallet().getAccount(0).getChange().incAddrIdx();
} else if (SendParams.getInstance().getChangeType() == 49) {
BIP49Util.getInstance(TxAnimUIActivity.this).getWallet().getAccount(0).getChange().incAddrIdx();
} else {
try {
HD_WalletFactory.getInstance(TxAnimUIActivity.this).get().getAccount(0).getChange().incAddrIdx();
} catch (IOException ioe) {
;
} catch (MnemonicException.MnemonicLengthException mle) {
;
}
}
}
if (PrefsUtil.getInstance(TxAnimUIActivity.this).getValue(PrefsUtil.RBF_OPT_IN, false) == true) {
for (TransactionOutput out : _tx.getOutputs()) {
try {
if (Bech32Util.getInstance().isBech32Script(Hex.toHexString(out.getScriptBytes())) && !SendParams.getInstance().getDestAddress().equals(Bech32Util.getInstance().getAddressFromScript(Hex.toHexString(out.getScriptBytes())))) {
rbf.addChangeAddr(Bech32Util.getInstance().getAddressFromScript(Hex.toHexString(out.getScriptBytes())));
Log.d("SendActivity", "added change output:" + Bech32Util.getInstance().getAddressFromScript(Hex.toHexString(out.getScriptBytes())));
} else if (SendParams.getInstance().getChangeType() == 44 && !SendParams.getInstance().getDestAddress().equals(out.getAddressFromP2PKHScript(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString())) {
rbf.addChangeAddr(out.getAddressFromP2PKHScript(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
Log.d("SendActivity", "added change output:" + out.getAddressFromP2PKHScript(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
} else if (SendParams.getInstance().getChangeType() != 44 && !SendParams.getInstance().getDestAddress().equals(out.getAddressFromP2SH(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString())) {
rbf.addChangeAddr(out.getAddressFromP2SH(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
Log.d("SendActivity", "added change output:" + out.getAddressFromP2SH(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
} else {
;
}
} catch (NullPointerException npe) {
;
} catch (Exception e) {
;
}
}
rbf.setHash(strTxHash);
rbf.setSerializedTx(hexTx);
RBFUtil.getInstance().add(rbf);
}
// increment counter if BIP47 spend
if (SendParams.getInstance().getPCode() != null && SendParams.getInstance().getPCode().length() > 0) {
BIP47Meta.getInstance().getPCode4AddrLookup().put(SendParams.getInstance().getDestAddress(), SendParams.getInstance().getPCode());
BIP47Meta.getInstance().incOutgoingIdx(SendParams.getInstance().getPCode());
SentToFromBIP47Util.getInstance().add(SendParams.getInstance().getPCode(), strTxHash);
SimpleDateFormat sd = new SimpleDateFormat("dd MMM");
String strTS = sd.format(System.currentTimeMillis());
String event = strTS + " " + TxAnimUIActivity.this.getString(R.string.sent) + " " + MonetaryUtil.getInstance().getBTCFormat().format((double) SendParams.getInstance().getSpendAmount() / 1e8) + " BTC";
BIP47Meta.getInstance().setLatestEvent(SendParams.getInstance().getPCode(), event);
} else if (SendParams.getInstance().getBatchSend() != null) {
for (BatchSendUtil.BatchSend d : SendParams.getInstance().getBatchSend()) {
String address = d.addr;
String pcode = d.pcode;
// increment counter if BIP47 spend
if (pcode != null && pcode.length() > 0) {
BIP47Meta.getInstance().getPCode4AddrLookup().put(address, pcode);
BIP47Meta.getInstance().incOutgoingIdx(pcode);
SentToFromBIP47Util.getInstance().add(pcode, strTxHash);
SimpleDateFormat sd = new SimpleDateFormat("dd MMM");
String strTS = sd.format(System.currentTimeMillis());
String event = strTS + " " + TxAnimUIActivity.this.getString(R.string.sent) + " " + MonetaryUtil.getInstance().getBTCFormat().format((double) d.amount / 1e8) + " BTC";
BIP47Meta.getInstance().setLatestEvent(pcode, event);
}
}
} else {
;
}
if (SendParams.getInstance().hasPrivacyWarning() && SendParams.getInstance().hasPrivacyChecked()) {
SendAddressUtil.getInstance().add(SendParams.getInstance().getDestAddress(), false);
} else if (SendAddressUtil.getInstance().get(SendParams.getInstance().getDestAddress()) == 0) {
SendAddressUtil.getInstance().add(SendParams.getInstance().getDestAddress(), false);
} else {
SendAddressUtil.getInstance().add(SendParams.getInstance().getDestAddress(), true);
}
if (SendParams.getInstance().getChangeAmount() == 0L) {
Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
intent.putExtra("notifTx", false);
intent.putExtra("fetch", true);
LocalBroadcastManager.getInstance(TxAnimUIActivity.this).sendBroadcast(intent);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent _intent = new Intent(TxAnimUIActivity.this, BalanceActivity.class);
_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (SendParams.getInstance().getAccount() != 0) {
_intent.putExtra("_account", SendParams.getInstance().getAccount());
}
startActivity(_intent);
}
}, 1000L);
} else {
Toast.makeText(TxAnimUIActivity.this, R.string.tx_failed, Toast.LENGTH_SHORT).show();
// reset change index upon tx fail
if (SendParams.getInstance().getAccount() != 0) {
BIP84Util.getInstance(TxAnimUIActivity.this).getWallet().getAccountAt(SendParams.getInstance().getAccount()).getChange().setAddrIdx(SendParams.getInstance().getChangeIdx());
AddressFactory.getInstance(TxAnimUIActivity.this).setHighestPostChangeIdx(SendParams.getInstance().getChangeIdx());
} else if (SendParams.getInstance().getChangeType() == 84) {
BIP84Util.getInstance(TxAnimUIActivity.this).getWallet().getAccount(0).getChange().setAddrIdx(SendParams.getInstance().getChangeIdx());
} else if (SendParams.getInstance().getChangeType() == 49) {
BIP49Util.getInstance(TxAnimUIActivity.this).getWallet().getAccount(0).getChange().setAddrIdx(SendParams.getInstance().getChangeIdx());
} else {
HD_WalletFactory.getInstance(TxAnimUIActivity.this).get().getAccount(0).getChange().setAddrIdx(SendParams.getInstance().getChangeIdx());
}
}
} catch (MnemonicException.MnemonicLengthException mle) {
Toast.makeText(TxAnimUIActivity.this, "pushTx:" + mle.getMessage(), Toast.LENGTH_SHORT).show();
} catch (DecoderException de) {
Toast.makeText(TxAnimUIActivity.this, "pushTx:" + de.getMessage(), Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
Toast.makeText(TxAnimUIActivity.this, "pushTx:" + ioe.getMessage(), Toast.LENGTH_SHORT).show();
} finally {
;
}
}
Aggregations