diff --git a/src/init.cpp b/src/init.cpp index 63610b17fb807..ebf019860af40 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -26,6 +26,7 @@ using namespace std; using namespace boost; CWallet* pwalletMain; +char *walletPath; // useful for printf style messages, etc. CClientUIInterface uiInterface; // Used to pass flags to the Bind() function @@ -247,6 +248,7 @@ std::string HelpMessage() " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n" + " -gen " + _("Generate coins") + "\n" + " -gen=0 " + _("Don't generate coins") + "\n" + + " -walletpath= " + _("Specify the wallet filename (default: wallet.dat)") + "\n" + " -datadir= " + _("Specify data directory") + "\n" + " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + @@ -610,6 +612,21 @@ bool AppInit2() uiInterface.InitMessage(_("Verifying wallet...")); + boost::filesystem::path + pathWalletFile(GetArg("-walletpath", "wallet.dat")); + + if (!pathWalletFile.is_complete()) + pathWalletFile = GetDataDir(false) / pathWalletFile; + + walletPath = new char[ pathWalletFile.string().size() + 1 ]; + strcpy( walletPath, pathWalletFile.string().c_str() ); + + (void)printf( + "wallet filename is %s, path (derived) is:\n%s\n", + pathWalletFile.filename().string().c_str(), + walletPath + ); + if (!bitdb.Open(GetDataDir())) { string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str()); @@ -619,23 +636,27 @@ bool AppInit2() if (GetBoolArg("-salvagewallet")) { // Recover readable keypairs: - if (!CWalletDB::Recover(bitdb, "wallet.dat", true)) + //if (!CWalletDB::Recover(bitdb, "wallet.dat", true)) + if (!CWalletDB::Recover(bitdb, walletPath, true)) return false; } - if (filesystem::exists(GetDataDir() / "wallet.dat")) + //if (filesystem::exists(GetDataDir() / "wallet.dat")) + if (filesystem::exists(walletPath)) { - CDBEnv::VerifyResult r = bitdb.Verify("wallet.dat", CWalletDB::Recover); + //CDBEnv::VerifyResult r = bitdb.Verify("wallet.dat", CWalletDB::Recover); + CDBEnv::VerifyResult r = bitdb.Verify(walletPath, CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { - string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" - " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" - " your balance or transactions are incorrect you should" - " restore from a backup."), strDataDir.c_str()); + string msg = strprintf(_("Warning: %s corrupt, data salvaged!" + " Original %s saved as wallet.{timestamp}.bak in %s; if" + " your balance or transactions are incorrect, you should" + " restore from a backup."), + walletPath, walletPath, strDataDir.c_str()); InitWarning(msg); } if (r == CDBEnv::RECOVER_FAIL) - return InitError(_("wallet.dat corrupt, salvage failed")); + return InitError(_("wallet.dat corrupt, salvage failed")); // should say %s walletPath } // ********************************************************* Step 6: network initialization @@ -835,7 +856,7 @@ bool AppInit2() } fLoaded = true; - } while(false); + } while(false); // this always fails, so isn't it redundant? Better just { } if at all? if (!fLoaded) { // first suggest a reindex @@ -903,16 +924,17 @@ bool AppInit2() nStart = GetTimeMillis(); bool fFirstRun = true; - pwalletMain = new CWallet("wallet.dat"); + //pwalletMain = new CWallet("wallet.dat"); + pwalletMain = new CWallet(walletPath); DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); if (nLoadWalletRet != DB_LOAD_OK) { if (nLoadWalletRet == DB_CORRUPT) - strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n"; + strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n"; // again walletPath else if (nLoadWalletRet == DB_NONCRITICAL_ERROR) { string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" - " or address book entries might be missing or incorrect.")); + " or address book entries might be missing or incorrect.")); // ditto InitWarning(msg); } else if (nLoadWalletRet == DB_TOO_NEW) @@ -924,7 +946,7 @@ bool AppInit2() return InitError(strErrors.str()); } else - strErrors << _("Error loading wallet.dat") << "\n"; + strErrors << _("Error loading wallet.dat") << "\n"; //ditto } if (GetBoolArg("-upgradewallet", fFirstRun)) @@ -966,7 +988,8 @@ bool AppInit2() pindexRescan = pindexGenesisBlock; else { - CWalletDB walletdb("wallet.dat"); + //CWalletDB walletdb("wallet.dat"); + CWalletDB walletdb(walletPath); CBlockLocator locator; if (walletdb.ReadBestBlock(locator)) pindexRescan = locator.GetBlockIndex(); @@ -974,7 +997,8 @@ bool AppInit2() if (pindexBest && pindexBest != pindexRescan) { uiInterface.InitMessage(_("Rescanning...")); - printf("Rescanning last %i blocks (from block %i)...\n", pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight); + printf("Rescanning last %i blocks (from block %i)...\n", + pindexBest->nHeight - pindexRescan->nHeight, pindexRescan->nHeight); nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart); diff --git a/src/init.h b/src/init.h index 8308ee648bcc0..18b17b8b7b25c 100644 --- a/src/init.h +++ b/src/init.h @@ -8,6 +8,7 @@ #include "wallet.h" extern CWallet* pwalletMain; +extern char *walletPath; // useful for printf style messages, etc. void StartShutdown(); void Shutdown(void* parg); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index cd3170a306228..9419563c649f6 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -1,7 +1,7 @@ #include "optionsmodel.h" #include "bitcoinunits.h" -#include "init.h" +#include "init.h" // graciously gives walletPath #include "walletdb.h" #include "guiutil.h" @@ -89,7 +89,9 @@ bool OptionsModel::Upgrade() settings.setValue("bImportFinished", true); // Move settings from old wallet.dat (if any): - CWalletDB walletdb("wallet.dat"); + //CWalletDB walletdb("wallet.dat"); + CWalletDB walletdb(walletPath); + QList intOptions; intOptions << "nDisplayUnit" << "nTransactionFee"; diff --git a/src/walletdb.cpp b/src/walletdb.cpp index fe9bce21e806b..4a0d51843495a 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -5,6 +5,7 @@ #include "walletdb.h" #include "wallet.h" +#include "init.h" // in virtue of walletPath #include using namespace std; @@ -527,7 +528,8 @@ void ThreadFlushWalletDB(void* parg) map::iterator mi = bitdb.mapFileUseCount.find(strFile); if (mi != bitdb.mapFileUseCount.end()) { - printf("Flushing wallet.dat\n"); + //printf("Flushing wallet.dat\n"); + printf("Flushing %s\n", walletPath); nLastFlushed = nWalletDBUpdated; int64 nStart = GetTimeMillis(); @@ -536,7 +538,8 @@ void ThreadFlushWalletDB(void* parg) bitdb.CheckpointLSN(strFile); bitdb.mapFileUseCount.erase(mi++); - printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); + //printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); + printf("Flushed %s %"PRI64d"ms\n", walletPath, GetTimeMillis() - nStart); } } } @@ -560,7 +563,8 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) bitdb.mapFileUseCount.erase(wallet.strWalletFile); // Copy wallet.dat - filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; + //filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; + filesystem::path pathSrc = walletPath; filesystem::path pathDest(strDest); if (filesystem::is_directory(pathDest)) pathDest /= wallet.strWalletFile; @@ -571,10 +575,11 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) #else filesystem::copy_file(pathSrc, pathDest); #endif - printf("copied wallet.dat to %s\n", pathDest.string().c_str()); + //printf("copied wallet.dat to %s\n", pathDest.string().c_str()); + printf("copied %s to %s\n", walletPath, pathDest.string().c_str()); return true; } catch(const filesystem::filesystem_error &e) { - printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); + printf("error copying %s to %s - %s\n", walletPath, pathDest.string().c_str(), e.what()); return false; } }