Skip to content

Commit 0995517

Browse files
committed
wallet, rpc: Give warning in listwalletdir for legacy wallets
1 parent 638a4c0 commit 0995517

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/wallet/rpc/wallet.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ static RPCHelpMan listwalletdir()
135135
{RPCResult::Type::OBJ, "", "",
136136
{
137137
{RPCResult::Type::STR, "name", "The wallet name"},
138+
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
139+
{
140+
{RPCResult::Type::STR, "", ""},
141+
}},
138142
}},
139143
}},
140144
}
@@ -146,9 +150,14 @@ static RPCHelpMan listwalletdir()
146150
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
147151
{
148152
UniValue wallets(UniValue::VARR);
149-
for (const auto& [path, _] : ListDatabases(GetWalletDir())) {
153+
for (const auto& [path, db_type] : ListDatabases(GetWalletDir())) {
150154
UniValue wallet(UniValue::VOBJ);
151155
wallet.pushKV("name", path.utf8string());
156+
UniValue warnings(UniValue::VARR);
157+
if (db_type == "bdb") {
158+
warnings.push_back("This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded");
159+
}
160+
wallet.pushKV("warnings", warnings);
152161
wallets.push_back(std::move(wallet));
153162
}
154163

test/functional/wallet_migration.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def migrate_and_get_rpc(self, wallet_name, **kwargs):
113113
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", self.master_node.wallets_path / "wallet.dat")
114114
else:
115115
shutil.copytree(self.old_node.wallets_path / wallet_name, self.master_node.wallets_path / wallet_name)
116+
# Check that the wallet shows up in listwalletdir with a warning about migration
117+
wallets = self.master_node.listwalletdir()
118+
for w in wallets["wallets"]:
119+
if w["name"] == wallet_name:
120+
assert_equal(w["warnings"], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded"])
116121
# Migrate, checking that rescan does not occur
117122
with self.master_node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
118123
migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, **kwargs)
@@ -548,7 +553,7 @@ def test_default_wallet(self):
548553
assert_equal(info["format"], "sqlite")
549554

550555
walletdir_list = wallet.listwalletdir()
551-
assert {"name": info["walletname"]} in walletdir_list["wallets"]
556+
assert {"name": info["walletname"]} in [{"name": w["name"]} for w in walletdir_list["wallets"]]
552557

553558
# Check backup existence and its non-empty wallet filename
554559
backup_filename = f"default_wallet_{curr_time}.legacy.bak"

test/functional/wallet_multiwallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def wallet_file(name):
7272
return wallet_dir(name, "wallet.dat")
7373
return wallet_dir(name)
7474

75-
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name}]})
75+
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name, "warnings": []}]})
7676

7777
# check wallet.dat is created
7878
self.stop_nodes()

0 commit comments

Comments
 (0)