diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-03-22 03:56:31 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-03-22 23:47:29 +0100 |
commit | 439e1497e130914c2b78eff20c38046d6b1b6d49 (patch) | |
tree | 20eef7dba2044093e6a92fdce3f5a62c16f62840 /src/wallet.h | |
parent | 4a17e3e6b947d6ede40e49f77244d880240240cd (diff) |
Introduce explicit -walletupgrade option
Do not automatically change the wallet format unless the user takes an
explicit action that implies an upgrade (encrypting, for now), or uses
-walletupgrade.
-walletupgrade optionally takes an integer argument: the client version
up to which upgrading is allowed. Without an argument, it is upgraded
to latest supported version. If an argument to -walletupgrade is
provided at the time the wallet is created, the new wallet will initially
not use features beyond that version.
Third, the current wallet version number is reported in getinfo.
Diffstat (limited to 'src/wallet.h')
-rw-r--r-- | src/wallet.h | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/wallet.h b/src/wallet.h index fea3297788..6a6ee0c4ab 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -14,6 +14,16 @@ class CWalletTx; class CReserveKey; class CWalletDB; +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 @@ -25,8 +35,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 +56,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 +81,9 @@ public: std::vector<unsigned char> 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<unsigned char> GenerateNewKey(); @@ -73,12 +92,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<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret); // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) - bool LoadCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } + bool LoadCryptedKey(const std::vector<unsigned char> &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { SetMinVersion(FEATURE_WALLETCRYPT); return CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret); } bool AddCScript(const CScript& redeemScript); bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); } @@ -216,7 +235,14 @@ public: bool SetDefaultKey(const std::vector<unsigned char> &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; } }; |