wallet: Refactor SetupDescSPKMs to take CExtKey
Refactors SetupDescSPKMs so that the DescSPKM loops are in their own function. This allows us to call it later during migration with a key that was already generated.
This commit is contained in:
1 parent
22401f17e0
commit
5b62f095e7
2 files changed
+25
-17
No files matched your search
+24
-17
@@ -3433,6 +3433,29 @@ void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)
|
||||||
|
{
|
||||||
|
AssertLockHeld(cs_wallet);
|
||||||
|
|
||||||
|
for (bool internal : {false, true}) {
|
||||||
|
for (OutputType t : OUTPUT_TYPES) {
|
||||||
|
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this));
|
||||||
|
if (IsCrypted()) {
|
||||||
|
if (IsLocked()) {
|
||||||
|
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
||||||
|
}
|
||||||
|
if (!spk_manager->CheckDecryptionKey(vMasterKey) && !spk_manager->Encrypt(vMasterKey, nullptr)) {
|
||||||
|
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spk_manager->SetupDescriptorGeneration(master_key, t, internal);
|
||||||
|
uint256 id = spk_manager->GetID();
|
||||||
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
|
AddActiveScriptPubKeyMan(id, t, internal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CWallet::SetupDescriptorScriptPubKeyMans()
|
void CWallet::SetupDescriptorScriptPubKeyMans()
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
@@ -3448,23 +3471,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
|||||||
CExtKey master_key;
|
CExtKey master_key;
|
||||||
master_key.SetSeed(seed_key);
|
master_key.SetSeed(seed_key);
|
||||||
|
|
||||||
for (bool internal : {false, true}) {
|
SetupDescriptorScriptPubKeyMans(master_key);
|
||||||
for (OutputType t : OUTPUT_TYPES) {
|
|
||||||
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this));
|
|
||||||
if (IsCrypted()) {
|
|
||||||
if (IsLocked()) {
|
|
||||||
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
|
||||||
}
|
|
||||||
if (!spk_manager->CheckDecryptionKey(vMasterKey) && !spk_manager->Encrypt(vMasterKey, nullptr)) {
|
|
||||||
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
spk_manager->SetupDescriptorGeneration(master_key, t, internal);
|
|
||||||
uint256 id = spk_manager->GetID();
|
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
|
||||||
AddActiveScriptPubKeyMan(id, t, internal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
|
ExternalSigner signer = ExternalSignerScriptPubKeyMan::GetExternalSigner();
|
||||||
|
|
||||||
|
|||||||
@@ -907,6 +907,7 @@ public:
|
|||||||
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
|
void DeactivateScriptPubKeyMan(uint256 id, OutputType type, bool internal);
|
||||||
|
|
||||||
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
|
//! Create new DescriptorScriptPubKeyMans and add them to the wallet
|
||||||
|
void SetupDescriptorScriptPubKeyMans(const CExtKey& master_key) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
void SetupDescriptorScriptPubKeyMans() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
|
|
||||||
//! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet
|
//! Return the DescriptorScriptPubKeyMan for a WalletDescriptor if it is already in the wallet
|
||||||
|
|||||||
Reference in new issue
Block a user