aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-06-07 21:41:03 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2016-07-29 17:04:14 -0700
commit867f842f1e5a385aeb2093f802d6f37a84d0fe5d (patch)
tree11f1d708106754f15a7d6f5c03bb61df3c714b07 /src/wallet/wallet.cpp
parent00f09c920c2e8906d2260251be6d1d2fa1bbb29d (diff)
downloadbitcoin-867f842f1e5a385aeb2093f802d6f37a84d0fe5d.tar.xz
Remove CWalletDB* parameter from CWallet::AddToWallet
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 68ce26eaa8..63a3baea04 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -741,11 +741,14 @@ void CWallet::MarkDirty()
}
}
-bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
+bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
{
+ LOCK(cs_wallet);
+
+ CWalletDB walletdb(strWalletFile, "r+", fFlushOnClose);
+
uint256 hash = wtxIn.GetHash();
- LOCK(cs_wallet);
// Inserts only if not already there, returns tx inserted or tx found
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
CWalletTx& wtx = (*ret.first).second;
@@ -754,7 +757,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
if (fInsertedNew)
{
wtx.nTimeReceived = GetAdjustedTime();
- wtx.nOrderPos = IncOrderPosNext(pwalletdb);
+ wtx.nOrderPos = IncOrderPosNext(&walletdb);
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0)));
wtx.nTimeSmart = wtx.nTimeReceived;
@@ -836,7 +839,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
// Write to disk
if (fInsertedNew || fUpdated)
- if (!pwalletdb->WriteTx(wtx))
+ if (!walletdb.WriteTx(wtx))
return false;
// Break debit/credit balance caches:
@@ -911,11 +914,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
if (pblock)
wtx.SetMerkleBranch(*pblock);
- // Do not flush the wallet here for performance reasons
- // this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism
- CWalletDB walletdb(strWalletFile, "r+", false);
-
- return AddToWallet(wtx, &walletdb);
+ return AddToWallet(wtx, false);
}
}
return false;
@@ -2458,7 +2457,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
// Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history.
- AddToWallet(wtxNew, pwalletdb);
+ AddToWallet(wtxNew);
// Notify that old coins are spent
set<CWalletTx*> setCoins;