Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
static const size_t OUTPUT_GROUP_MAX_ENTRIES = 10; | static const size_t OUTPUT_GROUP_MAX_ENTRIES = 10; | ||||
std::shared_ptr<CWallet> LoadWallet(const CChainParams &chainParams, | std::shared_ptr<CWallet> LoadWallet(const CChainParams &chainParams, | ||||
interfaces::Chain &chain, | interfaces::Chain &chain, | ||||
const WalletLocation &location, | const WalletLocation &location, | ||||
bilingual_str &error, | bilingual_str &error, | ||||
std::vector<bilingual_str> &warnings) { | std::vector<bilingual_str> &warnings) { | ||||
if (!CWallet::Verify(chainParams, chain, location, false, error, | if (!CWallet::Verify(chainParams, chain, location, error, warnings)) { | ||||
warnings)) { | |||||
error = Untranslated("Wallet file verification failed.") + | error = Untranslated("Wallet file verification failed.") + | ||||
Untranslated(" ") + error; | Untranslated(" ") + error; | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> wallet = CWallet::CreateWalletFromFile( | ||||
chainParams, chain, location, error, warnings); | chainParams, chain, location, error, warnings); | ||||
if (!wallet) { | if (!wallet) { | ||||
Show All 36 Lines | WalletCreationStatus CreateWallet(const CChainParams ¶ms, | ||||
if (location.Exists()) { | if (location.Exists()) { | ||||
error = strprintf(Untranslated("Wallet %s already exists."), | error = strprintf(Untranslated("Wallet %s already exists."), | ||||
location.GetName()); | location.GetName()); | ||||
return WalletCreationStatus::CREATION_FAILED; | return WalletCreationStatus::CREATION_FAILED; | ||||
} | } | ||||
// Wallet::Verify will check if we're trying to create a wallet with a | // Wallet::Verify will check if we're trying to create a wallet with a | ||||
// duplicate name. | // duplicate name. | ||||
if (!CWallet::Verify(params, chain, location, false, error, warnings)) { | if (!CWallet::Verify(params, chain, location, error, warnings)) { | ||||
error = Untranslated("Wallet file verification failed.") + | error = Untranslated("Wallet file verification failed.") + | ||||
Untranslated(" ") + error; | Untranslated(" ") + error; | ||||
return WalletCreationStatus::CREATION_FAILED; | return WalletCreationStatus::CREATION_FAILED; | ||||
} | } | ||||
// Do not allow a passphrase when private keys are disabled | // Do not allow a passphrase when private keys are disabled | ||||
if (!passphrase.empty() && | if (!passphrase.empty() && | ||||
(wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { | ||||
▲ Show 20 Lines • Show All 3,877 Lines • ▼ Show 20 Lines | for (const auto &address : m_address_book) { | ||||
values.emplace_back(data.second); | values.emplace_back(data.second); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return values; | return values; | ||||
} | } | ||||
bool CWallet::Verify(const CChainParams &chainParams, interfaces::Chain &chain, | bool CWallet::Verify(const CChainParams &chainParams, interfaces::Chain &chain, | ||||
const WalletLocation &location, bool salvage_wallet, | const WalletLocation &location, | ||||
bilingual_str &error_string, | bilingual_str &error_string, | ||||
std::vector<bilingual_str> &warnings) { | std::vector<bilingual_str> &warnings) { | ||||
// Do some checking on wallet path. It should be either a: | // Do some checking on wallet path. It should be either a: | ||||
// | // | ||||
// 1. Path where a directory can be created. | // 1. Path where a directory can be created. | ||||
// 2. Path to an existing directory. | // 2. Path to an existing directory. | ||||
// 3. Path to a symlink to a directory. | // 3. Path to a symlink to a directory. | ||||
// 4. For backwards compatibility, the name of a data file in -walletdir. | // 4. For backwards compatibility, the name of a data file in -walletdir. | ||||
Show All 34 Lines | try { | ||||
} | } | ||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
error_string = Untranslated( | error_string = Untranslated( | ||||
strprintf("Error loading wallet %s. %s", location.GetName(), | strprintf("Error loading wallet %s. %s", location.GetName(), | ||||
fsbridge::get_filesystem_error_message(e))); | fsbridge::get_filesystem_error_message(e))); | ||||
return false; | return false; | ||||
} | } | ||||
if (salvage_wallet) { | |||||
// Recover readable keypairs: | |||||
CWallet dummyWallet(chainParams, &chain, WalletLocation(), | |||||
WalletDatabase::CreateDummy()); | |||||
std::string backup_filename; | |||||
if (!WalletBatch::Recover( | |||||
wallet_path, static_cast<void *>(&dummyWallet), | |||||
WalletBatch::RecoverKeysOnlyFilter, backup_filename)) { | |||||
return false; | |||||
} | |||||
} | |||||
return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string); | return WalletBatch::VerifyDatabaseFile(wallet_path, warnings, error_string); | ||||
} | } | ||||
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | ||||
const CChainParams &chainParams, interfaces::Chain &chain, | const CChainParams &chainParams, interfaces::Chain &chain, | ||||
const WalletLocation &location, bilingual_str &error, | const WalletLocation &location, bilingual_str &error, | ||||
std::vector<bilingual_str> &warnings, uint64_t wallet_creation_flags) { | std::vector<bilingual_str> &warnings, uint64_t wallet_creation_flags) { | ||||
const std::string walletFile = | const std::string walletFile = | ||||
▲ Show 20 Lines • Show All 882 Lines • Show Last 20 Lines |