diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2011-07-12 19:34:30 -0700 |
---|---|---|
committer | Jeff Garzik <jgarzik@exmulti.com> | 2011-07-12 19:34:30 -0700 |
commit | 0fa89d8e816807a621419495d7bdc6366979a0f0 (patch) | |
tree | 32327a402bb77104f74738c2a10022c8938db252 | |
parent | 61e3c011f5506b4ebd0014e49ea8b61ae916d20d (diff) | |
parent | 7ec552676c66488fe00fb503d02ec4a389a715b7 (diff) |
Merge pull request #381 from TheBlueMatt/nminversion
Add minversion to wallet.
-rw-r--r-- | src/db.cpp | 15 | ||||
-rw-r--r-- | src/db.h | 9 | ||||
-rw-r--r-- | src/init.cpp | 12 | ||||
-rw-r--r-- | src/wallet.cpp | 5 |
4 files changed, 32 insertions, 9 deletions
diff --git a/src/db.cpp b/src/db.cpp index ebe7e3a8f6..1dea92eadc 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -670,7 +670,7 @@ void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountin } -bool CWalletDB::LoadWallet(CWallet* pwallet) +int CWalletDB::LoadWallet(CWallet* pwallet) { pwallet->vchDefaultKey.clear(); int nFileVersion = 0; @@ -690,7 +690,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) // Get cursor Dbc* pcursor = GetCursor(); if (!pcursor) - return false; + return DB_CORRUPT; loop { @@ -701,7 +701,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) if (ret == DB_NOTFOUND) break; else if (ret != 0) - return false; + return DB_CORRUPT; // Unserialize // Taking advantage of the fact that pair serialization @@ -836,6 +836,13 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) if (strKey == "addrProxy") ssValue >> addrProxy; if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP; } + else if (strType == "minversion") + { + int nMinVersion = 0; + ssValue >> nMinVersion; + if (nMinVersion > VERSION) + return DB_TOO_NEW; + } } pcursor->close(); } @@ -865,7 +872,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet) } - return true; + return DB_LOAD_OK; } void ThreadFlushWalletDB(void* parg) @@ -342,6 +342,13 @@ public: +enum DBErrors +{ + DB_LOAD_OK, + DB_CORRUPT, + DB_TOO_NEW +}; + class CWalletDB : public CDB { public: @@ -469,7 +476,7 @@ public: int64 GetAccountCreditDebit(const std::string& strAccount); void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries); - bool LoadWallet(CWallet* pwallet); + int LoadWallet(CWallet* pwallet); }; #endif diff --git a/src/init.cpp b/src/init.cpp index 21b40d5193..fd1d8d3cd9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -387,8 +387,16 @@ bool AppInit2(int argc, char* argv[]) nStart = GetTimeMillis(); bool fFirstRun; pwalletMain = new CWallet("wallet.dat"); - if (!pwalletMain->LoadWallet(fFirstRun)) - strErrors += _("Error loading wallet.dat \n"); + int nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); + if (nLoadWalletRet != DB_LOAD_OK) + { + if (nLoadWalletRet == DB_CORRUPT) + strErrors += _("Error loading wallet.dat: Wallet corrupted \n"); + else if (nLoadWalletRet == DB_TOO_NEW) + strErrors += _("Error loading wallet.dat: Wallet requires newer version of Bitcoin \n"); + else + strErrors += _("Error loading wallet.dat \n"); + } printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart); RegisterWallet(pwalletMain); diff --git a/src/wallet.cpp b/src/wallet.cpp index 93313e7b27..a211fde468 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1130,8 +1130,9 @@ bool CWallet::LoadWallet(bool& fFirstRunRet) if (!fFileBacked) return false; fFirstRunRet = false; - if (!CWalletDB(strWalletFile,"cr+").LoadWallet(this)) - return false; + int nLoadWalletRet = CWalletDB(strWalletFile,"cr+").LoadWallet(this); + if (nLoadWalletRet != DB_LOAD_OK) + return nLoadWalletRet; fFirstRunRet = vchDefaultKey.empty(); if (!HaveKey(vchDefaultKey)) |