mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
wallet: Remove -format and bdb from wallet tool's createfromdump
This commit is contained in:
parent
c847dee148
commit
7a41c939f0
4 changed files with 8 additions and 35 deletions
|
@ -40,7 +40,6 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
|
||||||
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||||
argsman.AddArg("-format=<format>", "The format of the wallet file to create. Either \"bdb\" or \"sqlite\". Only used with 'createfromdump'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
|
||||||
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
argsman.AddArg("-withinternalbdb", "Use the internal Berkeley DB parser when dumping a Berkeley DB wallet file (default: false)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
argsman.AddArg("-withinternalbdb", "Use the internal Berkeley DB parser when dumping a Berkeley DB wallet file (default: false)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||||
|
|
||||||
|
|
|
@ -175,26 +175,14 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
|
||||||
dump_file.close();
|
dump_file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get the data file format with format_value as the default
|
// Make sure that the dump was created from a sqlite database only as that is the only
|
||||||
std::string file_format = args.GetArg("-format", format_value);
|
// type of database that we still support.
|
||||||
if (file_format.empty()) {
|
// Other formats such as BDB should not be loaded into a sqlite database since they also
|
||||||
error = _("No wallet file format provided. To use createfromdump, -format=<format> must be provided.");
|
// use a different type of wallet entirely which is no longer compatible with this software.
|
||||||
|
if (format_value != "sqlite") {
|
||||||
|
error = strprintf(_("Error: Dumpfile specifies an unsupported database format (%s). Only sqlite database dumps are supported"), format_value);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DatabaseFormat data_format;
|
|
||||||
if (file_format == "bdb") {
|
|
||||||
data_format = DatabaseFormat::BERKELEY;
|
|
||||||
} else if (file_format == "sqlite") {
|
|
||||||
data_format = DatabaseFormat::SQLITE;
|
|
||||||
} else if (file_format == "bdb_swap") {
|
|
||||||
data_format = DatabaseFormat::BERKELEY_SWAP;
|
|
||||||
} else {
|
|
||||||
error = strprintf(_("Unknown wallet file format \"%s\" provided. Please provide one of \"bdb\" or \"sqlite\"."), file_format);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (file_format != format_value) {
|
|
||||||
warnings.push_back(strprintf(_("Warning: Dumpfile wallet format \"%s\" does not match command line specified format \"%s\"."), format_value, file_format));
|
|
||||||
}
|
|
||||||
std::string format_hasher_line = strprintf("%s,%s\n", format_key, format_value);
|
std::string format_hasher_line = strprintf("%s,%s\n", format_key, format_value);
|
||||||
hasher << std::span{format_hasher_line};
|
hasher << std::span{format_hasher_line};
|
||||||
|
|
||||||
|
@ -202,7 +190,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
|
||||||
DatabaseStatus status;
|
DatabaseStatus status;
|
||||||
ReadDatabaseArgs(args, options);
|
ReadDatabaseArgs(args, options);
|
||||||
options.require_create = true;
|
options.require_create = true;
|
||||||
options.require_format = data_format;
|
options.require_format = DatabaseFormat::SQLITE;
|
||||||
std::unique_ptr<WalletDatabase> database = MakeDatabase(wallet_path, options, status, error);
|
std::unique_ptr<WalletDatabase> database = MakeDatabase(wallet_path, options, status, error);
|
||||||
if (!database) return false;
|
if (!database) return false;
|
||||||
|
|
||||||
|
|
|
@ -112,10 +112,6 @@ static void WalletShowInfo(CWallet* wallet_instance)
|
||||||
|
|
||||||
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
|
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
|
||||||
{
|
{
|
||||||
if (args.IsArgSet("-format") && command != "createfromdump") {
|
|
||||||
tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (args.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") {
|
if (args.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") {
|
||||||
tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
|
tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -145,21 +145,15 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
for k, v in e.items():
|
for k, v in e.items():
|
||||||
assert_equal(v, r[k])
|
assert_equal(v, r[k])
|
||||||
|
|
||||||
def do_tool_createfromdump(self, wallet_name, dumpfile, file_format=None):
|
def do_tool_createfromdump(self, wallet_name, dumpfile):
|
||||||
dumppath = self.nodes[0].datadir_path / dumpfile
|
dumppath = self.nodes[0].datadir_path / dumpfile
|
||||||
rt_dumppath = self.nodes[0].datadir_path / "rt-{}.dump".format(wallet_name)
|
rt_dumppath = self.nodes[0].datadir_path / "rt-{}.dump".format(wallet_name)
|
||||||
|
|
||||||
dump_data = self.read_dump(dumppath)
|
|
||||||
|
|
||||||
args = ["-wallet={}".format(wallet_name),
|
args = ["-wallet={}".format(wallet_name),
|
||||||
"-dumpfile={}".format(dumppath)]
|
"-dumpfile={}".format(dumppath)]
|
||||||
if file_format is not None:
|
|
||||||
args.append("-format={}".format(file_format))
|
|
||||||
args.append("createfromdump")
|
args.append("createfromdump")
|
||||||
|
|
||||||
load_output = ""
|
load_output = ""
|
||||||
if file_format is not None and file_format != dump_data["format"]:
|
|
||||||
load_output += "Warning: Dumpfile wallet format \"{}\" does not match command line specified format \"{}\".\n".format(dump_data["format"], file_format)
|
|
||||||
self.assert_tool_output(load_output, *args)
|
self.assert_tool_output(load_output, *args)
|
||||||
assert (self.nodes[0].wallets_path / wallet_name).is_dir()
|
assert (self.nodes[0].wallets_path / wallet_name).is_dir()
|
||||||
|
|
||||||
|
@ -316,7 +310,6 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
self.log.info('Checking createfromdump arguments')
|
self.log.info('Checking createfromdump arguments')
|
||||||
self.assert_raises_tool_error('No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.', '-wallet=todump', 'createfromdump')
|
self.assert_raises_tool_error('No dump file provided. To use createfromdump, -dumpfile=<filename> must be provided.', '-wallet=todump', 'createfromdump')
|
||||||
non_exist_dump = self.nodes[0].datadir_path / "wallet.nodump"
|
non_exist_dump = self.nodes[0].datadir_path / "wallet.nodump"
|
||||||
self.assert_raises_tool_error('Unknown wallet file format "notaformat" provided. Please provide one of "bdb" or "sqlite".', '-wallet=todump', '-format=notaformat', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
|
|
||||||
self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump')
|
self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump')
|
||||||
wallet_path = self.nodes[0].wallets_path / "todump2"
|
wallet_path = self.nodes[0].wallets_path / "todump2"
|
||||||
self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
|
self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
|
||||||
|
@ -324,9 +317,6 @@ class ToolWalletTest(BitcoinTestFramework):
|
||||||
|
|
||||||
self.log.info('Checking createfromdump')
|
self.log.info('Checking createfromdump')
|
||||||
self.do_tool_createfromdump("load", "wallet.dump")
|
self.do_tool_createfromdump("load", "wallet.dump")
|
||||||
if self.is_bdb_compiled():
|
|
||||||
self.do_tool_createfromdump("load-bdb", "wallet.dump", "bdb")
|
|
||||||
self.do_tool_createfromdump("load-sqlite", "wallet.dump", "sqlite")
|
|
||||||
|
|
||||||
self.log.info('Checking createfromdump handling of magic and versions')
|
self.log.info('Checking createfromdump handling of magic and versions')
|
||||||
bad_ver_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_ver1.dump"
|
bad_ver_wallet_dump = self.nodes[0].datadir_path / "wallet-bad_ver1.dump"
|
||||||
|
|
Loading…
Add table
Reference in a new issue