Skip to content

Commit 373b50d

Browse files
committed
Merge bitcoin#8028: Fix insanity of CWalletDB::WriteTx and CWalletTx::WriteToDisk
0fd5997 Fix insanity of CWalletDB::WriteTx and CWalletTx::WriteToDisk (Patrick Strateman)
2 parents 41138f9 + 0fd5997 commit 373b50d

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

src/wallet/wallet.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
730730

731731
// Write to disk
732732
if (fInsertedNew || fUpdated)
733-
if (!wtx.WriteToDisk(pwalletdb))
733+
if (!pwalletdb->WriteTx(wtx))
734734
return false;
735735

736736
// Break debit/credit balance caches:
@@ -830,7 +830,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
830830
wtx.nIndex = -1;
831831
wtx.setAbandoned();
832832
wtx.MarkDirty();
833-
wtx.WriteToDisk(&walletdb);
833+
walletdb.WriteTx(wtx);
834834
NotifyTransactionChanged(this, wtx.GetHash(), CT_UPDATED);
835835
// Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too
836836
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(hashTx, 0));
@@ -892,7 +892,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
892892
wtx.nIndex = -1;
893893
wtx.hashBlock = hashBlock;
894894
wtx.MarkDirty();
895-
wtx.WriteToDisk(&walletdb);
895+
walletdb.WriteTx(wtx);
896896
// Iterate over all its outputs, and mark transactions in the wallet that spend them conflicted too
897897
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(now, 0));
898898
while (iter != mapTxSpends.end() && iter->first.hash == now) {
@@ -1187,12 +1187,6 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived,
11871187
}
11881188
}
11891189

1190-
1191-
bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
1192-
{
1193-
return pwalletdb->WriteTx(GetHash(), *this);
1194-
}
1195-
11961190
/**
11971191
* Scan the block chain (starting in pindexStart) for transactions
11981192
* from or to us. If fUpdate is true, found transactions that already
@@ -3195,7 +3189,7 @@ bool CWallet::InitLoadWallet()
31953189
copyTo->fFromMe = copyFrom->fFromMe;
31963190
copyTo->strFromAccount = copyFrom->strFromAccount;
31973191
copyTo->nOrderPos = copyFrom->nOrderPos;
3198-
copyTo->WriteToDisk(&walletdb);
3192+
walletdb.WriteTx(*copyTo);
31993193
}
32003194
}
32013195
}

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ class CWalletTx : public CMerkleTx
394394
bool InMempool() const;
395395
bool IsTrusted() const;
396396

397-
bool WriteToDisk(CWalletDB *pwalletdb);
398-
399397
int64_t GetTxTime() const;
400398
int GetRequestCount() const;
401399

src/wallet/walletdb.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ bool CWalletDB::ErasePurpose(const string& strPurpose)
5555
return Erase(make_pair(string("purpose"), strPurpose));
5656
}
5757

58-
bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
58+
bool CWalletDB::WriteTx(const CWalletTx& wtx)
5959
{
6060
nWalletDBUpdated++;
61-
return Write(std::make_pair(std::string("tx"), hash), wtx);
61+
return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx);
6262
}
6363

6464
bool CWalletDB::EraseTx(uint256 hash)
@@ -291,7 +291,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
291291

292292
if (pwtx)
293293
{
294-
if (!WriteTx(pwtx->GetHash(), *pwtx))
294+
if (!WriteTx(*pwtx))
295295
return DB_LOAD_FAIL;
296296
}
297297
else
@@ -315,7 +315,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
315315
// Since we're changing the order, write it back
316316
if (pwtx)
317317
{
318-
if (!WriteTx(pwtx->GetHash(), *pwtx))
318+
if (!WriteTx(*pwtx))
319319
return DB_LOAD_FAIL;
320320
}
321321
else
@@ -698,7 +698,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
698698
pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
699699

700700
BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
701-
WriteTx(hash, pwallet->mapWallet[hash]);
701+
WriteTx(pwallet->mapWallet[hash]);
702702

703703
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
704704
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))

src/wallet/walletdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CWalletDB : public CDB
8787
bool WritePurpose(const std::string& strAddress, const std::string& purpose);
8888
bool ErasePurpose(const std::string& strAddress);
8989

90-
bool WriteTx(uint256 hash, const CWalletTx& wtx);
90+
bool WriteTx(const CWalletTx& wtx);
9191
bool EraseTx(uint256 hash);
9292

9393
bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);

0 commit comments

Comments
 (0)