Wallet: Pass dump_filename to DumpWallet as an argument

This commit is contained in:
Luke Dashjr 2021-02-27 16:36:53 +00:00
parent 55bd5d8015
commit 111058215c
3 changed files with 11 additions and 10 deletions

View File

@ -21,15 +21,8 @@ namespace wallet {
static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP"; static const std::string DUMP_MAGIC = "BITCOIN_CORE_WALLET_DUMP";
uint32_t DUMP_VERSION = 1; uint32_t DUMP_VERSION = 1;
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error) bool DumpWallet(WalletDatabase& db, bilingual_str& error, const std::string& dump_filename)
{ {
// Get the dumpfile
std::string dump_filename = args.GetArg("-dumpfile", "");
if (dump_filename.empty()) {
error = _("No dump file provided. To use dump, -dumpfile=<filename> must be provided.");
return false;
}
fs::path path = fs::PathFromString(dump_filename); fs::path path = fs::PathFromString(dump_filename);
path = fs::absolute(path); path = fs::absolute(path);
if (fs::exists(path)) { if (fs::exists(path)) {

View File

@ -16,7 +16,7 @@ class ArgsManager;
namespace wallet { namespace wallet {
class WalletDatabase; class WalletDatabase;
bool DumpWallet(const ArgsManager& args, WalletDatabase& db, bilingual_str& error); bool DumpWallet(WalletDatabase& db, bilingual_str& error, const std::string& dump_filename);
bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings); bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::path& wallet_path, bilingual_str& error, std::vector<bilingual_str>& warnings);
} // namespace wallet } // namespace wallet

View File

@ -193,6 +193,14 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
DatabaseOptions options; DatabaseOptions options;
ReadDatabaseArgs(args, options); ReadDatabaseArgs(args, options);
options.require_existing = true; options.require_existing = true;
// Get the dumpfile
std::string dump_filename = args.GetArg("-dumpfile", "");
if (dump_filename.empty()) {
tfm::format(std::cerr, "No dump file provided. To use dump, -dumpfile=<filename> must be provided.\n");
return false;
}
DatabaseStatus status; DatabaseStatus status;
bilingual_str error; bilingual_str error;
std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error); std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error);
@ -201,7 +209,7 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
return false; return false;
} }
bool ret = DumpWallet(args, *database, error); bool ret = DumpWallet(*database, error, dump_filename);
if (!ret && !error.empty()) { if (!ret && !error.empty()) {
tfm::format(std::cerr, "%s\n", error.original); tfm::format(std::cerr, "%s\n", error.original);
return ret; return ret;