@@ -445,13 +445,20 @@ static RPCHelpMan unloadwallet()
445
445
throw JSONRPCError (RPC_WALLET_NOT_FOUND, " Requested wallet does not exist or is not loaded" );
446
446
}
447
447
448
- // Release the "main" shared pointer and prevent further notifications.
449
- // Note that any attempt to load the same wallet would fail until the wallet
450
- // is destroyed (see CheckUniqueFileid).
451
448
std::vector<bilingual_str> warnings;
452
- std::optional<bool > load_on_start = request.params [1 ].isNull () ? std::nullopt : std::optional<bool >(request.params [1 ].get_bool ());
453
- if (!RemoveWallet (context, wallet, load_on_start, warnings)) {
454
- throw JSONRPCError (RPC_MISC_ERROR, " Requested wallet already unloaded" );
449
+ {
450
+ WalletRescanReserver reserver (*wallet);
451
+ if (!reserver.reserve ()) {
452
+ throw JSONRPCError (RPC_WALLET_ERROR, " Wallet is currently rescanning. Abort existing rescan or wait." );
453
+ }
454
+
455
+ // Release the "main" shared pointer and prevent further notifications.
456
+ // Note that any attempt to load the same wallet would fail until the wallet
457
+ // is destroyed (see CheckUniqueFileid).
458
+ std::optional<bool > load_on_start = request.params [1 ].isNull () ? std::nullopt : std::optional<bool >(request.params [1 ].get_bool ());
459
+ if (!RemoveWallet (context, wallet, load_on_start, warnings)) {
460
+ throw JSONRPCError (RPC_MISC_ERROR, " Requested wallet already unloaded" );
461
+ }
455
462
}
456
463
457
464
UnloadWallet (std::move (wallet));
0 commit comments