Skip to content

Commit d8cc80a

Browse files
committed
Remove CWalletDB* parameter from CWallet::AddToWallet
Coming from btc@867f842f1e5a385aeb2093f802d6f37a84d0fe5d
1 parent 4074208 commit d8cc80a

File tree

7 files changed

+18
-25
lines changed

7 files changed

+18
-25
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24382438
CWalletTx wtx(pwalletMain, tx);
24392439
wtx.nTimeReceived = pindex->GetBlockTime();
24402440
wtx.SetMerkleBranch(block);
2441-
pwalletMain->AddToWallet(wtx, nullptr);
2441+
pwalletMain->AddToWallet(wtx);
24422442
setAddedTx.insert(pSpend.second);
24432443
}
24442444
}

src/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: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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()) {

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
435435

436436
bool GetLabelDestination(CTxDestination& dest, const std::string& label, bool bForceNew = false);
437437
void MarkDirty();
438-
bool AddToWallet(const CWalletTx& wtxIn, CWalletDB* pwalletdb = nullptr);
438+
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose = true);
439439
bool LoadToWallet(const CWalletTx& wtxIn);
440440
void SyncTransaction(const CTransaction& tx, const CBlock* pblock);
441441
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate);

src/wallet/wallet_zerocoin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void CWallet::doZPivRescan(const CBlockIndex* pindex, const CBlock& block,
101101
if (fCheckZPIV && consensus.NetworkUpgradeActive(pindex->nHeight, Consensus::UPGRADE_ZC)) {
102102
std::list<CZerocoinMint> listMints;
103103
BlockToZerocoinMintList(block, listMints, true);
104-
CWalletDB walletdb(strWalletFile);
105104

106105
for (auto& m : listMints) {
107106
if (IsMyMint(m.GetValue())) {
@@ -117,7 +116,7 @@ void CWallet::doZPivRescan(const CBlockIndex* pindex, const CBlock& block,
117116
CWalletTx wtx(this, tx);
118117
wtx.nTimeReceived = block.GetBlockTime();
119118
wtx.SetMerkleBranch(block);
120-
AddToWallet(wtx, &walletdb);
119+
AddToWallet(wtx);
121120
setAddedToWallet.insert(txid);
122121
}
123122
}
@@ -137,7 +136,7 @@ void CWallet::doZPivRescan(const CBlockIndex* pindex, const CBlock& block,
137136
wtx.SetMerkleBranch(blockSpend);
138137

139138
wtx.nTimeReceived = pindexSpend->nTime;
140-
AddToWallet(wtx, &walletdb);
139+
AddToWallet(wtx);
141140
setAddedToWallet.emplace(txidSpend);
142141
}
143142
}

src/zpiv/zpivwallet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ void CzPIVWallet::SyncWithChain(bool fGenerateMintPool)
183183
{
184184
uint32_t nLastCountUsed = 0;
185185
bool found = true;
186-
CWalletDB walletdb(wallet->strWalletFile);
187186

188187
std::set<uint256> setAddedTx;
189188
while (found) {
@@ -267,7 +266,7 @@ void CzPIVWallet::SyncWithChain(bool fGenerateMintPool)
267266

268267
//Fill out wtx so that a transaction record can be created
269268
wtx.nTimeReceived = pindex->GetBlockTime();
270-
wallet->AddToWallet(wtx, &walletdb);
269+
wallet->AddToWallet(wtx);
271270
setAddedTx.insert(txHash);
272271
}
273272

@@ -323,8 +322,7 @@ bool CzPIVWallet::SetMintSeen(const CBigNum& bnValue, const int& nHeight, const
323322
wtx.SetMerkleBranch(block);
324323

325324
wtx.nTimeReceived = pindex->nTime;
326-
CWalletDB walletdb(wallet->strWalletFile);
327-
wallet->AddToWallet(wtx, &walletdb);
325+
wallet->AddToWallet(wtx);
328326
}
329327

330328
// Add to zpivTracker which also adds to database

src/zpivchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ bool UpdateZPIVSupplyConnect(const CBlock& block, CBlockIndex* pindex, bool fJus
443443
CWalletTx wtx(pwalletMain, tx);
444444
wtx.nTimeReceived = block.GetBlockTime();
445445
wtx.SetMerkleBranch(block);
446-
pwalletMain->AddToWallet(wtx, nullptr);
446+
pwalletMain->AddToWallet(wtx);
447447
setAddedToWallet.insert(txid);
448448
}
449449
}

0 commit comments

Comments
 (0)