Skip to content

Commit 867f842

Browse files
committed
Remove CWalletDB* parameter from CWallet::AddToWallet
1 parent 00f09c9 commit 867f842

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ UniValue importprunedfunds(const UniValue& params, bool fHelp)
309309
LOCK2(cs_main, pwalletMain->cs_wallet);
310310

311311
if (pwalletMain->IsMine(tx)) {
312-
CWalletDB walletdb(pwalletMain->strWalletFile, "r+", false);
313-
pwalletMain->AddToWallet(wtx, &walletdb);
312+
pwalletMain->AddToWallet(wtx, false);
314313
return NullUniValue;
315314
}
316315

src/wallet/test/accounting_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
4848
pwalletMain->AddAccountingEntry(ae, walletdb);
4949

5050
wtx.mapValue["comment"] = "z";
51-
pwalletMain->AddToWallet(wtx, &walletdb);
51+
pwalletMain->AddToWallet(wtx);
5252
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
5353
vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
5454
vpwtx[0]->nOrderPos = -1;
@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
9090
--tx.nLockTime; // Just to change the hash :)
9191
*static_cast<CTransaction*>(&wtx) = CTransaction(tx);
9292
}
93-
pwalletMain->AddToWallet(wtx, &walletdb);
93+
pwalletMain->AddToWallet(wtx);
9494
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
9595
vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
9696

@@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
100100
--tx.nLockTime; // Just to change the hash :)
101101
*static_cast<CTransaction*>(&wtx) = CTransaction(tx);
102102
}
103-
pwalletMain->AddToWallet(wtx, &walletdb);
103+
pwalletMain->AddToWallet(wtx);
104104
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
105105
vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
106106
vpwtx[2]->nOrderPos = -1;

src/wallet/wallet.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,14 @@ void CWallet::MarkDirty()
741741
}
742742
}
743743

744-
bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
744+
bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
745745
{
746+
LOCK(cs_wallet);
747+
748+
CWalletDB walletdb(strWalletFile, "r+", fFlushOnClose);
749+
746750
uint256 hash = wtxIn.GetHash();
747751

748-
LOCK(cs_wallet);
749752
// Inserts only if not already there, returns tx inserted or tx found
750753
pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
751754
CWalletTx& wtx = (*ret.first).second;
@@ -754,7 +757,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
754757
if (fInsertedNew)
755758
{
756759
wtx.nTimeReceived = GetAdjustedTime();
757-
wtx.nOrderPos = IncOrderPosNext(pwalletdb);
760+
wtx.nOrderPos = IncOrderPosNext(&walletdb);
758761
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0)));
759762

760763
wtx.nTimeSmart = wtx.nTimeReceived;
@@ -836,7 +839,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
836839

837840
// Write to disk
838841
if (fInsertedNew || fUpdated)
839-
if (!pwalletdb->WriteTx(wtx))
842+
if (!walletdb.WriteTx(wtx))
840843
return false;
841844

842845
// Break debit/credit balance caches:
@@ -911,11 +914,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
911914
if (pblock)
912915
wtx.SetMerkleBranch(*pblock);
913916

914-
// Do not flush the wallet here for performance reasons
915-
// this is safe, as in case of a crash, we rescan the necessary blocks on startup through our SetBestChain-mechanism
916-
CWalletDB walletdb(strWalletFile, "r+", false);
917-
918-
return AddToWallet(wtx, &walletdb);
917+
return AddToWallet(wtx, false);
919918
}
920919
}
921920
return false;
@@ -2458,7 +2457,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
24582457

24592458
// Add tx to wallet, because if it has change it's also ours,
24602459
// otherwise just for transaction history.
2461-
AddToWallet(wtxNew, pwalletdb);
2460+
AddToWallet(wtxNew);
24622461

24632462
// Notify that old coins are spent
24642463
set<CWalletTx*> setCoins;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
729729
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
730730

731731
void MarkDirty();
732-
bool AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb);
732+
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
733733
bool LoadToWallet(const CWalletTx& wtxIn);
734734
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
735735
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);

0 commit comments

Comments
 (0)