From 439e1497e130914c2b78eff20c38046d6b1b6d49 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 22 Mar 2012 03:56:31 +0100 Subject: 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. --- src/wallet.cpp | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/wallet.cpp') diff --git a/src/wallet.cpp b/src/wallet.cpp index 30590c80e..27ed7228d 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -17,7 +17,7 @@ using namespace std; std::vector CWallet::GenerateNewKey() { - bool fCompressed = true; // default to compressed public keys + bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets RandAddSeedPerfmon(); CKey key; @@ -25,7 +25,7 @@ std::vector CWallet::GenerateNewKey() // Compressed public keys were introduced in version 0.6.0 if (fCompressed) - SetMinVersion(59900); + SetMinVersion(FEATURE_COMPRPUBKEY); if (!AddKey(key)) throw std::runtime_error("CWallet::GenerateNewKey() : AddKey failed"); @@ -148,13 +148,20 @@ public: ) }; -bool CWallet::SetMinVersion(int nVersion, CWalletDB* pwalletdbIn) +bool CWallet::SetMinVersion(enum WalletFeature nVersion, CWalletDB* pwalletdbIn, bool fExplicit) { if (nWalletVersion >= nVersion) return true; + // when doing an explicit upgrade, if we pass the max version permitted, upgrade all the way + if (fExplicit && nVersion > nWalletMaxVersion) + nVersion = FEATURE_LATEST; + nWalletVersion = nVersion; + if (nVersion > nWalletMaxVersion) + nWalletMaxVersion = nVersion; + if (fFileBacked) { CWalletDB* pwalletdb = pwalletdbIn ? pwalletdbIn : new CWalletDB(strWalletFile); @@ -174,6 +181,17 @@ bool CWallet::SetMinVersion(int nVersion, CWalletDB* pwalletdbIn) return true; } +bool CWallet::SetMaxVersion(int nVersion) +{ + // cannot downgrade below current version + if (nWalletVersion > nVersion) + return false; + + nWalletMaxVersion = nVersion; + + return true; +} + bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) { if (IsCrypted()) @@ -228,7 +246,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) } // Encryption was introduced in version 0.4.0 - SetMinVersion(40000, pwalletdbEncryption); + SetMinVersion(FEATURE_WALLETCRYPT, pwalletdbEncryption, true); if (fFileBacked) { @@ -1253,19 +1271,6 @@ int CWallet::LoadWallet(bool& fFirstRunRet) return nLoadWalletRet; fFirstRunRet = vchDefaultKey.empty(); - if (!HaveKey(Hash160(vchDefaultKey))) - { - // Create new keyUser and set as default key - RandAddSeedPerfmon(); - - std::vector newDefaultKey; - if (!GetKeyFromPool(newDefaultKey, false)) - return DB_LOAD_FAIL; - SetDefaultKey(newDefaultKey); - if (!SetAddressBookName(CBitcoinAddress(vchDefaultKey), "")) - return DB_LOAD_FAIL; - } - CreateThread(ThreadFlushWalletDB, &strWalletFile); return DB_LOAD_OK; } -- cgit v1.2.3