let user select wallet file with -wallet=foo.dat

use std::string instead of psz for WalletFile

only allow wallets within $DATADIR

Use strWalletFile in salvage/recover

fix: remove unused variable pszWalletFile

move strWalletFile to init.h/init.cpp

avoid conversion of strWalletfile to c-string
This commit is contained in:
Nils Schneider 2012-06-03 01:19:07 +02:00 committed by Nils Schneider
parent a4f43075d6
commit 674cb304b3
3 changed files with 15 additions and 6 deletions

View file

@ -29,6 +29,7 @@
using namespace std;
using namespace boost;
std::string strWalletFile;
CWallet* pwalletMain;
CClientUIInterface uiInterface;
@ -169,6 +170,7 @@ std::string HelpMessage()
strUsage += " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n";
strUsage += " -gen " + _("Generate coins (default: 0)") + "\n";
strUsage += " -datadir=<dir> " + _("Specify data directory") + "\n";
strUsage += " -wallet=<file> " + _("Specify wallet file (within data directory)") + "\n";
strUsage += " -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n";
strUsage += " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n";
strUsage += " -proxy=<ip:port> " + _("Connect through socks proxy") + "\n";
@ -493,10 +495,16 @@ bool AppInit2(boost::thread_group& threadGroup)
InitWarning(_("Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
}
strWalletFile = GetArg("-wallet", "wallet.dat");
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
std::string strDataDir = GetDataDir().string();
// Wallet file must be a plain filename without a directory
if (strWalletFile != boost::filesystem::basename(strWalletFile) + boost::filesystem::extension(strWalletFile))
return InitError(strprintf(_("Wallet %s resides outside data directory %s\n"), strWalletFile.c_str(), strDataDir.c_str()));
// Make sure only a single Bitcoin process is using the data directory.
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
@ -555,13 +563,13 @@ bool AppInit2(boost::thread_group& threadGroup)
if (GetBoolArg("-salvagewallet", false))
{
// Recover readable keypairs:
if (!CWalletDB::Recover(bitdb, "wallet.dat", true))
if (!CWalletDB::Recover(bitdb, strWalletFile, true))
return false;
}
if (filesystem::exists(GetDataDir() / "wallet.dat"))
if (filesystem::exists(GetDataDir() / strWalletFile))
{
CDBEnv::VerifyResult r = bitdb.Verify("wallet.dat", CWalletDB::Recover);
CDBEnv::VerifyResult r = bitdb.Verify(strWalletFile, CWalletDB::Recover);
if (r == CDBEnv::RECOVER_OK)
{
string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!"
@ -838,7 +846,7 @@ bool AppInit2(boost::thread_group& threadGroup)
nStart = GetTimeMillis();
bool fFirstRun = true;
pwalletMain = new CWallet("wallet.dat");
pwalletMain = new CWallet(strWalletFile);
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
if (nLoadWalletRet != DB_LOAD_OK)
{
@ -903,7 +911,7 @@ bool AppInit2(boost::thread_group& threadGroup)
pindexRescan = pindexGenesisBlock;
else
{
CWalletDB walletdb("wallet.dat");
CWalletDB walletdb(strWalletFile);
CBlockLocator locator;
if (walletdb.ReadBestBlock(locator))
pindexRescan = locator.GetBlockIndex();

View file

@ -7,6 +7,7 @@
#include "wallet.h"
extern std::string strWalletFile;
extern CWallet* pwalletMain;
void StartShutdown();

View file

@ -89,7 +89,7 @@ bool OptionsModel::Upgrade()
settings.setValue("bImportFinished", true);
// Move settings from old wallet.dat (if any):
CWalletDB walletdb("wallet.dat");
CWalletDB walletdb(strWalletFile);
QList<QString> intOptions;
intOptions << "nDisplayUnit" << "nTransactionFee";