@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); }