Remove CWalletDB* parameter from CWallet::AddToWallet

This commit is contained in:
Patrick Strateman 2016-06-07 21:41:03 -07:00
parent 00f09c920c
commit 867f842f1e
4 changed files with 14 additions and 16 deletions

View file

@ -309,8 +309,7 @@ UniValue importprunedfunds(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
if (pwalletMain->IsMine(tx)) { if (pwalletMain->IsMine(tx)) {
CWalletDB walletdb(pwalletMain->strWalletFile, "r+", false); pwalletMain->AddToWallet(wtx, false);
pwalletMain->AddToWallet(wtx, &walletdb);
return NullUniValue; return NullUniValue;
} }

View file

@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
pwalletMain->AddAccountingEntry(ae, walletdb); pwalletMain->AddAccountingEntry(ae, walletdb);
wtx.mapValue["comment"] = "z"; wtx.mapValue["comment"] = "z";
pwalletMain->AddToWallet(wtx, &walletdb); pwalletMain->AddToWallet(wtx);
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
vpwtx[0]->nTimeReceived = (unsigned int)1333333335; vpwtx[0]->nTimeReceived = (unsigned int)1333333335;
vpwtx[0]->nOrderPos = -1; vpwtx[0]->nOrderPos = -1;
@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
--tx.nLockTime; // Just to change the hash :) --tx.nLockTime; // Just to change the hash :)
*static_cast<CTransaction*>(&wtx) = CTransaction(tx); *static_cast<CTransaction*>(&wtx) = CTransaction(tx);
} }
pwalletMain->AddToWallet(wtx, &walletdb); pwalletMain->AddToWallet(wtx);
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
vpwtx[1]->nTimeReceived = (unsigned int)1333333336; vpwtx[1]->nTimeReceived = (unsigned int)1333333336;
@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
--tx.nLockTime; // Just to change the hash :) --tx.nLockTime; // Just to change the hash :)
*static_cast<CTransaction*>(&wtx) = CTransaction(tx); *static_cast<CTransaction*>(&wtx) = CTransaction(tx);
} }
pwalletMain->AddToWallet(wtx, &walletdb); pwalletMain->AddToWallet(wtx);
vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]); vpwtx.push_back(&pwalletMain->mapWallet[wtx.GetHash()]);
vpwtx[2]->nTimeReceived = (unsigned int)1333333329; vpwtx[2]->nTimeReceived = (unsigned int)1333333329;
vpwtx[2]->nOrderPos = -1; vpwtx[2]->nOrderPos = -1;

View file

@ -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(); uint256 hash = wtxIn.GetHash();
LOCK(cs_wallet);
// Inserts only if not already there, returns tx inserted or tx found // 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)); pair<map<uint256, CWalletTx>::iterator, bool> ret = mapWallet.insert(make_pair(hash, wtxIn));
CWalletTx& wtx = (*ret.first).second; CWalletTx& wtx = (*ret.first).second;
@ -754,7 +757,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
if (fInsertedNew) if (fInsertedNew)
{ {
wtx.nTimeReceived = GetAdjustedTime(); wtx.nTimeReceived = GetAdjustedTime();
wtx.nOrderPos = IncOrderPosNext(pwalletdb); wtx.nOrderPos = IncOrderPosNext(&walletdb);
wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0))); wtxOrdered.insert(make_pair(wtx.nOrderPos, TxPair(&wtx, (CAccountingEntry*)0)));
wtx.nTimeSmart = wtx.nTimeReceived; wtx.nTimeSmart = wtx.nTimeReceived;
@ -836,7 +839,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb)
// Write to disk // Write to disk
if (fInsertedNew || fUpdated) if (fInsertedNew || fUpdated)
if (!pwalletdb->WriteTx(wtx)) if (!walletdb.WriteTx(wtx))
return false; return false;
// Break debit/credit balance caches: // Break debit/credit balance caches:
@ -911,11 +914,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
if (pblock) if (pblock)
wtx.SetMerkleBranch(*pblock); wtx.SetMerkleBranch(*pblock);
// Do not flush the wallet here for performance reasons return AddToWallet(wtx, false);
// 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 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, // Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history. // otherwise just for transaction history.
AddToWallet(wtxNew, pwalletdb); AddToWallet(wtxNew);
// Notify that old coins are spent // Notify that old coins are spent
set<CWalletTx*> setCoins; set<CWalletTx*> setCoins;

View file

@ -729,7 +729,7 @@ public:
bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false); bool GetAccountPubkey(CPubKey &pubKey, std::string strAccount, bool bForceNew = false);
void MarkDirty(); void MarkDirty();
bool AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb); bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose=true);
bool LoadToWallet(const CWalletTx& wtxIn); bool LoadToWallet(const CWalletTx& wtxIn);
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock); void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, const CBlock* pblock);
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);