Update License in File Headers
[novacoin.git] / src / wallet.h
index 6a6ee0c..9e451f8 100644 (file)
@@ -1,11 +1,11 @@
 // Copyright (c) 2009-2010 Satoshi Nakamoto
 // 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.
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
 #ifndef BITCOIN_WALLET_H
 #define BITCOIN_WALLET_H
 
-#include "bignum.h"
+#include "main.h"
 #include "key.h"
 #include "keystore.h"
 #include "script.h"
@@ -14,6 +14,7 @@ class CWalletTx;
 class CReserveKey;
 class CWalletDB;
 
+/** (client) version numbers for particular wallet features */
 enum WalletFeature
 {
     FEATURE_BASE = 10500, // the earliest version new wallets supports (only useful for getinfo's clientversion output)
@@ -24,9 +25,37 @@ enum WalletFeature
     FEATURE_LATEST = 60000
 };
 
-// A CWallet is an extension of a keystore, which also maintains a set of
-// transactions and balances, and provides the ability to create new
-// transactions
+
+/** A key pool entry */
+class CKeyPool
+{
+public:
+    int64 nTime;
+    std::vector<unsigned char> vchPubKey;
+
+    CKeyPool()
+    {
+        nTime = GetTime();
+    }
+
+    CKeyPool(const std::vector<unsigned char>& vchPubKeyIn)
+    {
+        nTime = GetTime();
+        vchPubKey = vchPubKeyIn;
+    }
+
+    IMPLEMENT_SERIALIZE
+    (
+        if (!(nType & SER_GETHASH))
+            READWRITE(nVersion);
+        READWRITE(nTime);
+        READWRITE(vchPubKey);
+    )
+};
+
+/** A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,
+ * and provides the ability to create new transactions.
+ */
 class CWallet : public CCryptoKeyStore
 {
 private:
@@ -195,14 +224,9 @@ public:
         }
         return nChange;
     }
-    void SetBestChain(const CBlockLocator& loc)
-    {
-        CWalletDB walletdb(strWalletFile);
-        walletdb.WriteBestBlock(loc);
-    }
+    void SetBestChain(const CBlockLocator& loc);
 
     int LoadWallet(bool& fFirstRunRet);
-//    bool BackupWallet(const std::string& strDest);
 
     bool SetAddressBookName(const CBitcoinAddress& address, const std::string& strName);
 
@@ -210,16 +234,18 @@ public:
 
     void UpdatedTransaction(const uint256 &hashTx)
     {
-        CRITICAL_BLOCK(cs_wallet)
+        {
+            LOCK(cs_wallet);
             vWalletUpdated.push_back(hashTx);
+        }
     }
 
     void PrintWallet(const CBlock& block);
 
     void Inventory(const uint256 &hash)
     {
-        CRITICAL_BLOCK(cs_wallet)
         {
+            LOCK(cs_wallet);
             std::map<uint256, int>::iterator mi = mapRequestCount.find(hash);
             if (mi != mapRequestCount.end())
                 (*mi).second++;
@@ -245,7 +271,7 @@ public:
     int GetVersion() { return nWalletVersion; }
 };
 
-
+/** A key allocated from the key pool. */
 class CReserveKey
 {
 protected:
@@ -271,11 +297,9 @@ public:
 };
 
 
-//
-// A transaction with a bunch of additional info that only the owner cares
-// about.  It includes any unrecorded transactions needed to link it back
-// to the block chain.
-//
+/** A transaction with a bunch of additional info that only the owner cares about. 
+ * It includes any unrecorded transactions needed to link it back to the block chain.
+ */
 class CWalletTx : public CMerkleTx
 {
 private:
@@ -292,20 +316,15 @@ public:
     std::vector<char> vfSpent; // which outputs are already spent
 
     // memory only
-    mutable char fDebitCached;
-    mutable char fCreditCached;
-    mutable char fAvailableCreditCached;
-    mutable char fChangeCached;
+    mutable bool fDebitCached;
+    mutable bool fCreditCached;
+    mutable bool fAvailableCreditCached;
+    mutable bool fChangeCached;
     mutable int64 nDebitCached;
     mutable int64 nCreditCached;
     mutable int64 nAvailableCreditCached;
     mutable int64 nChangeCached;
 
-    // memory only UI hints
-    mutable unsigned int nTimeDisplayed;
-    mutable int nLinesDisplayed;
-    mutable char fConfirmedDisplayed;
-
     CWalletTx()
     {
         Init(NULL);
@@ -345,9 +364,6 @@ public:
         nCreditCached = 0;
         nAvailableCreditCached = 0;
         nChangeCached = 0;
-        nTimeDisplayed = 0;
-        nLinesDisplayed = 0;
-        fConfirmedDisplayed = false;
     }
 
     IMPLEMENT_SERIALIZE
@@ -401,7 +417,7 @@ public:
     bool UpdateSpent(const std::vector<char>& vfNewSpent)
     {
         bool fReturn = false;
-        for (int i=0; i < vfNewSpent.size(); i++)
+        for (unsigned int i = 0; i < vfNewSpent.size(); i++)
         {
             if (i == vfSpent.size())
                 break;
@@ -487,7 +503,7 @@ public:
             return nAvailableCreditCached;
 
         int64 nCredit = 0;
-        for (int i = 0; i < vout.size(); i++)
+        for (unsigned int i = 0; i < vout.size(); i++)
         {
             if (!IsSpent(i))
             {
@@ -540,7 +556,7 @@ public:
         std::vector<const CMerkleTx*> vWorkQueue;
         vWorkQueue.reserve(vtxPrev.size()+1);
         vWorkQueue.push_back(this);
-        for (int i = 0; i < vWorkQueue.size(); i++)
+        for (unsigned int i = 0; i < vWorkQueue.size(); i++)
         {
             const CMerkleTx* ptx = vWorkQueue[i];
 
@@ -552,8 +568,10 @@ public:
                 return false;
 
             if (mapPrev.empty())
+            {
                 BOOST_FOREACH(const CMerkleTx& tx, vtxPrev)
                     mapPrev[tx.GetHash()] = &tx;
+            }
 
             BOOST_FOREACH(const CTxIn& txin, ptx->vin)
             {
@@ -580,9 +598,7 @@ public:
 };
 
 
-//
-// Private key that includes an expiration date in case it never gets used.
-//
+/** Private key that includes an expiration date in case it never gets used. */
 class CWalletKey
 {
 public:
@@ -615,10 +631,9 @@ public:
 
 
 
-//
-// Account information.
-// Stored in wallet with key "acc"+string account name
-//
+/** Account information.
+ * Stored in wallet with key "acc"+string account name.
+ */
 class CAccount
 {
 public:
@@ -644,10 +659,9 @@ public:
 
 
 
-//
-// Internal transfers.
-// Database key is acentry<account><counter>
-//
+/** Internal transfers.
+ * Database key is acentry<account><counter>.
+ */
 class CAccountingEntry
 {
 public: