Skip to content

Commit 6052c78

Browse files
committed
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.
1 parent f2541d0 commit 6052c78

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/wallet/wallet.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,21 +3754,28 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)
37543754
if (!batch.TxnCommit()) throw std::runtime_error("Error: cannot commit db transaction for descriptors setup");
37553755
}
37563756

3757-
void CWallet::SetupDescriptorScriptPubKeyMans()
3757+
void CWallet::SetupOwnDescriptorScriptPubKeyMans()
37583758
{
37593759
AssertLockHeld(cs_wallet);
3760+
assert(!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER));
3761+
// Make a seed
3762+
CKey seed_key = GenerateRandomKey();
3763+
CPubKey seed = seed_key.GetPubKey();
3764+
assert(seed_key.VerifyPubKey(seed));
37603765

3761-
if (!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
3762-
// Make a seed
3763-
CKey seed_key = GenerateRandomKey();
3764-
CPubKey seed = seed_key.GetPubKey();
3765-
assert(seed_key.VerifyPubKey(seed));
3766+
// Get the extended key
3767+
CExtKey master_key;
3768+
master_key.SetSeed(seed_key);
37663769

3767-
// Get the extended key
3768-
CExtKey master_key;
3769-
master_key.SetSeed(seed_key);
3770+
SetupDescriptorScriptPubKeyMans(master_key);
3771+
}
37703772

3771-
SetupDescriptorScriptPubKeyMans(master_key);
3773+
void CWallet::SetupDescriptorScriptPubKeyMans()
3774+
{
3775+
AssertLockHeld(cs_wallet);
3776+
3777+
if (!IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
3778+
SetupOwnDescriptorScriptPubKeyMans();
37723779
} else {
37733780
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
37743781

@@ -4102,7 +4109,7 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
41024109
SetupDescriptorScriptPubKeyMans(data.master_key);
41034110
} else {
41044111
// Setup with a new seed if we don't.
4105-
SetupDescriptorScriptPubKeyMans();
4112+
SetupOwnDescriptorScriptPubKeyMans();
41064113
}
41074114
}
41084115

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
10211021
void SetupDescriptorScriptPubKeyMans(const CExtKey& master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10221022
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10231023

1024+
//! Create new seed and default DescriptorScriptPubKeyMans for this wallet
1025+
void SetupOwnDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
1026+
10241027
//! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet
10251028
DescriptorScriptPubKeyMan* GetDescriptorScriptPubKeyMan(const WalletDescriptor& desc) const;
10261029

0 commit comments

Comments
 (0)