use of org.bitcoinj.wallet.UnreadableWalletException in project bitcoin-wallet by bitcoin-wallet.
the class WalletApplication method loadWalletFromProtobuf.
private void loadWalletFromProtobuf() {
if (walletFile.exists()) {
try (final FileInputStream walletStream = new FileInputStream(walletFile)) {
final Stopwatch watch = Stopwatch.createStarted();
wallet = new WalletProtobufSerializer().readWallet(walletStream);
watch.stop();
if (!wallet.getParams().equals(Constants.NETWORK_PARAMETERS))
throw new UnreadableWalletException("bad wallet network parameters: " + wallet.getParams().getId());
log.info("wallet loaded from: '{}', took {}", walletFile, watch);
} catch (final IOException | UnreadableWalletException x) {
log.error("problem loading wallet", x);
Toast.makeText(WalletApplication.this, x.getClass().getName(), Toast.LENGTH_LONG).show();
wallet = restoreWalletFromBackup();
}
if (!wallet.isConsistent()) {
Toast.makeText(this, "inconsistent wallet: " + walletFile, Toast.LENGTH_LONG).show();
wallet = restoreWalletFromBackup();
}
if (!wallet.getParams().equals(Constants.NETWORK_PARAMETERS))
throw new Error("bad wallet network parameters: " + wallet.getParams().getId());
} else {
final Stopwatch watch = Stopwatch.createStarted();
wallet = new Wallet(Constants.NETWORK_PARAMETERS);
saveWallet();
backupWallet();
watch.stop();
log.info("fresh wallet created, took {}", watch);
config.armBackupReminder();
}
}
use of org.bitcoinj.wallet.UnreadableWalletException in project bitcoin-wallet by bitcoin-wallet.
the class WalletApplication method restoreWalletFromBackup.
private Wallet restoreWalletFromBackup() {
try (final InputStream is = openFileInput(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF)) {
final Wallet wallet = new WalletProtobufSerializer().readWallet(is, true, null);
if (!wallet.isConsistent())
throw new Error("inconsistent backup");
BlockchainService.resetBlockchain(this);
Toast.makeText(this, R.string.toast_wallet_reset, Toast.LENGTH_LONG).show();
log.info("wallet restored from backup: '" + Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + "'");
return wallet;
} catch (final IOException | UnreadableWalletException x) {
throw new Error("cannot read backup", x);
}
}
use of org.bitcoinj.wallet.UnreadableWalletException in project toshi-android-client by toshiapp.
the class HDWallet method initFromMasterSeed.
private Wallet initFromMasterSeed(final String masterSeed) {
try {
final DeterministicSeed seed = getSeed(masterSeed);
seed.check();
return constructFromSeed(seed);
} catch (final UnreadableWalletException | MnemonicException e) {
LogUtil.exception("Error while initiating from from master seed", e);
throw new RuntimeException("Unable to create wallet. Seed is invalid");
}
}
use of org.bitcoinj.wallet.UnreadableWalletException in project toshi-android-client by toshiapp.
the class HDWallet method createFromMasterSeed.
public Single<HDWallet> createFromMasterSeed(final String masterSeed) {
return Single.fromCallable(() -> {
try {
final DeterministicSeed seed = getSeed(masterSeed);
seed.check();
final Wallet wallet = constructFromSeed(seed);
deriveKeysFromWallet(wallet);
saveMasterSeedToStorage(masterSeed);
return this;
} catch (final UnreadableWalletException | MnemonicException e) {
LogUtil.exception("Error while creating wallet from master seed", e);
throw new InvalidMasterSeedException(e);
}
});
}
use of org.bitcoinj.wallet.UnreadableWalletException in project cryptoputty by alokmenghrajani.
the class CryptoputtyApplication method initialize.
@Override
public void initialize(final Bootstrap<CryptoputtyConfiguration> bootstrap) {
bootstrap.addBundle(new ViewBundle<>());
NetworkParameters params = TestNet3Params.get();
File tempDir = Files.createTempDir();
tempDir.deleteOnExit();
kit = new WalletAppKit(params, tempDir, "cryptoputty");
try {
kit.restoreWalletFromSeed(new DeterministicSeed("office suit release flame robust know depth truly swim bird quality reopen", null, "", 1522261414L));
kit.setBlockingStartup(false);
kit.setAutoSave(true);
kit.startAsync();
kit.awaitRunning();
// Perhaps having bloom filters doesn't hurt since we don't plan to do anything
// kit.peerGroup().setBloomFilteringEnabled(false);
// I have no idea what I'm doing, but let's increase these max values.
kit.peerGroup().setMaxPeersToDiscoverCount(10000);
kit.peerGroup().setMaxConnections(5000);
log.info(format("send money to: %s", kit.wallet().freshReceiveAddress().toString()));
log.info("done initializing");
} catch (UnreadableWalletException e) {
e.printStackTrace();
}
}
Aggregations