Prevent crashes due to missing or corrupted database records
[novacoin.git] / src / db.h
index 75748ac..551e093 100644 (file)
--- a/src/db.h
+++ b/src/db.h
@@ -1,7 +1,7 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
 // Copyright (c) 2011 The Bitcoin developers
 // Distributed under the MIT/X11 software license, see the accompanying
-// file license.txt or http://www.opensource.org/licenses/mit-license.php.
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
 #ifndef BITCOIN_DB_H
 #define BITCOIN_DB_H
 
@@ -28,11 +28,9 @@ class CBlockLocator;
 extern unsigned int nWalletDBUpdated;
 extern DbEnv dbenv;
 
-
 extern void DBFlush(bool fShutdown);
 void ThreadFlushWalletDB(void* parg);
 bool BackupWallet(const CWallet& wallet, const std::string& strDest);
-extern bool Resilver(const std::string& strFile);
 
 
 
@@ -74,8 +72,13 @@ protected:
             return false;
 
         // Unserialize value
-        CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK);
-        ssValue >> value;
+        try {
+            CDataStream ssValue((char*)datValue.get_data(), (char*)datValue.get_data() + datValue.get_size(), SER_DISK);
+            ssValue >> value;
+        }
+        catch (std::exception &e) {
+            return false;
+        }
 
         // Clear and free memory
         memset(datValue.get_data(), 0, datValue.get_size());
@@ -258,7 +261,7 @@ public:
         return Write(std::string("version"), nVersion);
     }
 
-    friend bool Resilver(const std::string&);
+    bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL);
 };
 
 
@@ -351,7 +354,7 @@ enum DBErrors
     DB_CORRUPT,
     DB_TOO_NEW,
     DB_LOAD_FAIL,
-    DB_NEED_RESILVER
+    DB_NEED_REWRITE
 };
 
 class CWalletDB : public CDB