Skip to content

Commit 2def858

Browse files
committed
Merge bitcoin/bitcoin#32481: wallet, refactor: Remove Legacy wallet unused warnings and errors
ce90f0c rpc, wallet, refactor: Remove non-descriptor errors (pablomartin4btc) 573bcd7 wallet, refactor: Remove unused SetupGeneration (pablomartin4btc) 5431f2d wallet, refactor: Remove Legacy warnings and errors (pablomartin4btc) Pull request description: Remove dead code due to legacy wallet support removal. These changes have no impact on functionality. They are transparent to the end user, as legacy wallets can't be created or loaded anymore, so these checks are no longer reached. The legacy-to-descriptor wallet migration flow is not affected either, as these removals are not part of its process. ACKs for top commit: achow101: ACK ce90f0c rkrux: utACK ce90f0c Tree-SHA512: 9229ad9dda9ff1dece73b5b15a20d69c6ab1ff2c75b2ec430ddbbaeb3467f6a850f53df527bcb4a8114ccbf1aa9c794462d71a8d516aed6f9a9da74edae16feb
2 parents 287cd04 + ce90f0c commit 2def858

File tree

4 files changed

+10
-72
lines changed

4 files changed

+10
-72
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,6 @@ RPCHelpMan importdescriptors()
356356
// the user could have gotten from another RPC command prior to now
357357
wallet.BlockUntilSyncedToCurrentChain();
358358

359-
// Make sure wallet is a descriptor wallet
360-
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
361-
throw JSONRPCError(RPC_WALLET_ERROR, "importdescriptors is not available for non-descriptor wallets");
362-
}
363-
364359
WalletRescanReserver reserver(*pwallet);
365360
if (!reserver.reserve(/*with_passphrase=*/true)) {
366361
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
@@ -493,10 +488,6 @@ RPCHelpMan listdescriptors()
493488
const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
494489
if (!wallet) return UniValue::VNULL;
495490

496-
if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
497-
throw JSONRPCError(RPC_WALLET_ERROR, "listdescriptors is not available for non-descriptor wallets");
498-
}
499-
500491
const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
501492
if (priv) {
502493
EnsureWalletIsUnlocked(*wallet);

src/wallet/rpc/wallet.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,6 @@ RPCHelpMan gethdkeys()
763763
const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
764764
if (!wallet) return UniValue::VNULL;
765765

766-
if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
767-
throw JSONRPCError(RPC_WALLET_ERROR, "gethdkeys is not available for non-descriptor wallets");
768-
}
769-
770766
LOCK(wallet->cs_wallet);
771767

772768
UniValue options{request.params[0].isNull() ? UniValue::VOBJ : request.params[0]};
@@ -865,11 +861,6 @@ static RPCHelpMan createwalletdescriptor()
865861
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
866862
if (!pwallet) return UniValue::VNULL;
867863

868-
// Make sure wallet is a descriptor wallet
869-
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
870-
throw JSONRPCError(RPC_WALLET_ERROR, "createwalletdescriptor is not available for non-descriptor wallets");
871-
}
872-
873864
std::optional<OutputType> output_type = ParseOutputType(request.params[0].get_str());
874865
if (!output_type) {
875866
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str()));

src/wallet/scriptpubkeyman.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ class ScriptPubKeyMan
112112
*/
113113
virtual std::vector<WalletDestination> MarkUnusedAddresses(const CScript& script) { return {}; }
114114

115-
/** Sets up the key generation stuff, i.e. generates new HD seeds and sets them as active.
116-
* Returns false if already setup or setup fails, true if setup is successful
117-
* Set force=true to make it re-setup if already setup, used for upgrades
118-
*/
119-
virtual bool SetupGeneration(bool force = false) { return false; }
120-
121115
/* Returns true if HD is enabled */
122116
virtual bool IsHDEnabled() const { return false; }
123117

src/wallet/wallet.cpp

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ std::shared_ptr<CWallet> LoadWalletInternal(WalletContext& context, const std::s
288288
return nullptr;
289289
}
290290

