bitcoind changes to stop storing settings in wallet.dat.
[novacoin.git] / src / db.h
index 73ea190..74cb5d8 100644 (file)
--- a/src/db.h
+++ b/src/db.h
@@ -1,5 +1,5 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2011 The Bitcoin developers
+// Copyright (c) 2009-2012 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.
 #ifndef BITCOIN_DB_H
 
 #include <db_cxx.h>
 
-class CTxIndex;
+class CAccount;
+class CAccountingEntry;
+class CAddress;
+class CBlockLocator;
 class CDiskBlockIndex;
 class CDiskTxPos;
+class CMasterKey;
 class COutPoint;
-class CAddress;
-class CWalletTx;
+class CTxIndex;
 class CWallet;
-class CAccount;
-class CAccountingEntry;
-class CBlockLocator;
-
+class CWalletTx;
 
 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:
@@ -257,6 +255,8 @@ public:
     {
         return Write(std::string("version"), nVersion);
     }
+
+    bool static Rewrite(const std::string& strFile, const char* pszSkip = NULL);
 };
 
 
@@ -349,6 +349,7 @@ enum DBErrors
     DB_CORRUPT,
     DB_TOO_NEW,
     DB_LOAD_FAIL,
+    DB_NEED_REWRITE
 };
 
 class CWalletDB : public CDB
@@ -419,6 +420,19 @@ public:
         return Write(std::make_pair(std::string("mkey"), nID), kMasterKey, true);
     }
 
+    // Support for BIP 0013 : see https://en.bitcoin.it/wiki/BIP_0013
+    bool ReadCScript(const uint160 &hash, CScript& redeemScript)
+    {
+        redeemScript.clear();
+        return Read(std::make_pair(std::string("cscript"), hash), redeemScript);
+    }
+
+    bool WriteCScript(const uint160& hash, const CScript& redeemScript)
+    {
+        nWalletDBUpdated++;
+        return Write(std::make_pair(std::string("cscript"), hash), redeemScript, false);
+    }
+
     bool WriteBestBlock(const CBlockLocator& locator)
     {
         nWalletDBUpdated++;
@@ -459,18 +473,29 @@ public:
         return Erase(std::make_pair(std::string("pool"), nPool));
     }
 
+    // Settings are no longer stored in wallet.dat; these are
+    // used only for backwards compatibility:
     template<typename T>
     bool ReadSetting(const std::string& strKey, T& value)
     {
         return Read(std::make_pair(std::string("setting"), strKey), value);
     }
-
     template<typename T>
     bool WriteSetting(const std::string& strKey, const T& value)
     {
         nWalletDBUpdated++;
         return Write(std::make_pair(std::string("setting"), strKey), value);
     }
+    bool EraseSetting(const std::string& strKey)
+    {
+        nWalletDBUpdated++;
+        return Erase(std::make_pair(std::string("setting"), strKey));
+    }
+
+    bool WriteMinVersion(int nVersion)
+    {
+        return Write(std::string("minversion"), nVersion);
+    }
 
     bool ReadAccount(const std::string& strAccount, CAccount& account);
     bool WriteAccount(const std::string& strAccount, const CAccount& account);