Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show All 28 Lines | |||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util.h> | #include <util.h> | ||||
#include <utilmoneystr.h> | #include <utilmoneystr.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/coinselection.h> | #include <wallet/coinselection.h> | ||||
#include <wallet/fees.h> | #include <wallet/fees.h> | ||||
#include <wallet/finaltx.h> | #include <wallet/finaltx.h> | ||||
#include <wallet/walletutil.h> | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <future> | #include <future> | ||||
static CCriticalSection cs_wallets; | static CCriticalSection cs_wallets; | ||||
▲ Show 20 Lines • Show All 4,177 Lines • ▼ Show 20 Lines | for (const auto &address : mapAddressBook) { | ||||
if (!data.first.compare(0, prefix.size(), prefix)) { | if (!data.first.compare(0, prefix.size(), prefix)) { | ||||
values.emplace_back(data.second); | values.emplace_back(data.second); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return values; | return values; | ||||
} | } | ||||
bool CWallet::Verify(const CChainParams &chainParams, std::string wallet_file, | |||||
bool salvage_wallet) { | |||||
// Do some checking on wallet path. It should be either a: | |||||
// | |||||
// 1. Path where a directory can be created. | |||||
// 2. Path to an existing directory. | |||||
// 3. Path to a symlink to a directory. | |||||
// 4. For backwards compatibility, the name of a data file in -walletdir. | |||||
LOCK(cs_wallets); | |||||
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir()); | |||||
fs::file_type path_type = fs::symlink_status(wallet_path).type(); | |||||
if (!(path_type == fs::file_not_found || path_type == fs::directory_file || | |||||
(path_type == fs::symlink_file && fs::is_directory(wallet_path)) || | |||||
(path_type == fs::regular_file && | |||||
fs::path(wallet_file).filename() == wallet_file))) { | |||||
return InitError( | |||||
strprintf(_("Invalid -wallet path '%s'. -wallet path should point " | |||||
"to a directory where wallet.dat and " | |||||
"database/log.?????????? files can be stored, a " | |||||
"location where such a directory could be created, " | |||||
"or (for backwards compatibility) the name of an " | |||||
"existing data file in -walletdir (%s)"), | |||||
wallet_file, GetWalletDir())); | |||||
} | |||||
// Make sure that the wallet path doesn't clash with an existing wallet path | |||||
for (auto wallet : GetWallets()) { | |||||
if (fs::absolute(wallet->GetName(), GetWalletDir()) == wallet_path) { | |||||
return InitError(strprintf(_("Error loading wallet %s. Duplicate " | |||||
"-wallet filename specified."), | |||||
wallet_file)); | |||||
} | |||||
} | |||||
std::string strError; | |||||
if (!WalletBatch::VerifyEnvironment(wallet_path, strError)) { | |||||
return InitError(strError); | |||||
} | |||||
if (salvage_wallet) { | |||||
// Recover readable keypairs: | |||||
CWallet dummyWallet(chainParams, "dummy", | |||||
WalletDatabase::CreateDummy()); | |||||
std::string backup_filename; | |||||
if (!WalletBatch::Recover( | |||||
wallet_path, static_cast<void *>(&dummyWallet), | |||||
WalletBatch::RecoverKeysOnlyFilter, backup_filename)) { | |||||
return false; | |||||
} | |||||
} | |||||
std::string strWarning; | |||||
bool dbV = | |||||
WalletBatch::VerifyDatabaseFile(wallet_path, strWarning, strError); | |||||
if (!strWarning.empty()) { | |||||
InitWarning(strWarning); | |||||
} | |||||
if (!dbV) { | |||||
InitError(strError); | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
CWallet *CWallet::CreateWalletFromFile(const CChainParams &chainParams, | CWallet *CWallet::CreateWalletFromFile(const CChainParams &chainParams, | ||||
const std::string &name, | const std::string &name, | ||||
const fs::path &path) { | const fs::path &path) { | ||||
const std::string &walletFile = name; | const std::string &walletFile = name; | ||||
// Needed to restore wallet transaction meta data after -zapwallettxes | // Needed to restore wallet transaction meta data after -zapwallettxes | ||||
std::vector<CWalletTx> vWtx; | std::vector<CWalletTx> vWtx; | ||||
▲ Show 20 Lines • Show All 456 Lines • Show Last 20 Lines |