291-
// Legacy wallets are being deprecated, warn if the loaded wallet is legacy
292-
if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
293-
warnings.emplace_back(_("Wallet loaded successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future. Legacy wallets can be migrated to a descriptor wallet with migratewallet."));
294-
}
295-
296291
NotifyWalletLoaded(context, wallet);
297292
AddWallet(context, wallet);
298293
wallet->postInitProcess();
@@ -382,12 +377,9 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
382377
uint64_t wallet_creation_flags = options.create_flags;
383378
const SecureString& passphrase = options.create_passphrase;
384379

385-
if (wallet_creation_flags & WALLET_FLAG_DESCRIPTORS) options.require_format = DatabaseFormat::SQLITE;
386-
else {
387-
error = Untranslated("Legacy wallets can no longer be created");
388-
status = DatabaseStatus::FAILED_CREATE;
389-
return nullptr;
390-
}
380+
// Only descriptor wallets can be created
381+
Assert(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS);
382+
options.require_format = DatabaseFormat::SQLITE;
391383

392384
// Indicate that the wallet is actually supposed to be blank and not just blank to make it encrypted
393385
bool create_blank = (wallet_creation_flags & WALLET_FLAG_BLANK_WALLET);
@@ -404,13 +396,6 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
404396
return nullptr;
405397
}
406398

407-
// Descriptor support must be enabled for an external signer wallet
408-
if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) && !(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) {
409-
error = Untranslated("Descriptor support must be enabled when using an external signer");
410-
status = DatabaseStatus::FAILED_CREATE;
411-
return nullptr;
412-
}
413-
414399
// Do not allow a passphrase when private keys are disabled
415400
if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
416401
error = Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.");
@@ -453,17 +438,7 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
453438
// Set a seed for the wallet
454439
{
455440
LOCK(wallet->cs_wallet);
456-
if (wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
457-
wallet->SetupDescriptorScriptPubKeyMans();
458-
} else {
459-
for (auto spk_man : wallet->GetActiveScriptPubKeyMans()) {
460-
if (!spk_man->SetupGeneration()) {
461-
error = Untranslated("Unable to generate initial keys");
462-
status = DatabaseStatus::FAILED_CREATE;
463-
return nullptr;
464-
}
465-
}
466-
}
441+
wallet->SetupDescriptorScriptPubKeyMans();
467442
}
468443

469444
// Relock the wallet
@@ -478,11 +453,6 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
478453
// Write the wallet settings
479454
UpdateWalletSetting(*context.chain, name, load_on_start, warnings);
480455

481-
// Legacy wallets are being deprecated, warn if a newly created wallet is legacy
482-
if (!(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) {
483-
warnings.emplace_back(_("Wallet created successfully. The legacy wallet type is being deprecated and support for creating and opening legacy wallets will be removed in the future."));
484-
}
485-
486456
status = DatabaseStatus::SUCCESS;
487457
return wallet;
488458
}
@@ -813,6 +783,9 @@ void CWallet::AddToSpends(const CWalletTx& wtx, WalletBatch* batch)
813783

814784
bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
815785
{
786+
// Only descriptor wallets can be encrypted
787+
Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
788+
816789
if (IsCrypted())
817790
return false;
818791

@@ -871,8 +844,8 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
871844
Lock();
872845
Unlock(strWalletPassphrase);
873846

874-
// If we are using descriptors, make new descriptors with a new seed
875-
if (IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS) && !IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)) {
847+
// Make new descriptors with a new seed
848+
if (!IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)) {
876849
SetupDescriptorScriptPubKeyMans();
877850
}
878851
Lock();
@@ -2896,18 +2869,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
28962869
assert(walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
28972870

28982871
if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) || !(wallet_creation_flags & (WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET))) {
2899-
if (walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
2900-
walletInstance->SetupDescriptorScriptPubKeyMans();
2901-
// SetupDescriptorScriptPubKeyMans already calls SetupGeneration for us so we don't need to call SetupGeneration separately
2902-
} else {
2903-
// Legacy wallets need SetupGeneration here.
2904-
for (auto spk_man : walletInstance->GetActiveScriptPubKeyMans()) {
2905-
if (!spk_man->SetupGeneration()) {
2906-
error = _("Unable to generate initial keys");
2907-
return nullptr;
2908-
}
2909-
}
2910-
}
2872+
walletInstance->SetupDescriptorScriptPubKeyMans();
29112873
}
29122874

29132875
if (chain) {

0 commit comments

Comments
 (0)