aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/walletdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/walletdb.cpp')
-rw-r--r--src/wallet/walletdb.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 5b275131af..43e4747317 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -246,9 +246,9 @@ public:
}
};
-bool
+static bool
ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
- CWalletScanState &wss, std::string& strType, std::string& strErr)
+ CWalletScanState &wss, std::string& strType, std::string& strErr) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
{
try {
// Unserialize
@@ -495,22 +495,21 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue,
ssKey >> strAddress;
ssKey >> strKey;
ssValue >> strValue;
- if (!pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue))
- {
- strErr = "Error reading wallet database: LoadDestData failed";
- return false;
- }
+ pwallet->LoadDestData(DecodeDestination(strAddress), strKey, strValue);
}
else if (strType == "hdchain")
{
CHDChain chain;
ssValue >> chain;
- if (!pwallet->SetHDChain(chain, true))
- {
- strErr = "Error reading wallet database: SetHDChain failed";
+ pwallet->SetHDChain(chain, true);
+ } else if (strType == "flags") {
+ uint64_t flags;
+ ssValue >> flags;
+ if (!pwallet->SetWalletFlags(flags, true)) {
+ strErr = "Error reading wallet database: Unknown non-tolerable wallet flags found";
return false;
}
- } else if (strType != "bestblock" && strType != "bestblock_nomerkle"){
+ } else if (strType != "bestblock" && strType != "bestblock_nomerkle") {
wss.m_unknown_records++;
}
} catch (...)
@@ -537,7 +536,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
int nMinVersion = 0;
if (m_batch.Read((std::string)"minversion", nMinVersion))
{
- if (nMinVersion > CLIENT_VERSION)
+ if (nMinVersion > FEATURE_LATEST)
return DBErrors::TOO_NEW;
pwallet->LoadMinVersion(nMinVersion);
}
@@ -570,10 +569,12 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
{
// losing keys is considered a catastrophic error, anything else
// we assume the user can live with:
- if (IsKeyType(strType) || strType == "defaultkey")
+ if (IsKeyType(strType) || strType == "defaultkey") {
result = DBErrors::CORRUPT;
- else
- {
+ } else if(strType == "flags") {
+ // reading the wallet flags can only fail if unknown flags are present
+ result = DBErrors::TOO_NEW;
+ } else {
// Leave other errors alone, if we try to fix them we might make things worse.
fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
if (strType == "tx")
@@ -640,7 +641,7 @@ DBErrors WalletBatch::FindWalletTx(std::vector<uint256>& vTxHash, std::vector<CW
int nMinVersion = 0;
if (m_batch.Read((std::string)"minversion", nMinVersion))
{
- if (nMinVersion > CLIENT_VERSION)
+ if (nMinVersion > FEATURE_LATEST)
return DBErrors::TOO_NEW;
}
@@ -756,7 +757,7 @@ void MaybeCompactWalletDB()
return;
}
- for (CWallet* pwallet : GetWallets()) {
+ for (const std::shared_ptr<CWallet>& pwallet : GetWallets()) {
WalletDatabase& dbh = pwallet->GetDBHandle();
unsigned int nUpdateCounter = dbh.nUpdateCounter;
@@ -840,6 +841,11 @@ bool WalletBatch::WriteHDChain(const CHDChain& chain)
return WriteIC(std::string("hdchain"), chain);
}
+bool WalletBatch::WriteWalletFlags(const uint64_t flags)
+{
+ return WriteIC(std::string("flags"), flags);
+}
+
bool WalletBatch::TxnBegin()
{
return m_batch.TxnBegin();