Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
unsigned int nKeys{0}; | unsigned int nKeys{0}; | ||||
unsigned int nCKeys{0}; | unsigned int nCKeys{0}; | ||||
unsigned int nWatchKeys{0}; | unsigned int nWatchKeys{0}; | ||||
unsigned int nKeyMeta{0}; | unsigned int nKeyMeta{0}; | ||||
unsigned int m_unknown_records{0}; | unsigned int m_unknown_records{0}; | ||||
bool fIsEncrypted{false}; | bool fIsEncrypted{false}; | ||||
bool fAnyUnordered{false}; | bool fAnyUnordered{false}; | ||||
int nFileVersion{0}; | |||||
std::vector<TxId> vWalletUpgrade; | std::vector<TxId> vWalletUpgrade; | ||||
CWalletScanState() {} | CWalletScanState() {} | ||||
}; | }; | ||||
static bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, | static bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, | ||||
CDataStream &ssValue, CWalletScanState &wss, | CDataStream &ssValue, CWalletScanState &wss, | ||||
std::string &strType, std::string &strErr) | std::string &strType, std::string &strErr) | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | try { | ||||
} | } | ||||
} else if (strType == "pool") { | } else if (strType == "pool") { | ||||
int64_t nIndex; | int64_t nIndex; | ||||
ssKey >> nIndex; | ssKey >> nIndex; | ||||
CKeyPool keypool; | CKeyPool keypool; | ||||
ssValue >> keypool; | ssValue >> keypool; | ||||
pwallet->LoadKeyPool(nIndex, keypool); | pwallet->LoadKeyPool(nIndex, keypool); | ||||
} else if (strType == "version") { | |||||
ssValue >> wss.nFileVersion; | |||||
if (wss.nFileVersion == 10300) { | |||||
wss.nFileVersion = 300; | |||||
} | |||||
} else if (strType == "cscript") { | } else if (strType == "cscript") { | ||||
uint160 hash; | uint160 hash; | ||||
ssKey >> hash; | ssKey >> hash; | ||||
CScript script; | CScript script; | ||||
ssValue >> script; | ssValue >> script; | ||||
if (!pwallet->LoadCScript(script)) { | if (!pwallet->LoadCScript(script)) { | ||||
strErr = "Error reading wallet database: LoadCScript failed"; | strErr = "Error reading wallet database: LoadCScript failed"; | ||||
return false; | return false; | ||||
Show All 16 Lines | try { | ||||
uint64_t flags; | uint64_t flags; | ||||
ssValue >> flags; | ssValue >> flags; | ||||
if (!pwallet->SetWalletFlags(flags, true)) { | if (!pwallet->SetWalletFlags(flags, true)) { | ||||
strErr = "Error reading wallet database: Unknown non-tolerable " | strErr = "Error reading wallet database: Unknown non-tolerable " | ||||
"wallet flags found"; | "wallet flags found"; | ||||
return false; | return false; | ||||
} | } | ||||
} else if (strType != "bestblock" && strType != "bestblock_nomerkle" && | } else if (strType != "bestblock" && strType != "bestblock_nomerkle" && | ||||
strType != "minversion" && strType != "acentry") { | strType != "minversion" && strType != "acentry" && | ||||
strType != "version") { | |||||
wss.m_unknown_records++; | wss.m_unknown_records++; | ||||
} | } | ||||
} catch (...) { | } catch (...) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | DBErrors WalletBatch::LoadWallet(CWallet *pwallet) { | ||||
} | } | ||||
// Any wallet corruption at all: skip any rewriting or upgrading, we don't | // Any wallet corruption at all: skip any rewriting or upgrading, we don't | ||||
// want to make it worse. | // want to make it worse. | ||||
if (result != DBErrors::LOAD_OK) { | if (result != DBErrors::LOAD_OK) { | ||||
return result; | return result; | ||||
} | } | ||||
pwallet->WalletLogPrintf("nFileVersion = %d\n", wss.nFileVersion); | // Last client version to open this wallet, was previously the file version | ||||
// number | |||||
int last_client = CLIENT_VERSION; | |||||
ReadVersion(last_client); | |||||
pwallet->WalletLogPrintf("nFileVersion = %d\n", last_client); | |||||
pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ " | pwallet->WalletLogPrintf("Keys: %u plaintext, %u encrypted, %u w/ " | ||||
"metadata, %u total. Unknown wallet records: %u\n", | "metadata, %u total. Unknown wallet records: %u\n", | ||||
wss.nKeys, wss.nCKeys, wss.nKeyMeta, | wss.nKeys, wss.nCKeys, wss.nKeyMeta, | ||||
wss.nKeys + wss.nCKeys, wss.m_unknown_records); | wss.nKeys + wss.nCKeys, wss.m_unknown_records); | ||||
// nTimeFirstKey is only reliable if all keys have metadata | // nTimeFirstKey is only reliable if all keys have metadata | ||||
if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | if ((wss.nKeys + wss.nCKeys + wss.nWatchKeys) != wss.nKeyMeta) { | ||||
pwallet->UpdateTimeFirstKey(1); | pwallet->UpdateTimeFirstKey(1); | ||||
} | } | ||||
for (const TxId &txid : wss.vWalletUpgrade) { | for (const TxId &txid : wss.vWalletUpgrade) { | ||||
WriteTx(pwallet->mapWallet.at(txid)); | WriteTx(pwallet->mapWallet.at(txid)); | ||||
} | } | ||||
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: | // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: | ||||
if (wss.fIsEncrypted && | if (wss.fIsEncrypted && (last_client == 40000 || last_client == 50000)) { | ||||
(wss.nFileVersion == 40000 || wss.nFileVersion == 50000)) { | |||||
return DBErrors::NEED_REWRITE; | return DBErrors::NEED_REWRITE; | ||||
} | } | ||||
if (wss.nFileVersion < CLIENT_VERSION) { | if (last_client < CLIENT_VERSION) { | ||||
// Update | // Update | ||||
WriteVersion(CLIENT_VERSION); | WriteVersion(CLIENT_VERSION); | ||||
} | } | ||||
if (wss.fAnyUnordered) { | if (wss.fAnyUnordered) { | ||||
result = pwallet->ReorderTransactions(); | result = pwallet->ReorderTransactions(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |