Skip to content

Commit 9f94de5

Browse files
committed
wallet: init, don't error out when loading legacy wallets
Instead of failing during initialization when encountering a legacy wallet, skip loading the wallet and notify the user accordingly. This allows users to access migration functionalities without needing to manually remove the wallet from settings.json or resort to using the bitcoin-wallet utility. This means that GUI users will be able to use the migration button, and bitcoin-cli users will be able to call the migratewallet RPC directly after init.
1 parent 66c968b commit 9f94de5

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/wallet/db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ enum class DatabaseStatus {
184184
SUCCESS,
185185
FAILED_BAD_PATH,
186186
FAILED_BAD_FORMAT,
187+
FAILED_LEGACY_DISABLED,
187188
FAILED_ALREADY_LOADED,
188189
FAILED_ALREADY_EXISTS,
189190
FAILED_NOT_FOUND,

src/wallet/load.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ bool VerifyWallets(WalletContext& context)
9999
if (!MakeWalletDatabase(wallet_file, options, status, error_string)) {
100100
if (status == DatabaseStatus::FAILED_NOT_FOUND) {
101101
chain.initWarning(Untranslated(strprintf("Skipping -wallet path that doesn't exist. %s", error_string.original)));
102+
} else if (status == DatabaseStatus::FAILED_LEGACY_DISABLED) {
103+
// Skipping legacy wallets as they will not be loaded.
104+
// This will be properly communicated to the user during the loading process.
105+
continue;
102106
} else {
103107
chain.initError(error_string);
104108
return false;
@@ -132,8 +136,13 @@ bool LoadWallets(WalletContext& context)
132136
bilingual_str error;
133137
std::vector<bilingual_str> warnings;
134138
std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(name, options, status, error);
135-
if (!database && status == DatabaseStatus::FAILED_NOT_FOUND) {
136-
continue;
139+
if (!database) {
140+
if (status == DatabaseStatus::FAILED_NOT_FOUND) continue;
141+
if (status == DatabaseStatus::FAILED_LEGACY_DISABLED) {
142+
// Inform user that legacy wallet is not loaded and suggest upgrade options
143+
chain.initWarning(error);
144+
continue;
145+
}
137146
}
138147
chain.initMessage(_("Loading wallet…"));
139148
std::shared_ptr<CWallet> pwallet = database ? CWallet::Create(context, name, std::move(database), options.create_flags, error, warnings) : nullptr;

src/wallet/rpc/util.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& st
123123
switch (status) {
124124
case DatabaseStatus::FAILED_NOT_FOUND:
125125
case DatabaseStatus::FAILED_BAD_FORMAT:
126+
case DatabaseStatus::FAILED_LEGACY_DISABLED:
126127
code = RPC_WALLET_NOT_FOUND;
127128
break;
128129
case DatabaseStatus::FAILED_ALREADY_LOADED:

src/wallet/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,8 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
13831383

13841384
// BERKELEY_RO can only be opened if require_format was set, which only occurs in migration.
13851385
if (format && format == DatabaseFormat::BERKELEY_RO && (!options.require_format || options.require_format != DatabaseFormat::BERKELEY_RO)) {
1386-
error = Untranslated(strprintf("Failed to open database path '%s'. The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC).", fs::PathToString(path)));
1387-
status = DatabaseStatus::FAILED_BAD_FORMAT;
1386+
error = Untranslated(strprintf("Failed to open database path '%s'. The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option).", fs::PathToString(path)));
1387+
status = DatabaseStatus::FAILED_LEGACY_DISABLED;
13881388
return nullptr;
13891389
}
13901390

test/functional/wallet_backwards_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def run_test(self):
378378

379379
# Restore the wallet to master
380380
# Legacy wallets are no longer supported. Trying to load these should result in an error
381-
assert_raises_rpc_error(-18, "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC)", node_master.restorewallet, wallet_name, backup_path)
381+
assert_raises_rpc_error(-18, "The wallet appears to be a Legacy wallet, please use the wallet migration tool (migratewallet RPC or the GUI option)", node_master.restorewallet, wallet_name, backup_path)
382382

383383
self.test_v22_inactivehdchain_path()
384384

0 commit comments

Comments
 (0)