use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletDialogFragment method restorePrivateKeysFromBase58.
private void restorePrivateKeysFromBase58(final File file) {
try (final FileInputStream is = new FileInputStream(file)) {
restoreWallet(WalletUtils.restorePrivateKeysFromBase58(is, Constants.NETWORK_PARAMETERS));
log.info("successfully restored unencrypted private keys: {}", file);
} catch (final IOException x) {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
dialog.setPositiveButton(R.string.button_dismiss, null);
dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
show(activity.getSupportFragmentManager());
}
});
dialog.show();
log.info("problem restoring private keys: " + file, x);
}
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletDialogFragment method restoreWalletFromProtobuf.
private void restoreWalletFromProtobuf(final File file) {
try (final FileInputStream is = new FileInputStream(file)) {
restoreWallet(WalletUtils.restoreWalletFromProtobuf(is, Constants.NETWORK_PARAMETERS));
log.info("successfully restored unencrypted wallet: {}", file);
} catch (final IOException x) {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
dialog.setPositiveButton(R.string.button_dismiss, null);
dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
show(activity.getSupportFragmentManager());
}
});
dialog.show();
log.info("problem restoring unencrypted wallet: " + file, x);
}
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletDialogFragment method restoreWalletFromEncrypted.
private void restoreWalletFromEncrypted(final File file, final String password) {
try {
final BufferedReader cipherIn = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
final StringBuilder cipherText = new StringBuilder();
Io.copy(cipherIn, cipherText, Constants.BACKUP_MAX_CHARS);
cipherIn.close();
final byte[] plainText = Crypto.decryptBytes(cipherText.toString(), password.toCharArray());
final InputStream is = new ByteArrayInputStream(plainText);
restoreWallet(WalletUtils.restoreWalletFromProtobufOrBase58(is, Constants.NETWORK_PARAMETERS));
log.info("successfully restored encrypted wallet: {}", file);
} catch (final IOException x) {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
dialog.setPositiveButton(R.string.button_dismiss, null);
dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
show(activity.getSupportFragmentManager());
}
});
dialog.show();
log.info("problem restoring wallet: " + file, x);
}
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletDialogFragment method restoreWallet.
private void restoreWallet(final Wallet wallet) throws IOException {
application.replaceWallet(wallet);
config.disarmBackupReminder();
final DialogBuilder dialog = new DialogBuilder(activity);
final StringBuilder message = new StringBuilder();
message.append(getString(R.string.restore_wallet_dialog_success));
message.append("\n\n");
message.append(getString(R.string.restore_wallet_dialog_success_replay));
if (wallet.isEncrypted()) {
message.append("\n\n");
message.append(getString(R.string.restore_wallet_dialog_success_encrypted));
}
dialog.setMessage(message);
dialog.setNeutralButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
BlockchainService.resetBlockchain(activity);
activity.finish();
}
});
dialog.show();
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletFromExternalDialogFragment method handleRestore.
private void handleRestore(final String password) {
try {
final InputStream is = contentResolver.openInputStream(backupUri);
restoreWalletFromEncrypted(is, password);
config.disarmBackupReminder();
log.info("successfully restored encrypted wallet from external source");
final DialogBuilder dialog = new DialogBuilder(activity);
final StringBuilder message = new StringBuilder();
message.append(getString(R.string.restore_wallet_dialog_success));
message.append("\n\n");
message.append(getString(R.string.restore_wallet_dialog_success_replay));
if (application.getWallet().isEncrypted()) {
message.append("\n\n");
message.append(getString(R.string.restore_wallet_dialog_success_encrypted));
}
dialog.setMessage(message);
dialog.setNeutralButton(R.string.button_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
BlockchainService.resetBlockchain(activity);
activity.finish();
}
});
dialog.show();
} catch (final IOException x) {
log.info("problem restoring wallet", x);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
dialog.setPositiveButton(R.string.button_dismiss, finishListener).setOnCancelListener(finishListener);
dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int id) {
show(activity.getSupportFragmentManager(), backupUri);
}
});
dialog.show();
}
}
Aggregations