Skip to content

Commit b27104d

Browse files
author
MarcoFalke
committed
Merge #20687: wallet: Add missing check for -descriptors wallet tool option
fae32f2 wallet: Add missing check for -descriptors wallet tool option (MarcoFalke) faf8f61 test: Add missing check for is_sqlite_compiled (MarcoFalke) fa7dde1 wallet: Pass ArgsManager into ExecuteWalletToolFunc instead of using global (MarcoFalke) Pull request description: Also, fix a test failure when compiled without sqlite ACKs for top commit: ryanofsky: Code review ACK fae32f2. Thanks for implementing the -descriptors check and dealing with the test failure! jonatack: Code review utACK fae32f2 Tree-SHA512: 3d7710694085822739a8316e4abc6db270799ca6ff6b0f9e5563ae240da65ae6a9cab7ba2647feae6ba540dac40b55b38ed41c8f6ed0bf02a3d1536284448927
2 parents 9b28bd7 + fae32f2 commit b27104d

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/bitcoin-wallet.cpp

Lines changed: 3 additions & 2 deletions
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

@@ -120,8 +120,9 @@ int main(int argc, char* argv[])
120120

121121
ECCVerifyHandle globalVerifyHandle;
122122
ECC_Start();
123-
if (!WalletTool::ExecuteWalletToolFunc(method, name))
123+
if (!WalletTool::ExecuteWalletToolFunc(gArgs, method, name)) {
124124
return EXIT_FAILURE;
125+
}
125126
ECC_Stop();
126127
return EXIT_SUCCESS;
127128
}

src/wallet/wallettool.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,27 @@ static void WalletShowInfo(CWallet* wallet_instance)
103103
tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->m_address_book.size());
104104
}
105105

106-
bool ExecuteWalletToolFunc(const std::string& command, const std::string& name)
106+
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command, const std::string& name)
107107
{
108108
fs::path path = fs::absolute(name, GetWalletDir());
109109

110-
// -format is only allowed with createfromdump. Disallow it for all other commands.
111-
if (gArgs.IsArgSet("-format") && command != "createfromdump") {
110+
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.
116-
if (gArgs.IsArgSet("-dumpfile") && command != "dump" && command != "createfromdump") {
114+
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;
123125
options.require_create = true;
124-
if (gArgs.GetBoolArg("-descriptors", false)) {
126+
if (args.GetBoolArg("-descriptors", false)) {
125127
options.create_flags |= WALLET_FLAG_DESCRIPTORS;
126128
options.require_format = DatabaseFormat::SQLITE;
127129
}

src/wallet/wallettool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace WalletTool {
1111

1212
void WalletShowInfo(CWallet* wallet_instance);
13-
bool ExecuteWalletToolFunc(const std::string& command, const std::string& file);
13+
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command, const std::string& file);
1414

1515
} // namespace WalletTool
1616

test/functional/tool_wallet.py

Lines changed: 4 additions & 2 deletions
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,11 +344,13 @@ 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")
350351
self.do_tool_createfromdump("load-bdb", "wallet.dump", "bdb")
351-
self.do_tool_createfromdump("load-sqlite", "wallet.dump", "sqlite")
352+
if self.is_sqlite_compiled():
353+
self.do_tool_createfromdump("load-sqlite", "wallet.dump", "sqlite")
352354

353355
self.log.info('Checking createfromdump handling of magic and versions')
354356
bad_ver_wallet_dump = os.path.join(self.nodes[0].datadir, "wallet-bad_ver1.dump")

0 commit comments

Comments
 (0)