Skip to content

Commit fae32f2

Browse files
author
MarcoFalke
committed
wallet: Add missing check for -descriptors wallet tool option
1 parent faf8f61 commit fae32f2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
2929
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
3030
argsman.AddArg("-dumpfile=<file name>", "When used with 'dump', writes out the records to this file. When used with 'createfromdump', loads the records into a new wallet.", ArgsManager::ALLOW_STRING, OptionsCategory::OPTIONS);
3131
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
32-
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for create", ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
32+
argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_BOOL, OptionsCategory::OPTIONS);
3333
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);
3434
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
3535

src/wallet/wallettool.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command,
107107
{
108108
fs::path path = fs::absolute(name, GetWalletDir());
109109

110-
// -format is only allowed with createfromdump. Disallow it for all other commands.
111110
if (args.IsArgSet("-format") && command != "createfromdump") {
112111
tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n");
113112
return false;
114113
}
115-
// -dumpfile is only allowed with dump and createfromdump. Disallow it for all other commands.
116114
if (args.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") {
117115
tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
118116
return false;
119117
}
118+
if (args.IsArgSet("-descriptors") && command != "create") {
119+
tfm::format(std::cerr, "The -descriptors option can only be used with the 'create' command.\n");
120+
return false;
121+
}
120122

121123
if (command == "create") {
122124
DatabaseOptions options;

test/functional/tool_wallet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def skip_test_if_missing_module(self):
3131
def bitcoin_wallet_process(self, *args):
3232
binary = self.config["environment"]["BUILDDIR"] + '/src/bitcoin-wallet' + self.config["environment"]["EXEEXT"]
3333
default_args = ['-datadir={}'.format(self.nodes[0].datadir), '-chain=%s' % self.chain]
34-
if self.options.descriptors:
34+
if self.options.descriptors and 'create' in args:
3535
default_args.append('-descriptors')
3636

3737
return subprocess.Popen([binary] + default_args + list(args), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
@@ -344,6 +344,7 @@ def test_dump_createfromdump(self):
344344
self.assert_raises_tool_error('Dump file {} does not exist.'.format(non_exist_dump), '-wallet=todump', '-dumpfile={}'.format(non_exist_dump), 'createfromdump')
345345
wallet_path = os.path.join(self.nodes[0].datadir, 'regtest/wallets/todump2')
346346
self.assert_raises_tool_error('Failed to create database path \'{}\'. Database already exists.'.format(wallet_path), '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
347+
self.assert_raises_tool_error("The -descriptors option can only be used with the 'create' command.", '-descriptors', '-wallet=todump2', '-dumpfile={}'.format(wallet_dump), 'createfromdump')
347348

348349
self.log.info('Checking createfromdump')
349350
self.do_tool_createfromdump("load", "wallet.dump")

0 commit comments

Comments
 (0)