Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallettool.cpp
Show All 26 Lines | static std::shared_ptr<CWallet> CreateWallet(const std::string &name, | ||||
const fs::path &path) { | const fs::path &path) { | ||||
if (fs::exists(path)) { | if (fs::exists(path)) { | ||||
tfm::format(std::cerr, "Error: File exists already\n"); | tfm::format(std::cerr, "Error: File exists already\n"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// dummy chain interface | // dummy chain interface | ||||
std::shared_ptr<CWallet> wallet_instance( | std::shared_ptr<CWallet> wallet_instance( | ||||
new CWallet(nullptr /* chain */, WalletLocation(name), | new CWallet(nullptr /* chain */, WalletLocation(name), | ||||
WalletDatabase::Create(path)), | CreateWalletDatabase(path)), | ||||
WalletToolReleaseWallet); | WalletToolReleaseWallet); | ||||
LOCK(wallet_instance->cs_wallet); | LOCK(wallet_instance->cs_wallet); | ||||
bool first_run = true; | bool first_run = true; | ||||
DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run); | DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run); | ||||
if (load_wallet_ret != DBErrors::LOAD_OK) { | if (load_wallet_ret != DBErrors::LOAD_OK) { | ||||
tfm::format(std::cerr, "Error creating %s", name); | tfm::format(std::cerr, "Error creating %s", name); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
Show All 15 Lines | static std::shared_ptr<CWallet> LoadWallet(const std::string &name, | ||||
if (!fs::exists(path)) { | if (!fs::exists(path)) { | ||||
tfm::format(std::cerr, "Error: Wallet files does not exist\n"); | tfm::format(std::cerr, "Error: Wallet files does not exist\n"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// dummy chain interface | // dummy chain interface | ||||
std::shared_ptr<CWallet> wallet_instance( | std::shared_ptr<CWallet> wallet_instance( | ||||
new CWallet(nullptr /* chain */, WalletLocation(name), | new CWallet(nullptr /* chain */, WalletLocation(name), | ||||
WalletDatabase::Create(path)), | CreateWalletDatabase(path)), | ||||
WalletToolReleaseWallet); | WalletToolReleaseWallet); | ||||
DBErrors load_wallet_ret; | DBErrors load_wallet_ret; | ||||
try { | try { | ||||
bool first_run; | bool first_run; | ||||
load_wallet_ret = wallet_instance->LoadWallet(first_run); | load_wallet_ret = wallet_instance->LoadWallet(first_run); | ||||
} catch (const std::runtime_error &) { | } catch (const std::runtime_error &) { | ||||
tfm::format( | tfm::format( | ||||
std::cerr, | std::cerr, | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | tfm::format(std::cout, "Transactions: %zu\n", | ||||
wallet_instance->mapWallet.size()); | wallet_instance->mapWallet.size()); | ||||
tfm::format(std::cout, "Address Book: %zu\n", | tfm::format(std::cout, "Address Book: %zu\n", | ||||
wallet_instance->m_address_book.size()); | wallet_instance->m_address_book.size()); | ||||
} | } | ||||
static bool SalvageWallet(const fs::path &path) { | static bool SalvageWallet(const fs::path &path) { | ||||
// Create a Database handle to allow for the db to be initialized before | // Create a Database handle to allow for the db to be initialized before | ||||
// recovery | // recovery | ||||
std::unique_ptr<WalletDatabase> database = WalletDatabase::Create(path); | std::unique_ptr<WalletDatabase> database = CreateWalletDatabase(path); | ||||
// Initialize the environment before recovery | // Initialize the environment before recovery | ||||
bilingual_str error_string; | bilingual_str error_string; | ||||
try { | try { | ||||
database->Verify(error_string); | database->Verify(error_string); | ||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
error_string = | error_string = | ||||
Untranslated(strprintf("Error loading wallet. %s", | Untranslated(strprintf("Error loading wallet. %s", | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |