Skip to content

Commit 380498a

Browse files
committed
Move BackupWallet to CWallet::BackupWallet
1 parent ecb9741 commit 380498a

File tree

6 files changed

+44
-43
lines changed

6 files changed

+44
-43
lines changed

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
447447

448448
bool WalletModel::backupWallet(const QString &filename)
449449
{
450-
return BackupWallet(*wallet, filename.toLocal8Bit().data());
450+
return wallet->BackupWallet(filename.toLocal8Bit().data());
451451
}
452452

453453
// Handlers for core signals

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ UniValue backupwallet(const UniValue& params, bool fHelp)
18041804
LOCK2(cs_main, pwalletMain->cs_wallet);
18051805

18061806
string strDest = params[0].get_str();
1807-
if (!BackupWallet(*pwalletMain, strDest))
1807+
if (!pwalletMain->BackupWallet(strDest))
18081808
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!");
18091809

18101810
return NullUniValue;

src/wallet/wallet.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,46 @@ bool CWallet::ParameterInteraction()
32833283
return true;
32843284
}
32853285

3286+
bool CWallet::BackupWallet(const std::string& strDest)
3287+
{
3288+
if (!fFileBacked)
3289+
return false;
3290+
while (true)
3291+
{
3292+
{
3293+
LOCK(bitdb.cs_db);
3294+
if (!bitdb.mapFileUseCount.count(strWalletFile) || bitdb.mapFileUseCount[strWalletFile] == 0)
3295+
{
3296+
// Flush log data to the dat file
3297+
bitdb.CloseDb(strWalletFile);
3298+
bitdb.CheckpointLSN(strWalletFile);
3299+
bitdb.mapFileUseCount.erase(strWalletFile);
3300+
3301+
// Copy wallet file
3302+
boost::filesystem::path pathSrc = GetDataDir() / strWalletFile;
3303+
boost::filesystem::path pathDest(strDest);
3304+
if (boost::filesystem::is_directory(pathDest))
3305+
pathDest /= strWalletFile;
3306+
3307+
try {
3308+
#if BOOST_VERSION >= 104000
3309+
boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
3310+
#else
3311+
boost::filesystem::copy_file(pathSrc, pathDest);
3312+
#endif
3313+
LogPrintf("copied %s to %s\n", strWalletFile, pathDest.string());
3314+
return true;
3315+
} catch (const boost::filesystem::filesystem_error& e) {
3316+
LogPrintf("error copying %s to %s - %s\n", strWalletFile, pathDest.string(), e.what());
3317+
return false;
3318+
}
3319+
}
3320+
}
3321+
MilliSleep(100);
3322+
}
3323+
return false;
3324+
}
3325+
32863326
CKeyPool::CKeyPool()
32873327
{
32883328
nTime = GetTime();

src/wallet/wallet.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
885885

886886
/* Wallets parameter interaction */
887887
static bool ParameterInteraction();
888+
889+
bool BackupWallet(const std::string& strDest);
888890
};
889891

890892
/** A key allocated from the key pool. */

src/wallet/walletdb.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -903,46 +903,6 @@ void ThreadFlushWalletDB(const string& strFile)
903903
}
904904
}
905905

906-
bool BackupWallet(const CWallet& wallet, const string& strDest)
907-
{
908-
if (!wallet.fFileBacked)
909-
return false;
910-
while (true)
911-
{
912-
{
913-
LOCK(bitdb.cs_db);
914-
if (!bitdb.mapFileUseCount.count(wallet.strWalletFile) || bitdb.mapFileUseCount[wallet.strWalletFile] == 0)
915-
{
916-
// Flush log data to the dat file
917-
bitdb.CloseDb(wallet.strWalletFile);
918-
bitdb.CheckpointLSN(wallet.strWalletFile);
919-
bitdb.mapFileUseCount.erase(wallet.strWalletFile);
920-
921-
// Copy wallet file
922-
boost::filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
923-
boost::filesystem::path pathDest(strDest);
924-
if (boost::filesystem::is_directory(pathDest))
925-
pathDest /= wallet.strWalletFile;
926-
927-
try {
928-
#if BOOST_VERSION >= 104000
929-
boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
930-
#else
931-
boost::filesystem::copy_file(pathSrc, pathDest);
932-
#endif
933-
LogPrintf("copied %s to %s\n", wallet.strWalletFile, pathDest.string());
934-
return true;
935-
} catch (const boost::filesystem::filesystem_error& e) {
936-
LogPrintf("error copying %s to %s - %s\n", wallet.strWalletFile, pathDest.string(), e.what());
937-
return false;
938-
}
939-
}
940-
}
941-
MilliSleep(100);
942-
}
943-
return false;
944-
}
945-
946906
//
947907
// Try to (very carefully!) recover wallet file if there is a problem.
948908
//

src/wallet/walletdb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class CWalletDB : public CDB
141141
bool WriteAccountingEntry(const uint64_t nAccEntryNum, const CAccountingEntry& acentry);
142142
};
143143

144-
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
145144
void ThreadFlushWalletDB(const std::string& strFile);
146145

147146
#endif // BITCOIN_WALLET_WALLETDB_H

0 commit comments

Comments
 (0)