wallettool: Add createfromdump command

Creates a new wallet file using the dump file produced by the dump
command
This commit is contained in:
Andrew Chow
2020-06-01 18:00:22 -04:00
parent e1e7a90d5f
commit a88c320041
4 changed files with 208 additions and 1 deletions

View File

@@ -107,6 +107,11 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
{
fs::path path = fs::absolute(name, GetWalletDir());
// -format is only allowed with createfromdump. Disallow it for all other commands.
if (gArgs.IsArgSet("-format") && command != "createfromdump") {
tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n");
return false;
}
// -dumpfile is only allowed with dump and createfromdump. Disallow it for all other commands.
if (gArgs.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") {
tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
@@ -164,6 +169,17 @@ bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
}
tfm::format(std::cout, "The dumpfile may contain private keys. To ensure the safety of your Bitcoin, do not share the dumpfile.\n");
return ret;
} else if (command == "createfromdump") {
bilingual_str error;
std::vector<bilingual_str> warnings;
bool ret = CreateFromDump(name, path, error, warnings);
for (const auto& warning : warnings) {
tfm::format(std::cout, "%s\n", warning.original);
}
if (!ret && !error.empty()) {
tfm::format(std::cerr, "%s\n", error.original);
}
return ret;
} else {
tfm::format(std::cerr, "Invalid command: %s\n", command);
return false;