@@ -814,18 +814,20 @@ void CWallet::MarkDirty()
814814 }
815815}
816816
817- bool CWallet::AddToWallet (const CWalletTx& wtxIn, CWalletDB* pwalletdb )
817+ bool CWallet::AddToWallet (const CWalletTx& wtxIn, bool fFlushOnClose )
818818{
819- uint256 hash = wtxIn.GetHash ();
820819 LOCK (cs_wallet);
820+ CWalletDB walletdb (strWalletFile, " r+" , fFlushOnClose );
821+ uint256 hash = wtxIn.GetHash ();
822+
821823 // Inserts only if not already there, returns tx inserted or tx found
822824 std::pair<std::map<uint256, CWalletTx>::iterator, bool > ret = mapWallet.insert (std::make_pair (hash, wtxIn));
823825 CWalletTx& wtx = (*ret.first ).second ;
824826 wtx.BindWallet (this );
825827 bool fInsertedNew = ret.second ;
826828 if (fInsertedNew ) {
827829 wtx.nTimeReceived = GetAdjustedTime ();
828- wtx.nOrderPos = IncOrderPosNext (pwalletdb );
830+ wtx.nOrderPos = IncOrderPosNext (&walletdb );
829831 wtxOrdered.insert (std::make_pair (wtx.nOrderPos , TxPair (&wtx, (CAccountingEntry*)0 )));
830832 wtx.UpdateTimeSmart ();
831833 AddToSpends (hash);
@@ -860,11 +862,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
860862
861863 // Write to disk
862864 if (fInsertedNew || fUpdated ) {
863- if (!pwalletdb) {
864- CWalletDB (strWalletFile).WriteTx (wtx);
865- } else if (!pwalletdb->WriteTx (wtx)) {
865+ if (!walletdb.WriteTx (wtx))
866866 return false ;
867- }
868867 }
869868
870869 // Break debit/credit balance caches:
@@ -944,11 +943,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
944943 // Get merkle branch if transaction was found in a block
945944 if (pblock)
946945 wtx.SetMerkleBranch (*pblock);
947- // Do not flush the wallet here for performance reasons
948- // this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism
949- CWalletDB walletdb (strWalletFile, " r+" , false );
950946
951- return AddToWallet (wtx, &walletdb );
947+ return AddToWallet (wtx, false );
952948 }
953949 }
954950 return false ;
@@ -2961,7 +2957,7 @@ CWallet::CommitResult CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey&
29612957
29622958 // Add tx to wallet, because if it has change it's also ours,
29632959 // otherwise just for transaction history.
2964- AddToWallet (wtxNew, pwalletdb );
2960+ AddToWallet (wtxNew);
29652961
29662962 // Notify that old coins are spent
29672963 if (!wtxNew.HasZerocoinSpendInputs ()) {
0 commit comments