Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
bool CWalletDB::ErasePurpose(const std::string &strPurpose) { | bool CWalletDB::ErasePurpose(const std::string &strPurpose) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Erase(std::make_pair(std::string("purpose"), strPurpose)); | return Erase(std::make_pair(std::string("purpose"), strPurpose)); | ||||
} | } | ||||
bool CWalletDB::WriteTx(const CWalletTx &wtx) { | bool CWalletDB::WriteTx(const CWalletTx &wtx) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Write(std::make_pair(std::string("tx"), wtx.GetId()), wtx); | return Write(std::make_pair(std::string("tx"), wtx.GetHash()), wtx); | ||||
} | } | ||||
bool CWalletDB::EraseTx(uint256 hash) { | bool CWalletDB::EraseTx(TxHash hash) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
return Erase(std::make_pair(std::string("tx"), hash)); | return Erase(std::make_pair(std::string("tx"), hash)); | ||||
} | } | ||||
bool CWalletDB::WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, | bool CWalletDB::WriteKey(const CPubKey &vchPubKey, const CPrivKey &vchPrivKey, | ||||
const CKeyMetadata &keyMeta) { | const CKeyMetadata &keyMeta) { | ||||
nWalletDBUpdateCounter++; | nWalletDBUpdateCounter++; | ||||
▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | try { | ||||
uint256 hash; | uint256 hash; | ||||
ssKey >> hash; | ssKey >> hash; | ||||
CWalletTx wtx; | CWalletTx wtx; | ||||
ssValue >> wtx; | ssValue >> wtx; | ||||
CValidationState state; | CValidationState state; | ||||
bool isValid = wtx.IsCoinBase() | bool isValid = wtx.IsCoinBase() | ||||
? CheckCoinbase(wtx, state) | ? CheckCoinbase(wtx, state) | ||||
: CheckRegularTransaction(wtx, state); | : CheckRegularTransaction(wtx, state); | ||||
if (wtx.GetId() != hash || !isValid) return false; | if (wtx.GetHash() != hash || !isValid) return false; | ||||
// Undo serialize changes in 31600 | // Undo serialize changes in 31600 | ||||
if (31404 <= wtx.fTimeReceivedIsTxTime && | if (31404 <= wtx.fTimeReceivedIsTxTime && | ||||
wtx.fTimeReceivedIsTxTime <= 31703) { | wtx.fTimeReceivedIsTxTime <= 31703) { | ||||
if (!ssValue.empty()) { | if (!ssValue.empty()) { | ||||
char fTmp; | char fTmp; | ||||
char fUnused; | char fUnused; | ||||
ssValue >> fTmp >> fUnused >> wtx.strFromAccount; | ssValue >> fTmp >> fUnused >> wtx.strFromAccount; | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | DBErrors CWalletDB::LoadWallet(CWallet *pwallet) { | ||||
for (CAccountingEntry &entry : pwallet->laccentries) { | for (CAccountingEntry &entry : pwallet->laccentries) { | ||||
pwallet->wtxOrdered.insert(std::make_pair( | pwallet->wtxOrdered.insert(std::make_pair( | ||||
entry.nOrderPos, CWallet::TxPair((CWalletTx *)0, &entry))); | entry.nOrderPos, CWallet::TxPair((CWalletTx *)0, &entry))); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
DBErrors CWalletDB::FindWalletTx(CWallet *pwallet, | DBErrors CWalletDB::FindWalletTx(CWallet *pwallet, std::vector<TxHash> &vTxHash, | ||||
std::vector<uint256> &vTxHash, | |||||
std::vector<CWalletTx> &vWtx) { | std::vector<CWalletTx> &vWtx) { | ||||
pwallet->vchDefaultKey = CPubKey(); | pwallet->vchDefaultKey = CPubKey(); | ||||
bool fNoncriticalErrors = false; | bool fNoncriticalErrors = false; | ||||
DBErrors result = DB_LOAD_OK; | DBErrors result = DB_LOAD_OK; | ||||
try { | try { | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
int nMinVersion = 0; | int nMinVersion = 0; | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | DBErrors CWalletDB::FindWalletTx(CWallet *pwallet, std::vector<TxHash> &vTxHash, | ||||
if (fNoncriticalErrors && result == DB_LOAD_OK) | if (fNoncriticalErrors && result == DB_LOAD_OK) | ||||
result = DB_NONCRITICAL_ERROR; | result = DB_NONCRITICAL_ERROR; | ||||
return result; | return result; | ||||
} | } | ||||
DBErrors CWalletDB::ZapSelectTx(CWallet *pwallet, | DBErrors CWalletDB::ZapSelectTx(CWallet *pwallet, | ||||
std::vector<uint256> &vTxHashIn, | std::vector<TxHash> &vTxHashIn, | ||||
std::vector<uint256> &vTxHashOut) { | std::vector<TxHash> &vTxHashOut) { | ||||
// Build list of wallet TXs and hashes. | // Build list of wallet TXs and hashes. | ||||
std::vector<uint256> vTxHash; | std::vector<TxHash> vTxHash; | ||||
std::vector<CWalletTx> vWtx; | std::vector<CWalletTx> vWtx; | ||||
DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); | DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); | ||||
if (err != DB_LOAD_OK) { | if (err != DB_LOAD_OK) { | ||||
return err; | return err; | ||||
} | } | ||||
std::sort(vTxHash.begin(), vTxHash.end()); | std::sort(vTxHash.begin(), vTxHash.end()); | ||||
std::sort(vTxHashIn.begin(), vTxHashIn.end()); | std::sort(vTxHashIn.begin(), vTxHashIn.end()); | ||||
// Erase each matching wallet TX. | // Erase each matching wallet TX. | ||||
bool delerror = false; | bool delerror = false; | ||||
std::vector<uint256>::iterator it = vTxHashIn.begin(); | std::vector<TxHash>::iterator it = vTxHashIn.begin(); | ||||
for (uint256 hash : vTxHash) { | for (TxHash hash : vTxHash) { | ||||
while (it < vTxHashIn.end() && (*it) < hash) { | while (it < vTxHashIn.end() && (*it) < hash) { | ||||
it++; | it++; | ||||
} | } | ||||
if (it == vTxHashIn.end()) { | if (it == vTxHashIn.end()) { | ||||
break; | break; | ||||
} else if ((*it) == hash) { | } else if ((*it) == hash) { | ||||
pwallet->mapWallet.erase(hash); | pwallet->mapWallet.erase(hash); | ||||
if (!EraseTx(hash)) { | if (!EraseTx(hash)) { | ||||
Show All 10 Lines | if (delerror) { | ||||
return DB_CORRUPT; | return DB_CORRUPT; | ||||
} | } | ||||
return DB_LOAD_OK; | return DB_LOAD_OK; | ||||
} | } | ||||
DBErrors CWalletDB::ZapWalletTx(CWallet *pwallet, | DBErrors CWalletDB::ZapWalletTx(CWallet *pwallet, | ||||
std::vector<CWalletTx> &vWtx) { | std::vector<CWalletTx> &vWtx) { | ||||
// Build list of wallet TXs. | // Build list of wallet TXs. | ||||
std::vector<uint256> vTxHash; | std::vector<TxHash> vTxHash; | ||||
DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); | DBErrors err = FindWalletTx(pwallet, vTxHash, vWtx); | ||||
if (err != DB_LOAD_OK) return err; | if (err != DB_LOAD_OK) return err; | ||||
// Erase each wallet TX. | // Erase each wallet TX. | ||||
for (uint256 &hash : vTxHash) { | for (TxHash &hash : vTxHash) { | ||||
if (!EraseTx(hash)) return DB_CORRUPT; | if (!EraseTx(hash)) return DB_CORRUPT; | ||||
} | } | ||||
return DB_LOAD_OK; | return DB_LOAD_OK; | ||||
} | } | ||||
void ThreadFlushWalletDB() { | void ThreadFlushWalletDB() { | ||||
// Make this thread recognisable as the wallet flushing thread. | // Make this thread recognisable as the wallet flushing thread. | ||||
▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines |