Update License in File Headers
[novacoin.git] / src / db.h
index b910111..8f6c42d 100644 (file)
--- a/src/db.h
+++ b/src/db.h
@@ -1,6 +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
 
@@ -27,14 +28,12 @@ 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);
 
 
 
-
 class CDB
 {
 protected:
@@ -88,7 +87,7 @@ protected:
         if (!pdb)
             return false;
         if (fReadOnly)
-            assert(("Write called on database in read-only mode", false));
+            assert(!"Write called on database in read-only mode");
 
         // Key
         CDataStream ssKey(SER_DISK);
@@ -117,7 +116,7 @@ protected:
         if (!pdb)
             return false;
         if (fReadOnly)
-            assert(("Erase called on database in read-only mode", false));
+            assert(!"Erase called on database in read-only mode");
 
         // Key
         CDataStream ssKey(SER_DISK);
@@ -256,6 +255,8 @@ public:
     {
         return Write(std::string("version"), nVersion);
     }
+
+    bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL);
 };
 
 
@@ -346,7 +347,9 @@ enum DBErrors
 {
     DB_LOAD_OK,
     DB_CORRUPT,
-    DB_TOO_NEW
+    DB_TOO_NEW,
+    DB_LOAD_FAIL,
+    DB_NEED_REWRITE
 };
 
 class CWalletDB : public CDB
@@ -398,6 +401,25 @@ public:
         return Write(std::make_pair(std::string("key"), vchPubKey), vchPrivKey, false);
     }
 
+    bool WriteCryptedKey(const std::vector<unsigned char>& vchPubKey, const std::vector<unsigned char>& vchCryptedSecret, bool fEraseUnencryptedKey = true)
+    {
+        nWalletDBUpdated++;
+        if (!Write(std::make_pair(std::string("ckey"), vchPubKey), vchCryptedSecret, false))
+            return false;
+        if (fEraseUnencryptedKey)
+        {
+            Erase(std::make_pair(std::string("key"), vchPubKey));
+            Erase(std::make_pair(std::string("wkey"), vchPubKey));
+        }
+        return true;
+    }
+
+    bool WriteMasterKey(unsigned int nID, const CMasterKey& kMasterKey)
+    {
+        nWalletDBUpdated++;
+        return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
+    }
+
     bool WriteBestBlock(const CBlockLocator& locator)
     {
         nWalletDBUpdated++;