Skip to content

Commit e041ed9

Browse files
committed
wallet: Retrieve ID from loaded DescSPKM directly
Instead of iterating m_spk_managers a DescriptorSPKM has been loaded in order to get it's ID to compare, have LoadDescriptorSPKM return a reference to the loaded DescriptorSPKM so it can be queried directly.
1 parent 39640dd commit e041ed9

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,15 +3556,16 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
35563556
}
35573557
}
35583558

3559-
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
3559+
DescriptorScriptPubKeyMan& CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
35603560
{
3561+
DescriptorScriptPubKeyMan* spk_manager;
35613562
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
3562-
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size));
3563-
AddScriptPubKeyMan(id, std::move(spk_manager));
3563+
spk_manager = new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size);
35643564
} else {
3565-
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size));
3566-
AddScriptPubKeyMan(id, std::move(spk_manager));
3565+
spk_manager = new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size);
35673566
}
3567+
AddScriptPubKeyMan(id, std::unique_ptr<ScriptPubKeyMan>(spk_manager));
3568+
return *spk_manager;
35683569
}
35693570

35703571
void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
994994
void ConnectScriptPubKeyManNotifiers();
995995

996996
//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
997-
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
997+
DescriptorScriptPubKeyMan& LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
998998

999999
//! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file
10001000
//! @param[in] id The unique id for the ScriptPubKeyMan

src/wallet/walletdb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,10 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
804804
strErr = strprintf("%s\nDetails: %s", strErr, e.what());
805805
return DBErrors::UNKNOWN_DESCRIPTOR;
806806
}
807-
pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
807+
DescriptorScriptPubKeyMan& spkm = pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
808808

809809
// Prior to doing anything with this spkm, verify ID compatibility
810-
if (id != pwallet->GetDescriptorScriptPubKeyMan(desc)->GetID()) {
810+
if (id != spkm.GetID()) {
811811
strErr = "The descriptor ID calculated by the wallet differs from the one in DB";
812812
return DBErrors::CORRUPT;
813813
}

0 commit comments

Comments
 (0)