diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index a2aaec09..ff39e971 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -421,9 +421,18 @@ WalletDB.prototype.batch = function batch(wallet) { */ WalletDB.prototype.commit = co(function* commit(wallet) { - var batch = wallet.current; + var batch = this.batch(wallet); + + try { + yield batch.write(); + } catch (e) { + wallet.current = null; + wallet.accountCache.drop(); + wallet.pathCache.drop(); + throw e; + } + wallet.current = null; - yield batch.write(); wallet.accountCache.commit(); wallet.pathCache.commit(); });