Skip to content

Commit

Permalink
Merge pull request #121 from digital-dreamer/custom-wallet-filename
Browse files Browse the repository at this point in the history
Custom wallet filename option
  • Loading branch information
phelixbtc committed Jun 30, 2014
2 parents e1f9ea4 + cb0dfa9 commit ca083a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
21 changes: 12 additions & 9 deletions src/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "headers.h"
#include "db.h"
#include "net.h"
#include "init.h"
#include "auxpow.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
Expand Down Expand Up @@ -147,12 +148,12 @@ CDB::Close ()
if (!fReadOnly)
{
/* Flush database activity from memory pool to disk log.
wallet.dat is always flushed, the other files only every couple
wallet file is always flushed, the other files only every couple
of minutes.
Note: Namecoin has more .dat files than Bitcoin. */

unsigned int nMinutes = 2;
if (strFile == "wallet.dat")
if (strFile == walletPath)
nMinutes = 0;
else if ((strFile == "blkindex.dat" || strFile == "nameindex.dat")
&& IsInitialBlockDownload ())
Expand Down Expand Up @@ -841,17 +842,17 @@ void ThreadFlushWalletDB(void* parg)
if (mi != mapFileUseCount.end())
{
printf("%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
printf("Flushing wallet.dat\n");
printf("Flushing %s\n", walletPath.c_str());
nLastFlushed = nWalletDBUpdated;
int64 nStart = GetTimeMillis();

// Flush wallet.dat so it's self contained
// Flush wallet file so it's self contained
CloseDb(strFile);
dbenv.txn_checkpoint(0, 0, 0);
dbenv.lsn_reset(strFile.c_str(), 0);

mapFileUseCount.erase(mi++);
printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart);
printf("Flushed %s %"PRI64d"ms\n", walletPath.c_str(), GetTimeMillis() - nStart);
}
}
}
Expand All @@ -875,8 +876,10 @@ bool BackupWallet(const CWallet& wallet, const string& strDest)
dbenv.lsn_reset(wallet.strWalletFile.c_str(), 0);
mapFileUseCount.erase(wallet.strWalletFile);

// Copy wallet.dat
filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile);
// Copy wallet file
filesystem::path pathSrc(wallet.strWalletFile);
if(!pathSrc.is_complete())
pathSrc = filesystem::path(GetDataDir()) / pathSrc;
filesystem::path pathDest(strDest);
if (filesystem::is_directory(pathDest))
pathDest = pathDest / wallet.strWalletFile;
Expand All @@ -887,11 +890,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 %s to %s\n", walletPath.c_str(), 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.c_str(), pathDest.string().c_str(), e.what());
return false;
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace boost;
void rescanfornames();

CWallet* pwalletMain;
string walletPath;

//////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -406,9 +407,14 @@ bool AppInit2(int argc, char* argv[])
printf("Loading wallet...\n");
nStart = GetTimeMillis();
bool fFirstRun;
pwalletMain = new CWallet("wallet.dat");
string argWalletPath = GetArg("-walletpath", "wallet.dat");
boost::filesystem::path pathWalletFile(argWalletPath);
walletPath = pathWalletFile.string();

pwalletMain = new CWallet(walletPath);
if (!pwalletMain->LoadWallet(fFirstRun))
strErrors += _("Error loading wallet.dat \n");
strErrors += "Error loading " + argWalletPath + " \n";

printf(" wallet %15"PRI64d"ms\n", GetTimeMillis() - nStart);

RegisterWallet(pwalletMain);
Expand All @@ -433,7 +439,7 @@ bool AppInit2(int argc, char* argv[])
pindexRescan = pindexGenesisBlock;
else
{
CWalletDB walletdb("wallet.dat");
CWalletDB walletdb(walletPath);
CBlockLocator locator;
if (walletdb.ReadBestBlock(locator))
pindexRescan = locator.GetBlockIndex();
Expand Down Expand Up @@ -594,6 +600,7 @@ std::string HelpMessage()
std::string strUsage = std::string(_("Options:\n")) +
" -conf=<file> \t\t " + _("Specify configuration file (default: namecoin.conf)\n") +
" -pid=<file> \t\t " + _("Specify pid file (default: namecoind.pid)\n") +
" -walletpath=<file> \t " + _("Specify the wallet filename (default: wallet.dat)") + "\n" +
" -gen \t\t " + _("Generate coins\n") +
" -gen=0 \t\t " + _("Don't generate coins\n") +
" -min \t\t " + _("Start minimized\n") +
Expand Down
1 change: 1 addition & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define BITCOIN_INIT_H

extern CWallet* pwalletMain;
extern std::string walletPath;

void StartShutdown();
void Shutdown(void* parg);
Expand Down
3 changes: 2 additions & 1 deletion src/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "headers.h"
#include "db.h"
#include "init.h"
#include "wallet.h"
#include <boost/filesystem.hpp>

Expand Down Expand Up @@ -184,7 +185,7 @@ bool CWalletDB::LoadWallet(CWallet* pwallet)
wtx.pwallet = pwallet;

if (wtx.GetHash() != hash)
printf("Error in wallet.dat, hash mismatch\n");
printf("Error in %s, hash mismatch\n", walletPath.c_str());

// Undo serialize changes in 31600
if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)
Expand Down

0 comments on commit ca083a9

Please sign in to comment.