aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2012-03-22 03:56:31 +0100
committerPieter Wuille <[email protected]>2012-03-22 23:47:29 +0100
commit439e1497e130914c2b78eff20c38046d6b1b6d49 (patch)
tree20eef7dba2044093e6a92fdce3f5a62c16f62840 /src/init.cpp
parentMerge pull request #946 from luke-jr/bugfix_rm_mingw (diff)
downloaddiscoin-439e1497e130914c2b78eff20c38046d6b1b6d49.tar.xz
discoin-439e1497e130914c2b78eff20c38046d6b1b6d49.zip
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/init.cpp')
-rw-r--r--src/init.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 603022e1e..4078b7e0c 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -222,6 +222,7 @@ bool AppInit2(int argc, char* argv[])
" -rpcallowip=<ip> \t\t " + _("Allow JSON-RPC connections from specified IP address") + "\n" +
" -rpcconnect=<ip> \t " + _("Send commands to node running on <ip> (default: 127.0.0.1)") + "\n" +
" -blocknotify=<cmd> " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" +
+ " -upgradewallet \t " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> \t " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan \t " + _("Rescan the block chain for missing wallet transactions") + "\n" +
" -checkblocks=<n> \t\t " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
@@ -380,6 +381,36 @@ bool AppInit2(int argc, char* argv[])
else
strErrors << _("Error loading wallet.dat") << "\n";
}
+
+ if (GetBoolArg("-upgradewallet", fFirstRun))
+ {
+ int nMaxVersion = GetArg("-upgradewallet", 0);
+ if (nMaxVersion == 0) // the -walletupgrade without argument case
+ {
+ printf("Performing wallet upgrade to %i\n", FEATURE_LATEST);
+ nMaxVersion = CLIENT_VERSION;
+ pwalletMain->SetMinVersion(FEATURE_LATEST); // permanently upgrade the wallet immediately
+ }
+ else
+ printf("Allowing wallet upgrade up to %i\n", nMaxVersion);
+ if (nMaxVersion < pwalletMain->GetVersion())
+ strErrors << _("Cannot downgrade wallet") << "\n";
+ pwalletMain->SetMaxVersion(nMaxVersion);
+ }
+
+ if (fFirstRun)
+ {
+ // Create new keyUser and set as default key
+ RandAddSeedPerfmon();
+
+ std::vector<unsigned char> newDefaultKey;
+ if (!pwalletMain->GetKeyFromPool(newDefaultKey, false))
+ strErrors << _("Cannot initialize keypool") << "\n";
+ pwalletMain->SetDefaultKey(newDefaultKey);
+ if (!pwalletMain->SetAddressBookName(CBitcoinAddress(pwalletMain->vchDefaultKey), ""))
+ strErrors << _("Cannot write default address") << "\n";
+ }
+
printf("%s", strErrors.str().c_str());
printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);