Skip to content

Commit 6b24727

Browse files
committed
wallet: Disallow legacy wallet creation from the wallet tool
1 parent 5e93b1f commit 6b24727

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/wallet/wallettool.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,25 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
115115
tfm::format(std::cerr, "The -dumpfile option can only be used with the \"dump\" and \"createfromdump\" commands.\n");
116116
return false;
117117
}
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;
118+
if (args.IsArgSet("-descriptors")) {
119+
if (command != "create") {
120+
tfm::format(std::cerr, "The -descriptors option can only be used with the 'create' command.\n");
121+
return false;
122+
}
123+
if (!args.GetBoolArg("-descriptors", true)) {
124+
tfm::format(std::cerr, "The -descriptors option must be set to \"true\"\n");
125+
return false;
126+
}
121127
}
122-
if (args.IsArgSet("-legacy") && command != "create") {
123-
tfm::format(std::cerr, "The -legacy option can only be used with the 'create' command.\n");
124-
return false;
128+
if (args.IsArgSet("-legacy")) {
129+
if (command != "create") {
130+
tfm::format(std::cerr, "The -legacy option can only be used with the 'create' command.\n");
131+
return false;
132+
}
133+
if (args.GetBoolArg("-legacy", true)) {
134+
tfm::format(std::cerr, "The -legacy option must be set to \"false\"");
135+
return false;
136+
}
125137
}
126138
if (command == "create" && !args.IsArgSet("-wallet")) {
127139
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
@@ -134,22 +146,8 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
134146
DatabaseOptions options;
135147
ReadDatabaseArgs(args, options);
136148
options.require_create = true;
137-
// If -legacy is set, use it. Otherwise default to false.
138-
bool make_legacy = args.GetBoolArg("-legacy", false);
139-
// If neither -legacy nor -descriptors is set, default to true. If -descriptors is set, use its value.
140-
bool make_descriptors = (!args.IsArgSet("-descriptors") && !args.IsArgSet("-legacy")) || (args.IsArgSet("-descriptors") && args.GetBoolArg("-descriptors", true));
141-
if (make_legacy && make_descriptors) {
142-
tfm::format(std::cerr, "Only one of -legacy or -descriptors can be set to true, not both\n");
143-
return false;
144-
}
145-
if (!make_legacy && !make_descriptors) {
146-
tfm::format(std::cerr, "One of -legacy or -descriptors must be set to true (or omitted)\n");
147-
return false;
148-
}
149-
if (make_descriptors) {
150-
options.create_flags |= WALLET_FLAG_DESCRIPTORS;
151-
options.require_format = DatabaseFormat::SQLITE;
152-
}
149+
options.create_flags |= WALLET_FLAG_DESCRIPTORS;
150+
options.require_format = DatabaseFormat::SQLITE;
153151

154152
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, options);
155153
if (wallet_instance) {

test/functional/tool_wallet.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ def test_dump_very_large_records(self):
452452
else:
453453
assert False, "Big transaction was not found in wallet dump"
454454

455+
def test_no_create_legacy(self):
456+
self.log.info("Test that legacy wallets cannot be created")
457+
458+
self.assert_raises_tool_error("The -legacy option must be set to \"false\"", "-wallet=legacy", "-legacy", "create")
459+
assert not (self.nodes[0].wallets_path / "legacy").exists()
460+
self.assert_raises_tool_error("The -descriptors option must be set to \"true\"", "-wallet=legacy", "-descriptors=false", "create")
461+
assert not (self.nodes[0].wallets_path / "legacy").exists()
462+
455463
def run_test(self):
456464
self.wallet_path = self.nodes[0].wallets_path / self.default_wallet_name / self.wallet_data_filename
457465
self.test_invalid_tool_commands_and_args()
@@ -463,6 +471,7 @@ def run_test(self):
463471
self.test_dump_createfromdump()
464472
self.test_chainless_conflicts()
465473
self.test_dump_very_large_records()
474+
self.test_no_create_legacy()
466475

467476

468477
if __name__ == '__main__':

0 commit comments

Comments
 (0)