mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Pass CTxDestination to ScriptPubKeyMan::GetMetadata
Pass CTxDestination instead of more ambiguous uint160 hash value. This is more
type safe and more efficient since it avoids doing map lookups that will always
fail and were not done previously before
a18edd7b38 from
https://github.com/bitcoin/bitcoin/pull/17304
Change suggested by Andrew Chow <achow101-github@achow101.com> in
https://github.com/bitcoin/bitcoin/pull/17304#discussion_r340345745 and
https://github.com/bitcoin/bitcoin/pull/17381#issuecomment-549994944
This commit is contained in:
@@ -476,18 +476,24 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
|
||||
return nTimeFirstKey;
|
||||
}
|
||||
|
||||
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
|
||||
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& dest) const
|
||||
{
|
||||
AssertLockHeld(cs_wallet);
|
||||
auto it = mapKeyMetadata.find(CKeyID(id));
|
||||
if (it != mapKeyMetadata.end()) {
|
||||
return &it->second;
|
||||
} else {
|
||||
auto it2 = m_script_metadata.find(CScriptID(id));
|
||||
if (it2 != m_script_metadata.end()) {
|
||||
return &it2->second;
|
||||
|
||||
CKeyID key_id = GetKeyForDestination(*this, dest);
|
||||
if (!key_id.IsNull()) {
|
||||
auto it = mapKeyMetadata.find(key_id);
|
||||
if (it != mapKeyMetadata.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
}
|
||||
|
||||
CScript scriptPubKey = GetScriptForDestination(dest);
|
||||
auto it = m_script_metadata.find(CScriptID(scriptPubKey));
|
||||
if (it != m_script_metadata.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user