wallet, rpc: Give warning in listwalletdir for legacy wallets
This commit is contained in:
1 parent
638a4c0bd8
commit
09955172f3
3 files changed
+17
-3
No files matched your search
@@ -135,6 +135,10 @@ static RPCHelpMan listwalletdir()
|
|||||||
{RPCResult::Type::OBJ, "", "",
|
{RPCResult::Type::OBJ, "", "",
|
||||||
{
|
{
|
||||||
{RPCResult::Type::STR, "name", "The wallet name"},
|
{RPCResult::Type::STR, "name", "The wallet name"},
|
||||||
|
{RPCResult::Type::ARR, "warnings", /*optional=*/true, "Warning messages, if any, related to loading the wallet.",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::STR, "", ""},
|
||||||
|
}},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
@@ -146,9 +150,14 @@ static RPCHelpMan listwalletdir()
|
|||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
UniValue wallets(UniValue::VARR);
|
UniValue wallets(UniValue::VARR);
|
||||||
for (const auto& [path, _] : ListDatabases(GetWalletDir())) {
|
for (const auto& [path, db_type] : ListDatabases(GetWalletDir())) {
|
||||||
UniValue wallet(UniValue::VOBJ);
|
UniValue wallet(UniValue::VOBJ);
|
||||||
wallet.pushKV("name", path.utf8string());
|
wallet.pushKV("name", path.utf8string());
|
||||||
|
UniValue warnings(UniValue::VARR);
|
||||||
|
if (db_type == "bdb") {
|
||||||
|
warnings.push_back("This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded");
|
||||||
|
}
|
||||||
|
wallet.pushKV("warnings", warnings);
|
||||||
wallets.push_back(std::move(wallet));
|
wallets.push_back(std::move(wallet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,11 @@ class WalletMigrationTest(BitcoinTestFramework):
|
|||||||
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", self.master_node.wallets_path / "wallet.dat")
|
shutil.copyfile(self.old_node.wallets_path / "wallet.dat", self.master_node.wallets_path / "wallet.dat")
|
||||||
else:
|
else:
|
||||||
shutil.copytree(self.old_node.wallets_path / wallet_name, self.master_node.wallets_path / wallet_name)
|
shutil.copytree(self.old_node.wallets_path / wallet_name, self.master_node.wallets_path / wallet_name)
|
||||||
|
# Check that the wallet shows up in listwalletdir with a warning about migration
|
||||||
|
wallets = self.master_node.listwalletdir()
|
||||||
|
for w in wallets["wallets"]:
|
||||||
|
if w["name"] == wallet_name:
|
||||||
|
assert_equal(w["warnings"], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded"])
|
||||||
# Migrate, checking that rescan does not occur
|
# Migrate, checking that rescan does not occur
|
||||||
with self.master_node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
|
with self.master_node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
|
||||||
migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, **kwargs)
|
migrate_info = self.master_node.migratewallet(wallet_name=wallet_name, **kwargs)
|
||||||
@@ -548,7 +553,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
|||||||
assert_equal(info["format"], "sqlite")
|
assert_equal(info["format"], "sqlite")
|
||||||
|
|
||||||
walletdir_list = wallet.listwalletdir()
|
walletdir_list = wallet.listwalletdir()
|
||||||
assert {"name": info["walletname"]} in walletdir_list["wallets"]
|
assert {"name": info["walletname"]} in [{"name": w["name"]} for w in walletdir_list["wallets"]]
|
||||||
|
|
||||||
# Check backup existence and its non-empty wallet filename
|
# Check backup existence and its non-empty wallet filename
|
||||||
backup_filename = f"default_wallet_{curr_time}.legacy.bak"
|
backup_filename = f"default_wallet_{curr_time}.legacy.bak"
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
|||||||
return wallet_dir(name, "wallet.dat")
|
return wallet_dir(name, "wallet.dat")
|
||||||
return wallet_dir(name)
|
return wallet_dir(name)
|
||||||
|
|
||||||
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name}]})
|
assert_equal(self.nodes[0].listwalletdir(), {'wallets': [{'name': self.default_wallet_name, "warnings": []}]})
|
||||||
|
|
||||||
# check wallet.dat is created
|
# check wallet.dat is created
|
||||||
self.stop_nodes()
|
self.stop_nodes()
|
||||||
|
|||||||
Reference in new issue
Block a user