Browse Source

Fix insanity of CWalletDB::WriteTx and CWalletTx::WriteToDisk

0.13
Patrick Strateman 9 years ago
parent
commit
0fd599767d
  1. 14
      src/wallet/wallet.cpp
  2. 2
      src/wallet/wallet.h
  3. 10
      src/wallet/walletdb.cpp
  4. 2
      src/wallet/walletdb.h

14
src/wallet/wallet.cpp

@ -729,7 +729,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD @@ -729,7 +729,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletD
// Write to disk
if (fInsertedNew || fUpdated)
if (!wtx.WriteToDisk(pwalletdb))
if (!pwalletdb->WriteTx(wtx))
return false;
// Break debit/credit balance caches:
@ -829,7 +829,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx) @@ -829,7 +829,7 @@ bool CWallet::AbandonTransaction(const uint256& hashTx)
wtx.nIndex = -1;
wtx.setAbandoned();
wtx.MarkDirty();
wtx.WriteToDisk(&walletdb);
walletdb.WriteTx(wtx);
NotifyTransactionChanged(this, wtx.GetHash(), CT_UPDATED);
// Iterate over all its outputs, and mark transactions in the wallet that spend them abandoned too
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(hashTx, 0));
@ -891,7 +891,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx) @@ -891,7 +891,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
wtx.nIndex = -1;
wtx.hashBlock = hashBlock;
wtx.MarkDirty();
wtx.WriteToDisk(&walletdb);
walletdb.WriteTx(wtx);
// Iterate over all its outputs, and mark transactions in the wallet that spend them conflicted too
TxSpends::const_iterator iter = mapTxSpends.lower_bound(COutPoint(now, 0));
while (iter != mapTxSpends.end() && iter->first.hash == now) {
@ -1186,12 +1186,6 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived, @@ -1186,12 +1186,6 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived,
}
}
bool CWalletTx::WriteToDisk(CWalletDB *pwalletdb)
{
return pwalletdb->WriteTx(GetHash(), *this);
}
/**
* Scan the block chain (starting in pindexStart) for transactions
* from or to us. If fUpdate is true, found transactions that already
@ -3194,7 +3188,7 @@ bool CWallet::InitLoadWallet() @@ -3194,7 +3188,7 @@ bool CWallet::InitLoadWallet()
copyTo->fFromMe = copyFrom->fFromMe;
copyTo->strFromAccount = copyFrom->strFromAccount;
copyTo->nOrderPos = copyFrom->nOrderPos;
copyTo->WriteToDisk(&walletdb);
walletdb.WriteTx(*copyTo);
}
}
}

2
src/wallet/wallet.h

@ -394,8 +394,6 @@ public: @@ -394,8 +394,6 @@ public:
bool InMempool() const;
bool IsTrusted() const;
bool WriteToDisk(CWalletDB *pwalletdb);
int64_t GetTxTime() const;
int GetRequestCount() const;

10
src/wallet/walletdb.cpp

@ -55,10 +55,10 @@ bool CWalletDB::ErasePurpose(const string& strPurpose) @@ -55,10 +55,10 @@ bool CWalletDB::ErasePurpose(const string& strPurpose)
return Erase(make_pair(string("purpose"), strPurpose));
}
bool CWalletDB::WriteTx(uint256 hash, const CWalletTx& wtx)
bool CWalletDB::WriteTx(const CWalletTx& wtx)
{
nWalletDBUpdated++;
return Write(std::make_pair(std::string("tx"), hash), wtx);
return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx);
}
bool CWalletDB::EraseTx(uint256 hash)
@ -291,7 +291,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet) @@ -291,7 +291,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
if (pwtx)
{
if (!WriteTx(pwtx->GetHash(), *pwtx))
if (!WriteTx(*pwtx))
return DB_LOAD_FAIL;
}
else
@ -315,7 +315,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet) @@ -315,7 +315,7 @@ DBErrors CWalletDB::ReorderTransactions(CWallet* pwallet)
// Since we're changing the order, write it back
if (pwtx)
{
if (!WriteTx(pwtx->GetHash(), *pwtx))
if (!WriteTx(*pwtx))
return DB_LOAD_FAIL;
}
else
@ -698,7 +698,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) @@ -698,7 +698,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
pwallet->nTimeFirstKey = 1; // 0 would be considered 'no value'
BOOST_FOREACH(uint256 hash, wss.vWalletUpgrade)
WriteTx(hash, pwallet->mapWallet[hash]);
WriteTx(pwallet->mapWallet[hash]);
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
if (wss.fIsEncrypted && (wss.nFileVersion == 40000 || wss.nFileVersion == 50000))

2
src/wallet/walletdb.h

@ -87,7 +87,7 @@ public: @@ -87,7 +87,7 @@ public:
bool WritePurpose(const std::string& strAddress, const std::string& purpose);
bool ErasePurpose(const std::string& strAddress);
bool WriteTx(uint256 hash, const CWalletTx& wtx);
bool WriteTx(const CWalletTx& wtx);
bool EraseTx(uint256 hash);
bool WriteKey(const CPubKey& vchPubKey, const CPrivKey& vchPrivKey, const CKeyMetadata &keyMeta);

Loading…
Cancel
Save