mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
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.
This commit is contained in:
parent
39640dd34e
commit
e041ed9b75
3 changed files with 9 additions and 8 deletions
|
@ -3556,15 +3556,16 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
|
|||
}
|
||||
}
|
||||
|
||||
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
||||
DescriptorScriptPubKeyMan& CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
||||
{
|
||||
DescriptorScriptPubKeyMan* spk_manager;
|
||||
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
|
||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size));
|
||||
AddScriptPubKeyMan(id, std::move(spk_manager));
|
||||
spk_manager = new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size);
|
||||
} else {
|
||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size));
|
||||
AddScriptPubKeyMan(id, std::move(spk_manager));
|
||||
spk_manager = new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size);
|
||||
}
|
||||
AddScriptPubKeyMan(id, std::unique_ptr<ScriptPubKeyMan>(spk_manager));
|
||||
return *spk_manager;
|
||||
}
|
||||
|
||||
void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)
|
||||
|
|
|
@ -994,7 +994,7 @@ public:
|
|||
void ConnectScriptPubKeyManNotifiers();
|
||||
|
||||
//! Instantiate a descriptor ScriptPubKeyMan from the WalletDescriptor and load it
|
||||
void LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
|
||||
DescriptorScriptPubKeyMan& LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc);
|
||||
|
||||
//! Adds the active ScriptPubKeyMan for the specified type and internal. Writes it to the wallet file
|
||||
//! @param[in] id The unique id for the ScriptPubKeyMan
|
||||
|
|
|
@ -804,10 +804,10 @@ static DBErrors LoadDescriptorWalletRecords(CWallet* pwallet, DatabaseBatch& bat
|
|||
strErr = strprintf("%s\nDetails: %s", strErr, e.what());
|
||||
return DBErrors::UNKNOWN_DESCRIPTOR;
|
||||
}
|
||||
pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
|
||||
DescriptorScriptPubKeyMan& spkm = pwallet->LoadDescriptorScriptPubKeyMan(id, desc);
|
||||
|
||||
// Prior to doing anything with this spkm, verify ID compatibility
|
||||
if (id != pwallet->GetDescriptorScriptPubKeyMan(desc)->GetID()) {
|
||||
if (id != spkm.GetID()) {
|
||||
strErr = "The descriptor ID calculated by the wallet differs from the one in DB";
|
||||
return DBErrors::CORRUPT;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue