From 2dc74e3f4e5e6f01c8810359b91041bc6865f1c7 Mon Sep 17 00:00:00 2001 From: Novo Date: Tue, 13 May 2025 13:32:06 +0100 Subject: [PATCH] wallet/migration: use HavePrivateKeys in place of ToPrivateString ToPrivateString() behaviour will be modified in the following commits. In order to keep the scope of this PR limited to the RPC behaviour, this commit updates wallet migration to use 'Descriptor::HavePrivateKeys()' in place of 'Descriptor::ToPrivateString()' to determine watchonly descriptors. A follow-up PR can be opened to update migration logic to exclude descriptors with some private keys from the watchonly migration wallet. --- src/wallet/scriptpubkeyman.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 276817146c6..708f59892eb 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -717,10 +717,9 @@ std::optional LegacyDataSPKM::MigrateToDescriptor() std::vector desc_spks; - // Make the descriptor string with private keys - std::string desc_str; - bool watchonly = !desc->ToPrivateString(*this, desc_str); - if (watchonly && !m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { + // If we can't provide all private keys for this inferred descriptor, + // but this wallet is not watch-only, migrate it to the watch-only wallet. + if (!desc->HavePrivateKeys(*this) && !m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { out.watch_descs.emplace_back(desc->ToString(), creation_time); // Get the scriptPubKeys without writing this to the wallet