use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method onCreate.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balance);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (SamouraiWallet.getInstance().isTestNet()) {
setTitle(getText(R.string.app_name) + ":" + "TestNet");
}
LayoutInflater inflator = BalanceActivity.this.getLayoutInflater();
tvBalanceBar = (LinearLayout) inflator.inflate(R.layout.balance_layout, null);
tvBalanceBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (isBTC) {
isBTC = false;
} else {
isBTC = true;
}
displayBalance();
txAdapter.notifyDataSetChanged();
return false;
}
});
tvBalanceAmount = (TextView) tvBalanceBar.findViewById(R.id.BalanceAmount);
tvBalanceUnits = (TextView) tvBalanceBar.findViewById(R.id.BalanceUnits);
ibQuickSend = (FloatingActionsMenu) findViewById(R.id.wallet_menu);
actionSend = (FloatingActionButton) findViewById(R.id.send);
actionSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("via_menu", true);
startActivity(intent);
}
});
actionReceive = (FloatingActionButton) findViewById(R.id.receive);
actionReceive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).get();
if (hdw != null) {
Intent intent = new Intent(BalanceActivity.this, ReceiveActivity.class);
startActivity(intent);
}
} catch (IOException | MnemonicException.MnemonicLengthException e) {
;
}
}
});
actionBIP47 = (FloatingActionButton) findViewById(R.id.bip47);
actionBIP47.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(BalanceActivity.this, com.samourai.wallet.bip47.BIP47Activity.class);
startActivity(intent);
}
});
txs = new ArrayList<Tx>();
txStates = new HashMap<String, Boolean>();
txList = (ListView) findViewById(R.id.txList);
txAdapter = new TransactionAdapter();
txList.setAdapter(txAdapter);
txList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
if (position == 0) {
return;
}
long viewId = view.getId();
View v = (View) view.getParent();
final Tx tx = txs.get(position - 1);
ImageView ivTxStatus = (ImageView) v.findViewById(R.id.TransactionStatus);
TextView tvConfirmationCount = (TextView) v.findViewById(R.id.ConfirmationCount);
if (viewId == R.id.ConfirmationCount || viewId == R.id.TransactionStatus) {
if (txStates.containsKey(tx.getHash()) && txStates.get(tx.getHash()) == true) {
txStates.put(tx.getHash(), false);
displayTxStatus(false, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
} else {
txStates.put(tx.getHash(), true);
displayTxStatus(true, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
}
} else {
String message = getString(R.string.options_unconfirmed_tx);
// RBF
if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0 && RBFUtil.getInstance().contains(tx.getHash())) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (rbfTask == null || rbfTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
rbfTask = new RBFTask();
rbfTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else // CPFP receive
if (tx.getConfirmations() < 1 && tx.getAmount() >= 0.0) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
cpfpTask = new CPFPTask();
cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else // CPFP spend
if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
cpfpTask = new CPFPTask();
cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
doExplorerView(tx.getHash());
return;
}
}
}
});
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().post(new Runnable() {
@Override
public void run() {
refreshTx(false, true, true, false);
}
});
}
});
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
IntentFilter filter = new IntentFilter(ACTION_INTENT);
LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiver, filter);
// TorUtil.getInstance(BalanceActivity.this).setStatusFromBroadcast(false);
registerReceiver(torStatusReceiver, new IntentFilter(OrbotHelper.ACTION_STATUS));
boolean notifTx = false;
boolean fetch = false;
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("notifTx")) {
notifTx = extras.getBoolean("notifTx");
}
if (extras != null && extras.containsKey("uri")) {
fetch = extras.getBoolean("fetch");
}
refreshTx(notifTx, fetch, false, true);
if (PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_CLAIMED, false) == false && PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_REFUSED, false) == false) {
doClaimPayNym();
}
if (!AppUtil.getInstance(BalanceActivity.this).isClipboardSeen()) {
doClipboardCheck();
}
}
use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.
the class AddressFactory method getBIP49.
public SegwitAddress getBIP49(int accountIdx, int chain, int idx) {
HD_Address addr = null;
SegwitAddress p2shp2wpkh = null;
HD_Wallet hdw = BIP49Util.getInstance(context).getWallet();
addr = hdw.getAccount(accountIdx).getChain(chain).getAddressAt(idx);
p2shp2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
return p2shp2wpkh;
}
use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.
the class AppUtil method wipeApp.
public void wipeApp() {
try {
HD_Wallet hdw = HD_WalletFactory.getInstance(context).get();
String[] s = hdw.getXPUBs();
for (int i = 0; i < s.length; i++) {
APIFactory.getInstance(context).deleteXPUB(s[i], false);
}
String _s = BIP49Util.getInstance(context).getWallet().getAccount(0).ypubstr();
APIFactory.getInstance(context).deleteXPUB(_s, true);
PayloadUtil.getInstance(context).wipe();
} catch (Exception e) {
e.printStackTrace();
}
deleteBackup();
deleteQR();
final ComponentName component = new ComponentName(context.getApplicationContext().getPackageName(), "com.samourai.wallet.MainActivity");
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
PrefsUtil.getInstance(context).setValue(PrefsUtil.ICON_HIDDEN, false);
APIFactory.getInstance(context).setXpubBalance(0L);
APIFactory.getInstance(context).reset();
PrefsUtil.getInstance(context).clear();
BlockedUTXO.getInstance().clear();
AccessFactory.getInstance(context).setIsLoggedIn(false);
}
use of com.samourai.wallet.hd.HD_Wallet 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(), false);
}
*/
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.XPUB49REG, false) == false) {
registerXPUB(BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr(), true);
}
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);
}
}
}
if (addressStrings.size() > 0) {
s = addressStrings.toArray(new String[0]);
// Log.i("APIFactory", addressStrings.toString());
getUnspentOutputs(s);
}
Log.d("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 + 1 + s.length];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 1, hdw.getXPUBs().length);
System.arraycopy(s, 0, all, hdw.getXPUBs().length + 1, s.length);
} else {
all = new String[hdw.getXPUBs().length + 1];
all[0] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
System.arraycopy(hdw.getXPUBs(), 0, all, 1, 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] = HD_WalletFactory.getInstance(context).get().getAccount(1).xpubstr();
xs[2] = BIP49Util.getInstance(context).getWallet().getAccount(0).xpubstr();
getUnspentOutputs(xs);
getDynamicFees();
}
//
//
//
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()) {
Log.d("APIFactory", "not dusted:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().removeNotDusted(_s);
Log.d("APIFactory", "not dusted removed:" + _s);
}
}
for (String _s : BlockedUTXO.getInstance().getBlockedUTXO().keySet()) {
Log.d("APIFactory", "blocked:" + _s);
if (!seenOutputs.contains(_s)) {
BlockedUTXO.getInstance().remove(_s);
Log.d("APIFactory", "blocked removed:" + _s);
}
}
} catch (IndexOutOfBoundsException ioobe) {
ioobe.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.samourai.wallet.hd.HD_Wallet 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();
}
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();
}
progress = new ProgressDialog(PinEntryActivity.this);
progress.setCancelable(false);
progress.setTitle(R.string.app_name);
progress.setMessage(getString(R.string.please_wait));
progress.show();
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 {
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
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();
}
}).show();
}
Looper.loop();
}
}).start();
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
AppUtil.getInstance(PinEntryActivity.this).restartApp();
}
});
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);
startActivity(intent);
}
}
Aggregations