public void rescanBlockchain(long rescanTime) { mLogger.info(String.format("RESCANNING from %d", rescanTime)); // Make sure we are in a good state for this. if (mState != State.READY) { mLogger.warn("can't rescan until the wallet is ready"); return; } switch (mSyncState) { case SYNCHRONIZED: mSyncState = SyncState.RESCAN; break; default: mSyncState = SyncState.RERESCAN; break; } // Remove our wallet event listener. mKit.wallet().removeEventListener(mWalletListener); // Persist and remove our HDWallet. // // NOTE - It's best not to clear the balances here. When the // transactions are filling in on the transactions screen it's // disturbing to see negative historical balances. They'll // get completely refigured when the sync is done anyway ... // mHDWallet.persist(mApp); mHDWallet = null; mLogger.info("resetting wallet state"); mKit.wallet().clearTransactions(0); mKit.wallet().setLastBlockSeenHeight(-1); // magic value mKit.wallet().setLastBlockSeenHash(null); mLogger.info("shutting kit down"); try { mKit.shutDown(); mKit = null; } catch (Exception ex) { mLogger.error("kit shutdown failed: " + ex.toString()); return; } File dir = mApp.getWalletDir(); String spvpath = mApp.getWalletPrefix() + ".spvchain"; mLogger.info("removing spvchain file " + dir + spvpath); File chainFile = new File(dir, spvpath); if (!chainFile.delete()) mLogger.error("delete of spvchain file failed"); mLogger.info("restarting wallet"); mKeyCrypter = mApp.mKeyCrypter; mAesKey = mApp.mAesKey; setState(State.SETUP); mTask = new SetupWalletTask(); mTask.execute(rescanTime); }
public void changePasscode(KeyParameter oldAesKey, KeyCrypter keyCrypter, KeyParameter aesKey) { mLogger.info("changePasscode starting"); // Change the parameters on our HDWallet. mHDWallet.setPersistCrypter(keyCrypter, aesKey); mHDWallet.persist(mApp); mLogger.info("persisted HD wallet"); // Decrypt the wallet with the old key. mKit.wallet().decrypt(oldAesKey); mLogger.info("decrypted base wallet"); // Encrypt the wallet using the new key. mKit.wallet().encrypt(keyCrypter, aesKey); mLogger.info("reencrypted base wallet"); }
@Override public void onWalletChanged(Wallet wallet) { // Compute balances and transaction counts. Iterable<WalletTransaction> iwt = mKit.wallet().getWalletTransactions(); mHDWallet.applyAllTransactions(iwt); // Check to make sure we have sufficient margins. int maxExtended = mHDWallet.ensureMargins(mKit.wallet()); // Persist the new state. mHDWallet.persist(mApp); Intent intent = new Intent("wallet-state-changed"); mLBM.sendBroadcast(intent); if (maxExtended > HDChain.maxSafeExtend()) { mLogger.info(String.format("%d addresses added, rescanning", maxExtended)); rescanBlockchain(HDAddress.EPOCH); } }
public void addAccount() { mLogger.info("add account"); // Make sure we are in a good state for this. if (mState != State.READY) { mLogger.warn("can't add an account until the wallet is ready"); return; } mHDWallet.addAccount(); mHDWallet.ensureMargins(mKit.wallet()); // Set the new keys creation time to now. long now = Utils.now().getTime() / 1000; // Adding all the keys is overkill, but it is simpler for now. ArrayList<ECKey> keys = new ArrayList<ECKey>(); mHDWallet.gatherAllKeys(now, keys); mLogger.info(String.format("adding %d keys", keys.size())); mKit.wallet().addKeys(keys); mHDWallet.persist(mApp); }
public void persist() { mHDWallet.persist(mApp); }