use of com.samourai.sentinel.hd.HD_Wallet in project sentinel-android by Samourai-Wallet.
the class BalanceActivity method restoreWatchOnly.
private void restoreWatchOnly() {
final List<String> xpubList = SamouraiSentinel.getInstance(BalanceActivity.this).getAllAddrsSorted();
final Handler handler = new Handler();
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
progress = new ProgressDialog(BalanceActivity.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();
List<String> _xpubs = new ArrayList<String>();
for (String xpub : xpubList) {
if (xpub.startsWith("xpub") || xpub.startsWith("ypub")) {
_xpubs.add(xpub);
}
}
if (_xpubs.size() > 0) {
try {
String xpubs = StringUtils.join(_xpubs.toArray(new String[_xpubs.size()]), ":");
// Log.i("BalanceActivity", xpubs);
if (_xpubs.size() > 0) {
HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).restoreWallet(xpubs, null, 1);
if (hdw != null) {
List<HD_Account> accounts = hdw.getAccounts();
for (int i = 0; i < accounts.size(); i++) {
AddressFactory.getInstance().account2xpub().put(i, _xpubs.get(i));
AddressFactory.getInstance().xpub2account().put(_xpubs.get(i), i);
}
}
}
} catch (DecoderException de) {
PrefsUtil.getInstance(BalanceActivity.this).clear();
Toast.makeText(BalanceActivity.this, R.string.xpub_error, Toast.LENGTH_SHORT).show();
de.printStackTrace();
} catch (AddressFormatException afe) {
PrefsUtil.getInstance(BalanceActivity.this).clear();
Toast.makeText(BalanceActivity.this, R.string.xpub_error, Toast.LENGTH_SHORT).show();
afe.printStackTrace();
} finally {
;
}
}
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
handler.post(new Runnable() {
@Override
public void run() {
if (xpubList.size() == 1) {
account_selections = new String[1];
if (xpubList.get(0).startsWith("xpub") && SamouraiSentinel.getInstance(BalanceActivity.this).getXPUBs().containsKey(xpubList.get(0))) {
account_selections[0] = SamouraiSentinel.getInstance(BalanceActivity.this).getXPUBs().get(xpubList.get(0));
} else if ((xpubList.get(0).startsWith("xpub") || xpubList.get(0).startsWith("ypub")) && SamouraiSentinel.getInstance(BalanceActivity.this).getBIP49().containsKey(xpubList.get(0))) {
account_selections[0] = SamouraiSentinel.getInstance(BalanceActivity.this).getBIP49().get(xpubList.get(0));
} else {
account_selections[0] = SamouraiSentinel.getInstance(BalanceActivity.this).getLegacy().get(xpubList.get(0));
}
} else {
account_selections = new String[xpubList.size() + 1];
account_selections[0] = BalanceActivity.this.getString(R.string.total_title);
for (int i = 0; i < xpubList.size(); i++) {
if (xpubList.get(i).startsWith("xpub") && SamouraiSentinel.getInstance(BalanceActivity.this).getXPUBs().containsKey(xpubList.get(i))) {
account_selections[i + 1] = SamouraiSentinel.getInstance(BalanceActivity.this).getXPUBs().get(xpubList.get(i));
} else if ((xpubList.get(i).startsWith("xpub") || xpubList.get(i).startsWith("ypub")) && SamouraiSentinel.getInstance(BalanceActivity.this).getBIP49().containsKey(xpubList.get(i))) {
account_selections[i + 1] = SamouraiSentinel.getInstance(BalanceActivity.this).getBIP49().get(xpubList.get(i));
} else {
account_selections[i + 1] = SamouraiSentinel.getInstance(BalanceActivity.this).getLegacy().get(xpubList.get(i));
}
}
}
adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_dropdown_item, account_selections);
getActionBar().setListNavigationCallbacks(adapter, navigationListener);
adapter.notifyDataSetChanged();
if (account_selections.length == 1) {
SamouraiSentinel.getInstance(BalanceActivity.this).setCurrentSelectedAccount(0);
}
refreshTx(false);
try {
SamouraiSentinel.getInstance(BalanceActivity.this).serialize(SamouraiSentinel.getInstance(BalanceActivity.this).toJSON(), null);
} catch (IOException ioe) {
;
} catch (JSONException je) {
;
}
}
});
Looper.loop();
}
}).start();
}
use of com.samourai.sentinel.hd.HD_Wallet in project sentinel-android by Samourai-Wallet.
the class BalanceActivity method refreshTx.
public void refreshTx(final boolean dragged) {
final Handler handler = new Handler();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
int idx = SamouraiSentinel.getInstance(BalanceActivity.this).getCurrentSelectedAccount();
List<String> _xpubs = SamouraiSentinel.getInstance(BalanceActivity.this).getAllAddrsSorted();
if (idx == 0) {
APIFactory.getInstance(BalanceActivity.this).getXPUB(_xpubs.toArray(new String[_xpubs.size()]));
} else {
APIFactory.getInstance(BalanceActivity.this).getXPUB(new String[] { _xpubs.get(idx - 1) });
}
if (idx == 0) {
txs = APIFactory.getInstance(BalanceActivity.this).getAllXpubTxs();
} else {
txs = APIFactory.getInstance(BalanceActivity.this).getXpubTxs().get(_xpubs.get(idx - 1));
}
try {
if (HD_WalletFactory.getInstance(BalanceActivity.this).get() != null) {
HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).get();
for (int i = 0; i < hdw.getAccounts().size(); i++) {
HD_WalletFactory.getInstance(BalanceActivity.this).get().getAccount(i).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestTxReceiveIdx(i));
}
}
} catch (IOException ioe) {
;
} catch (MnemonicException.MnemonicLengthException mle) {
;
}
PrefsUtil.getInstance(BalanceActivity.this).setValue(PrefsUtil.FIRST_RUN, false);
handler.post(new Runnable() {
public void run() {
if (dragged) {
swipeRefreshLayout.setRefreshing(false);
}
txAdapter.notifyDataSetChanged();
displayBalance();
}
});
Looper.loop();
}
}).start();
}
Aggregations