From 6052c7891dc033e30b342ae5ea1690f8e7cbeb9e Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 29 Sep 2023 16:12:04 -0300 Subject: [PATCH] wallet: decouple default descriptors creation from external signer setup This will be useful in the following-up commit to batch the entire wallet migration process. --- src/wallet/wallet.cpp | 29 ++++++++++++++++++----------- src/wallet/wallet.h | 3 +++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index de565102cc2..75b258895dd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3754,21 +3754,28 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key) if (!batch.TxnCommit()) throw std::runtime_error("Error: cannot commit db transaction for descriptors setup"); } +void CWallet::SetupOwnDescriptorScriptPubKeyMans() +{ + AssertLockHeld(cs_wallet); + assert(!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)); + // Make a seed + CKey seed_key = GenerateRandomKey(); + CPubKey seed = seed_key.GetPubKey(); + assert(seed_key.VerifyPubKey(seed)); + + // Get the extended key + CExtKey master_key; + master_key.SetSeed(seed_key); + + SetupDescriptorScriptPubKeyMans(master_key); +} + void CWallet::SetupDescriptorScriptPubKeyMans() { AssertLockHeld(cs_wallet); if (!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) { - // Make a seed - CKey seed_key = GenerateRandomKey(); - CPubKey seed = seed_key.GetPubKey(); - assert(seed_key.VerifyPubKey(seed)); - - // Get the extended key - CExtKey master_key; - master_key.SetSeed(seed_key); - - SetupDescriptorScriptPubKeyMans(master_key); + SetupOwnDescriptorScriptPubKeyMans(); } else { ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner(); @@ -4102,7 +4109,7 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error) SetupDescriptorScriptPubKeyMans(data.master_key); } else { // Setup with a new seed if we don't. - SetupDescriptorScriptPubKeyMans(); + SetupOwnDescriptorScriptPubKeyMans(); } } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d3a7208b15e..f70f9ce2cf3 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1021,6 +1021,9 @@ public: void SetupDescriptorScriptPubKeyMans(const CExtKey& master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + //! Create new seed and default DescriptorScriptPubKeyMans for this wallet + void SetupOwnDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); + //! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;