aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-03-25 19:44:52 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2012-03-25 19:44:52 -0700
commit01a196e08db49d83cf6c5abd8a799c56dcfef503 (patch)
tree6bedf33565483961f16bd7741d21549c22656485 /src/wallet.h
parent59e659fcc08b622da08448018e507c2472ca2f1f (diff)
parent439e1497e130914c2b78eff20c38046d6b1b6d49 (diff)
Merge pull request #974 from sipa/walletupgrade
Introduce explicit -walletupgrade option
Diffstat (limited to 'src/wallet.h')
-rw-r--r--src/wallet.h36
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; }
};