X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fwallet.h;h=5672c6069dd940a05e5379075902c75f14fa3fd5;hb=0c3aa881e2ac7a6142fcfcbb9b7d2824532fe522;hp=fea329778889ee0e1574ca832a07a86ca71228b5;hpb=9976cf070fdda61afa30cd65ef5bcddad4f43e81;p=novacoin.git diff --git a/src/wallet.h b/src/wallet.h index fea3297..5672c60 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -14,9 +14,20 @@ class CWalletTx; class CReserveKey; class CWalletDB; -// 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 +/** (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) + + FEATURE_WALLETCRYPT = 40000, // wallet encryption + FEATURE_COMPRPUBKEY = 60000, // compressed public keys + + 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. + */ class CWallet : public CCryptoKeyStore { private: @@ -25,8 +36,12 @@ private: CWalletDB *pwalletdbEncryption; + // the current wallet version: clients below this version are not able to load the wallet int nWalletVersion; + // the maxmimum wallet format version: memory-only variable that specifies to what version this wallet may be upgraded + int nWalletMaxVersion; + public: mutable CCriticalSection cs_wallet; @@ -42,14 +57,16 @@ public: CWallet() { - nWalletVersion = 0; + nWalletVersion = FEATURE_BASE; + nWalletMaxVersion = FEATURE_BASE; fFileBacked = false; nMasterKeyMaxID = 0; pwalletdbEncryption = NULL; } CWallet(std::string strWalletFileIn) { - nWalletVersion = 0; + nWalletVersion = FEATURE_BASE; + nWalletMaxVersion = FEATURE_BASE; strWalletFile = strWalletFileIn; fFileBacked = true; nMasterKeyMaxID = 0; @@ -65,6 +82,9 @@ public: std::vector vchDefaultKey; + // check whether we are allowed to upgrade (or already support) to the named feature + bool CanSupportFeature(enum WalletFeature wf) { return nWalletMaxVersion >= wf; } + // keystore implementation // Generate a new key std::vector GenerateNewKey(); @@ -73,12 +93,12 @@ public: // Adds a key to the store, without saving it to disk (used by LoadWallet) bool LoadKey(const CKey& key) { return CCryptoKeyStore::AddKey(key); } - bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; return true; } + bool LoadMinVersion(int nVersion) { nWalletVersion = nVersion; nWalletMaxVersion = std::max(nWalletMaxVersion, nVersion); return true; } // Adds an encrypted key to the store, and saves it to disk. bool AddCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret); // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) - bool LoadCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) { return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } + bool LoadCryptedKey(const std::vector &vchPubKey, const std::vector &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } bool AddCScript(const CScript& redeemScript); bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); } @@ -216,10 +236,17 @@ public: bool SetDefaultKey(const std::vector &vchPubKey); - bool SetMinVersion(int nVersion, CWalletDB* pwalletdbIn = NULL); -}; + // signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVersion if those are lower + bool SetMinVersion(enum WalletFeature, CWalletDB* pwalletdbIn = NULL, bool fExplicit = false); + + // change which version we're allowed to upgrade to (note that this does not immediately imply upgrading to that format) + bool SetMaxVersion(int nVersion); + // get the current wallet format (the oldest client version guaranteed to understand this wallet) + int GetVersion() { return nWalletVersion; } +}; +/** A key allocated from the key pool. */ class CReserveKey { protected: @@ -245,11 +272,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: @@ -375,7 +400,7 @@ public: bool UpdateSpent(const std::vector& 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; @@ -461,7 +486,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)) { @@ -514,7 +539,7 @@ public: std::vector 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]; @@ -526,8 +551,10 @@ public: return false; if (mapPrev.empty()) + { BOOST_FOREACH(const CMerkleTx& tx, vtxPrev) mapPrev[tx.GetHash()] = &tx; + } BOOST_FOREACH(const CTxIn& txin, ptx->vin) { @@ -554,9 +581,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: @@ -589,10 +614,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: @@ -618,10 +642,9 @@ public: -// -// Internal transfers. -// Database key is acentry -// +/** Internal transfers. + * Database key is acentry. + */ class CAccountingEntry { public: