@@ -3628,6 +3628,26 @@ DescriptorScriptPubKeyMan& CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, Wa
36283628 return *spk_manager;
36293629}
36303630
3631+ DescriptorScriptPubKeyMan& CWallet::SetupDescriptorScriptPubKeyMan (WalletBatch& batch, const CExtKey& master_key, const OutputType& output_type, bool internal)
3632+ {
3633+ AssertLockHeld (cs_wallet);
3634+ auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan (*this , m_keypool_size));
3635+ if (IsCrypted ()) {
3636+ if (IsLocked ()) {
3637+ throw std::runtime_error (std::string (__func__) + " : Wallet is locked, cannot setup new descriptors" );
3638+ }
3639+ if (!spk_manager->CheckDecryptionKey (vMasterKey) && !spk_manager->Encrypt (vMasterKey, &batch)) {
3640+ throw std::runtime_error (std::string (__func__) + " : Could not encrypt new descriptors" );
3641+ }
3642+ }
3643+ spk_manager->SetupDescriptorGeneration (batch, master_key, output_type, internal);
3644+ DescriptorScriptPubKeyMan* out = spk_manager.get ();
3645+ uint256 id = spk_manager->GetID ();
3646+ AddScriptPubKeyMan (id, std::move (spk_manager));
3647+ AddActiveScriptPubKeyManWithDb (batch, id, output_type, internal);
3648+ return *out;
3649+ }
3650+
36313651void CWallet::SetupDescriptorScriptPubKeyMans (const CExtKey& master_key)
36323652{
36333653 AssertLockHeld (cs_wallet);
@@ -3638,19 +3658,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)
36383658
36393659 for (bool internal : {false , true }) {
36403660 for (OutputType t : OUTPUT_TYPES) {
3641- auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan (*this , m_keypool_size));
3642- if (IsCrypted ()) {
3643- if (IsLocked ()) {
3644- throw std::runtime_error (std::string (__func__) + " : Wallet is locked, cannot setup new descriptors" );
3645- }
3646- if (!spk_manager->CheckDecryptionKey (vMasterKey) && !spk_manager->Encrypt (vMasterKey, &batch)) {
3647- throw std::runtime_error (std::string (__func__) + " : Could not encrypt new descriptors" );
3648- }
3649- }
3650- spk_manager->SetupDescriptorGeneration (batch, master_key, t, internal);
3651- uint256 id = spk_manager->GetID ();
3652- AddScriptPubKeyMan (id, std::move (spk_manager));
3653- AddActiveScriptPubKeyManWithDb (batch, id, t, internal);
3661+ SetupDescriptorScriptPubKeyMan (batch, master_key, t, internal);
36543662 }
36553663 }
36563664
0 commit comments