Browse Source

Move BackupWallet to CWallet::BackupWallet

0.13
Patrick Strateman 9 years ago
parent
commit
380498aba4
  1. 2
      src/qt/walletmodel.cpp
  2. 2
      src/wallet/rpcwallet.cpp
  3. 40
      src/wallet/wallet.cpp
  4. 2
      src/wallet/wallet.h
  5. 40
      src/wallet/walletdb.cpp
  6. 1
      src/wallet/walletdb.h

2
src/qt/walletmodel.cpp

@ -447,7 +447,7 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri @@ -447,7 +447,7 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
bool WalletModel::backupWallet(const QString &filename)
{
return BackupWallet(*wallet, filename.toLocal8Bit().data());
return wallet->BackupWallet(filename.toLocal8Bit().data());
}
// Handlers for core signals

2
src/wallet/rpcwallet.cpp

@ -1804,7 +1804,7 @@ UniValue backupwallet(const UniValue& params, bool fHelp) @@ -1804,7 +1804,7 @@ UniValue backupwallet(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet);
string strDest = params[0].get_str();
if (!BackupWallet(*pwalletMain, strDest))
if (!pwalletMain->BackupWallet(strDest))
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
return NullUniValue;

40
src/wallet/wallet.cpp

@ -3283,6 +3283,46 @@ bool CWallet::ParameterInteraction() @@ -3283,6 +3283,46 @@ bool CWallet::ParameterInteraction()
return true;
}
bool CWallet::BackupWallet(const std::string& strDest)
{
if (!fFileBacked)
return false;
while (true)
{
{
LOCK(bitdb.cs_db);
if (!bitdb.mapFileUseCount.count(strWalletFile) || bitdb.mapFileUseCount[strWalletFile] == 0)
{
// Flush log data to the dat file
bitdb.CloseDb(strWalletFile);
bitdb.CheckpointLSN(strWalletFile);
bitdb.mapFileUseCount.erase(strWalletFile);
// Copy wallet file
boost::filesystem::path pathSrc = GetDataDir() / strWalletFile;
boost::filesystem::path pathDest(strDest);
if (boost::filesystem::is_directory(pathDest))
pathDest /= strWalletFile;
try {
#if BOOST_VERSION >= 104000
boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
#else
boost::filesystem::copy_file(pathSrc, pathDest);
#endif
LogPrintf("copied %s to %s\n", strWalletFile, pathDest.string());
return true;
} catch (const boost::filesystem::filesystem_error& e) {
LogPrintf("error copying %s to %s - %s\n", strWalletFile, pathDest.string(), e.what());
return false;
}
}
}
MilliSleep(100);
}
return false;
}
CKeyPool::CKeyPool()
{
nTime = GetTime();

2
src/wallet/wallet.h

@ -885,6 +885,8 @@ public: @@ -885,6 +885,8 @@ public:
/* Wallets parameter interaction */
static bool ParameterInteraction();
bool BackupWallet(const std::string& strDest);
};
/** A key allocated from the key pool. */

40
src/wallet/walletdb.cpp

@ -903,46 +903,6 @@ void ThreadFlushWalletDB(const string& strFile) @@ -903,46 +903,6 @@ void ThreadFlushWalletDB(const string& strFile)
}
}
bool BackupWallet(const CWallet& wallet, const string& strDest)
{
if (!wallet.fFileBacked)
return false;
while (true)
{
{
LOCK(bitdb.cs_db);
if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
{
// Flush log data to the dat file
bitdb.CloseDb(wallet.strWalletFile);
bitdb.CheckpointLSN(wallet.strWalletFile);
bitdb.mapFileUseCount.erase(wallet.strWalletFile);
// Copy wallet file
boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
boost::filesystem::path pathDest(strDest);
if (boost::filesystem::is_directory(pathDest))
pathDest /= wallet.strWalletFile;
try {
#if BOOST_VERSION >= 104000
boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
#else
boost::filesystem::copy_file(pathSrc, pathDest);
#endif
LogPrintf("copied %s to %s\n", wallet.strWalletFile, pathDest.string());
return true;
} catch (const boost::filesystem::filesystem_error& e) {
LogPrintf("error copying %s to %s - %s\n", wallet.strWalletFile, pathDest.string(), e.what());
return false;
}
}
}
MilliSleep(100);
}
return false;
}
//
// Try to (very carefully!) recover wallet file if there is a problem.
//

1
src/wallet/walletdb.h

@ -141,7 +141,6 @@ private: @@ -141,7 +141,6 @@ private:
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
};
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
void ThreadFlushWalletDB(const std::string& strFile);
#endif // BITCOIN_WALLET_WALLETDB_H

Loading…
Cancel
Save