Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/load.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <wallet/load.h> | #include <wallet/load.h> | ||||
#include <interfaces/chain.h> | #include <interfaces/chain.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/string.h> | #include <util/string.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletdb.h> | #include <wallet/walletdb.h> | ||||
bool VerifyWallets(const CChainParams &chainParams, interfaces::Chain &chain, | bool VerifyWallets(interfaces::Chain &chain, | ||||
const std::vector<std::string> &wallet_files) { | const std::vector<std::string> &wallet_files) { | ||||
if (gArgs.IsArgSet("-walletdir")) { | if (gArgs.IsArgSet("-walletdir")) { | ||||
fs::path wallet_dir = gArgs.GetArg("-walletdir", ""); | fs::path wallet_dir = gArgs.GetArg("-walletdir", ""); | ||||
boost::system::error_code error; | boost::system::error_code error; | ||||
// The canonical path cleans the path, preventing >1 Berkeley | // The canonical path cleans the path, preventing >1 Berkeley | ||||
// environment instances for the same directory | // environment instances for the same directory | ||||
fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error); | fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error); | ||||
if (error || !fs::exists(wallet_dir)) { | if (error || !fs::exists(wallet_dir)) { | ||||
Show All 31 Lines | for (const auto &wallet_file : wallet_files) { | ||||
chain.initError(strprintf(_("Error loading wallet %s. Duplicate " | chain.initError(strprintf(_("Error loading wallet %s. Duplicate " | ||||
"-wallet filename specified."), | "-wallet filename specified."), | ||||
wallet_file)); | wallet_file)); | ||||
return false; | return false; | ||||
} | } | ||||
bilingual_str error_string; | bilingual_str error_string; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
bool verify_success = CWallet::Verify(chainParams, chain, location, | bool verify_success = | ||||
error_string, warnings); | CWallet::Verify(chain, location, error_string, warnings); | ||||
if (!warnings.empty()) { | if (!warnings.empty()) { | ||||
chain.initWarning(Join(warnings, Untranslated("\n"))); | chain.initWarning(Join(warnings, Untranslated("\n"))); | ||||
} | } | ||||
if (!verify_success) { | if (!verify_success) { | ||||
chain.initError(error_string); | chain.initError(error_string); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool LoadWallets(const CChainParams &chainParams, interfaces::Chain &chain, | bool LoadWallets(interfaces::Chain &chain, | ||||
const std::vector<std::string> &wallet_files) { | const std::vector<std::string> &wallet_files) { | ||||
try { | try { | ||||
for (const std::string &walletFile : wallet_files) { | for (const std::string &walletFile : wallet_files) { | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile( | ||||
chainParams, chain, WalletLocation(walletFile), error, | chain, WalletLocation(walletFile), error, warnings); | ||||
warnings); | |||||
if (!warnings.empty()) { | if (!warnings.empty()) { | ||||
chain.initWarning(Join(warnings, Untranslated("\n"))); | chain.initWarning(Join(warnings, Untranslated("\n"))); | ||||
} | } | ||||
if (!pwallet) { | if (!pwallet) { | ||||
chain.initError(error); | chain.initError(error); | ||||
return false; | return false; | ||||
} | } | ||||
AddWallet(pwallet); | AddWallet(pwallet); | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |