Better wording for transaction fee notification messages
[novacoin.git] / db.h
diff --git a/db.h b/db.h
index 9b1f5e5..290981c 100644 (file)
--- a/db.h
+++ b/db.h
@@ -11,6 +11,9 @@ class CUser;
 class CReview;
 class CAddress;
 class CWalletTx;
+class CAccount;
+class CAccountingEntry;
+class CBlockLocator;
 
 extern map<string, string> mapAddressBook;
 extern CCriticalSection cs_mapAddressBook;
@@ -24,6 +27,8 @@ extern DbEnv dbenv;
 
 
 extern void DBFlush(bool fShutdown);
+extern vector<unsigned char> GetKeyFromKeyPool();
+extern int64 GetOldestKeyPoolTime();
 
 
 
@@ -261,7 +266,7 @@ public:
 class CTxDB : public CDB
 {
 public:
-    CTxDB(const char* pszMode="r+") : CDB(!fClient ? "blkindex.dat" : NULL, pszMode) { }
+    CTxDB(const char* pszMode="r+") : CDB("blkindex.dat", pszMode) { }
 private:
     CTxDB(const CTxDB&);
     void operator=(const CTxDB&);
@@ -298,6 +303,7 @@ private:
     void operator=(const CAddrDB&);
 public:
     bool WriteAddress(const CAddress& addr);
+    bool EraseAddress(const CAddress& addr);
     bool LoadAddresses();
 };
 
@@ -308,10 +314,41 @@ bool LoadAddresses();
 
 
 
+class CKeyPool
+{
+public:
+    int64 nTime;
+    vector<unsigned char> vchPubKey;
+
+    CKeyPool()
+    {
+        nTime = GetTime();
+    }
+
+    CKeyPool(const vector<unsigned char>& vchPubKeyIn)
+    {
+        nTime = GetTime();
+        vchPubKey = vchPubKeyIn;
+    }
+
+    IMPLEMENT_SERIALIZE
+    (
+        if (!(nType & SER_GETHASH))
+            READWRITE(nVersion);
+        READWRITE(nTime);
+        READWRITE(vchPubKey);
+    )
+};
+
+
+
+
 class CWalletDB : public CDB
 {
 public:
-    CWalletDB(const char* pszMode="r+") : CDB("wallet.dat", pszMode) { }
+    CWalletDB(const char* pszMode="r+") : CDB("wallet.dat", pszMode)
+    {
+    }
 private:
     CWalletDB(const CWalletDB&);
     void operator=(const CWalletDB&);
@@ -369,6 +406,17 @@ public:
         return Write(make_pair(string("key"), vchPubKey), vchPrivKey, false);
     }
 
+    bool WriteBestBlock(const CBlockLocator& locator)
+    {
+        nWalletDBUpdated++;
+        return Write(string("bestblock"), locator);
+    }
+
+    bool ReadBestBlock(CBlockLocator& locator)
+    {
+        return Read(string("bestblock"), locator);
+    }
+
     bool ReadDefaultKey(vector<unsigned char>& vchPubKey)
     {
         vchPubKey.clear();
@@ -395,7 +443,20 @@ public:
         return Write(make_pair(string("setting"), strKey), value);
     }
 
+    bool ReadAccount(const string& strAccount, CAccount& account);
+    bool WriteAccount(const string& strAccount, const CAccount& account);
+    bool WriteAccountingEntry(const CAccountingEntry& acentry);
+    int64 GetAccountCreditDebit(const string& strAccount);
+    void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);
+
     bool LoadWallet();
+protected:
+    void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
+    void KeepKey(int64 nIndex);
+    static void ReturnKey(int64 nIndex);
+    friend class CReserveKey;
+    friend vector<unsigned char> GetKeyFromKeyPool();
+    friend int64 GetOldestKeyPoolTime();
 };
 
 bool LoadWallet(bool& fFirstRunRet);
@@ -405,3 +466,49 @@ inline bool SetAddressBookName(const string& strAddress, const string& strName)
 {
     return CWalletDB().WriteName(strAddress, strName);
 }
+
+class CReserveKey
+{
+protected:
+    int64 nIndex;
+    vector<unsigned char> vchPubKey;
+public:
+    CReserveKey()
+    {
+        nIndex = -1;
+    }
+
+    ~CReserveKey()
+    {
+        if (!fShutdown)
+            ReturnKey();
+    }
+
+    vector<unsigned char> GetReservedKey()
+    {
+        if (nIndex == -1)
+        {
+            CKeyPool keypool;
+            CWalletDB().ReserveKeyFromKeyPool(nIndex, keypool);
+            vchPubKey = keypool.vchPubKey;
+        }
+        assert(!vchPubKey.empty());
+        return vchPubKey;
+    }
+
+    void KeepKey()
+    {
+        if (nIndex != -1)
+            CWalletDB().KeepKey(nIndex);
+        nIndex = -1;
+        vchPubKey.clear();
+    }
+
+    void ReturnKey()
+    {
+        if (nIndex != -1)
+            CWalletDB::ReturnKey(nIndex);
+        nIndex = -1;
+        vchPubKey.clear();
+    }
+};