Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallettool.cpp
Show All 13 Lines | |||||
namespace WalletTool { | namespace WalletTool { | ||||
// The standard wallet deleter function blocks on the validation interface | // The standard wallet deleter function blocks on the validation interface | ||||
// queue, which doesn't exist for the bitcoin-wallet. Define our own | // queue, which doesn't exist for the bitcoin-wallet. Define our own | ||||
// deleter here. | // deleter here. | ||||
static void WalletToolReleaseWallet(CWallet *wallet) { | static void WalletToolReleaseWallet(CWallet *wallet) { | ||||
wallet->WalletLogPrintf("Releasing wallet\n"); | wallet->WalletLogPrintf("Releasing wallet\n"); | ||||
wallet->Flush(true); | wallet->Close(); | ||||
delete wallet; | delete wallet; | ||||
} | } | ||||
static std::shared_ptr<CWallet> CreateWallet(const std::string &name, | 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; | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | |||||
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->Close(); | ||||
} | } | ||||
} 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->Close(); | ||||
} else if (command == "salvage") { | } else if (command == "salvage") { | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
bool ret = RecoverDatabaseFile(path, error, warnings); | bool ret = RecoverDatabaseFile(path, error, warnings); | ||||
if (!ret) { | if (!ret) { | ||||
for (const auto &warning : warnings) { | for (const auto &warning : warnings) { | ||||
tfm::format(std::cerr, "%s\n", warning.original); | tfm::format(std::cerr, "%s\n", warning.original); | ||||
} | } | ||||
Show All 14 Lines |