@@ -3883,7 +3883,7 @@ void CWallet::LoadActiveScriptPubKeyMan(uint256 id, OutputType type, bool intern
38833883 spk_mans[type] = spk_man;
38843884
38853885 const auto it = spk_mans_other.find (type);
3886- if (it != spk_mans_other.end () && it->second == spk_man) {
3886+ if (it != spk_mans_other.end () && it->second == spk_man && type != OutputType::SILENT_PAYMENT ) {
38873887 spk_mans_other.erase (type);
38883888 }
38893889
@@ -3976,10 +3976,23 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
39763976 return nullptr ;
39773977 }
39783978
3979+ auto type = desc.descriptor ->GetOutputType ();
3980+ if (type == OutputType::SILENT_PAYMENT && !IsWalletFlagSet (WALLET_FLAG_SILENT_PAYMENTS)) {
3981+ WalletLogPrintf (" Cannot add Silent Payment Descriptor to a wallet that does not support silent payments\n " );
3982+ return nullptr ;
3983+ }
3984+
39793985 auto spk_man = GetDescriptorScriptPubKeyMan (desc);
39803986 if (spk_man) {
39813987 WalletLogPrintf (" Update existing descriptor: %s\n " , desc.descriptor ->ToString ());
39823988 spk_man->UpdateWalletDescriptor (desc);
3989+ } else if (type == OutputType::SILENT_PAYMENT) {
3990+ auto new_spk_man = std::unique_ptr<SilentPaymentDescriptorScriptPubKeyMan>(new SilentPaymentDescriptorScriptPubKeyMan (*this , desc));
3991+ spk_man = new_spk_man.get ();
3992+
3993+ // Save the descriptor to memory
3994+ uint256 id = new_spk_man->GetID ();
3995+ AddScriptPubKeyMan (id, std::move (new_spk_man));
39833996 } else {
39843997 auto new_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan (*this , desc, m_keypool_size));
39853998 spk_man = new_spk_man.get ();
@@ -4005,7 +4018,7 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
40054018 // Note: we disable labels for ranged descriptors
40064019 if (!desc.descriptor ->IsRange ()) {
40074020 auto script_pub_keys = spk_man->GetScriptPubKeys ();
4008- if (script_pub_keys.empty ()) {
4021+ if (script_pub_keys.empty () && type != OutputType::SILENT_PAYMENT ) {
40094022 WalletLogPrintf (" Could not generate scriptPubKeys (cache is empty)\n " );
40104023 return nullptr ;
40114024 }
0 commit comments