Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallettool.cpp
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | static void WalletShowInfo(CWallet *wallet_instance) { | ||||
tfm::format(std::cout, "Keypool Size: %u\n", | tfm::format(std::cout, "Keypool Size: %u\n", | ||||
wallet_instance->GetKeyPoolSize()); | wallet_instance->GetKeyPoolSize()); | ||||
tfm::format(std::cout, "Transactions: %zu\n", | 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) { | |||||
// Create a Database handle to allow for the db to be initialized before | |||||
// recovery | |||||
std::unique_ptr<WalletDatabase> database = CreateWalletDatabase(path); | |||||
// Initialize the environment before recovery | |||||
bilingual_str error_string; | |||||
try { | |||||
database->Verify(error_string); | |||||
} catch (const fs::filesystem_error &e) { | |||||
error_string = | |||||
Untranslated(strprintf("Error loading wallet. %s", | |||||
fsbridge::get_filesystem_error_message(e))); | |||||
} | |||||
if (!error_string.original.empty()) { | |||||
tfm::format(std::cerr, "Failed to open wallet for salvage :%s\n", | |||||
error_string.original); | |||||
return false; | |||||
} | |||||
// Perform the recovery | |||||
return RecoverDatabaseFile(path); | |||||
} | |||||
bool ExecuteWalletToolFunc(const std::string &command, | bool ExecuteWalletToolFunc(const std::string &command, | ||||
const std::string &name) { | const std::string &name) { | ||||
fs::path path = fs::absolute(name, GetWalletDir()); | fs::path path = fs::absolute(name, GetWalletDir()); | ||||
if (command == "create") { | if (command == "create") { | ||||
std::shared_ptr<CWallet> wallet_instance = CreateWallet(name, path); | std::shared_ptr<CWallet> wallet_instance = CreateWallet(name, path); | ||||
if (wallet_instance) { | if (wallet_instance) { | ||||
WalletShowInfo(wallet_instance.get()); | WalletShowInfo(wallet_instance.get()); | ||||
wallet_instance->Flush(true); | wallet_instance->Flush(true); | ||||
} | } | ||||
} else if (command == "info" || command == "salvage") { | } else if (command == "info" || command == "salvage") { | ||||
if (!fs::exists(path)) { | if (!fs::exists(path)) { | ||||
tfm::format(std::cerr, "Error: no wallet file at %s\n", name); | tfm::format(std::cerr, "Error: no wallet file at %s\n", name); | ||||
return false; | return false; | ||||
} | } | ||||
if (command == "info") { | if (command == "info") { | ||||
std::shared_ptr<CWallet> wallet_instance = LoadWallet(name, path); | std::shared_ptr<CWallet> wallet_instance = LoadWallet(name, path); | ||||
if (!wallet_instance) { | if (!wallet_instance) { | ||||
return false; | return false; | ||||
} | } | ||||
WalletShowInfo(wallet_instance.get()); | WalletShowInfo(wallet_instance.get()); | ||||
wallet_instance->Flush(true); | wallet_instance->Flush(true); | ||||
} else if (command == "salvage") { | } else if (command == "salvage") { | ||||
return SalvageWallet(path); | return RecoverDatabaseFile(path); | ||||
} | } | ||||
} else { | } else { | ||||
tfm::format(std::cerr, "Invalid command: %s\n", command); | tfm::format(std::cerr, "Invalid command: %s\n", command); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
} // namespace WalletTool | } // namespace WalletTool |