diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3376,6 +3376,8 @@ } if (!request.params[5].isNull() && request.params[5].get_bool()) { flags |= WALLET_FLAG_DESCRIPTORS; + warnings.emplace_back( + Untranslated("Wallet is an experimental descriptor wallet")); } bilingual_str error; diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -298,7 +298,7 @@ virtual uint256 GetID() const { return uint256(); } - virtual void SetType(OutputType type, bool internal) {} + virtual void SetInternal(bool internal) {} /** * Prepends the wallet name in logging output to ease debugging in @@ -497,7 +497,7 @@ uint256 GetID() const override; - void SetType(OutputType type, bool internal) override; + void SetInternal(bool internal) override; // Map from Key ID to key metadata. std::map mapKeyMetadata GUARDED_BY(cs_KeyStore); @@ -665,14 +665,11 @@ PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man); int32_t m_max_cached_index = -1; - OutputType m_address_type; bool m_internal = false; KeyMap m_map_keys GUARDED_BY(cs_desc_man); CryptedKeyMap m_map_crypted_keys GUARDED_BY(cs_desc_man); - bool SetCrypted(); - //! keeps track of whether Unlock has run a thorough check before bool m_decryption_thoroughly_checked = false; @@ -700,10 +697,8 @@ DescriptorScriptPubKeyMan(WalletStorage &storage, WalletDescriptor &descriptor) : ScriptPubKeyMan(storage), m_wallet_descriptor(descriptor) {} - DescriptorScriptPubKeyMan(WalletStorage &storage, OutputType address_type, - bool internal) - : ScriptPubKeyMan(storage), m_address_type(address_type), - m_internal(internal) {} + DescriptorScriptPubKeyMan(WalletStorage &storage, bool internal) + : ScriptPubKeyMan(storage), m_internal(internal) {} mutable RecursiveMutex cs_desc_man; @@ -734,7 +729,8 @@ bool IsHDEnabled() const override; //! Setup descriptors based on the given CExtkey - bool SetupDescriptorGeneration(const CExtKey &master_key); + bool SetupDescriptorGeneration(const CExtKey &master_key, + OutputType addr_type); bool HavePrivateKeys() const override; @@ -767,7 +763,7 @@ uint256 GetID() const override; - void SetType(OutputType type, bool internal) override; + void SetInternal(bool internal) override; void SetCache(const DescriptorCache &cache); diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1619,7 +1619,7 @@ return set_address; } -void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {} +void LegacyScriptPubKeyMan::SetInternal(bool internal) {} bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination &dest, @@ -1635,7 +1635,10 @@ LOCK(cs_desc_man); // This is a combo descriptor which should not be an active descriptor assert(m_wallet_descriptor.descriptor->IsSingleType()); - if (type != m_address_type) { + std::optional desc_addr_type = + m_wallet_descriptor.descriptor->GetOutputType(); + assert(desc_addr_type); + if (type != *desc_addr_type) { throw std::runtime_error(std::string(__func__) + ": Types are inconsistent"); } @@ -1953,7 +1956,7 @@ } bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration( - const CExtKey &master_key) { + const CExtKey &master_key, OutputType addr_type) { LOCK(cs_desc_man); assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)); @@ -1969,7 +1972,7 @@ // Build descriptor string std::string desc_prefix; std::string desc_suffix = "/*)"; - switch (m_address_type) { + switch (addr_type) { case OutputType::LEGACY: { desc_prefix = "pkh(" + xpub + "/44'"; break; @@ -2258,8 +2261,7 @@ return id; } -void DescriptorScriptPubKeyMan::SetType(OutputType type, bool internal) { - this->m_address_type = type; +void DescriptorScriptPubKeyMan::SetInternal(bool internal) { this->m_internal = internal; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4896,7 +4896,7 @@ for (bool internal : {false, true}) { for (OutputType t : OUTPUT_TYPES) { auto spk_manager = - std::make_unique(*this, t, internal); + std::make_unique(*this, internal); if (IsCrypted()) { if (IsLocked()) { throw std::runtime_error( @@ -4910,7 +4910,7 @@ ": Could not encrypt new descriptors"); } } - spk_manager->SetupDescriptorGeneration(master_key); + spk_manager->SetupDescriptorGeneration(master_key, t); uint256 id = spk_manager->GetID(); m_spk_managers[id] = std::move(spk_manager); SetActiveScriptPubKeyMan(id, t, internal); @@ -4926,7 +4926,7 @@ auto &spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers; auto spk_man = m_spk_managers.at(id).get(); - spk_man->SetType(type, internal); + spk_man->SetInternal(internal); spk_mans[type] = spk_man; if (!memonly) {