diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dc868aa5a01d0a..3466b634e9d354 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3824,12 +3824,12 @@ UniValue getaddressinfo(const JSONRPCRequest& request) ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan(scriptPubKey); if (spk_man) { - const PKHash *pkhash = std::get_if(&dest); if (const CKeyMetadata* meta = spk_man->GetMetadata(dest)) { ret.pushKV("timestamp", meta->nCreateTime); CHDChain hdChainCurrent; LegacyScriptPubKeyMan* legacy_spk_man = pwallet->GetLegacyScriptPubKeyMan(); if (legacy_spk_man != nullptr) { + const PKHash *pkhash = std::get_if(&dest); if (pkhash && legacy_spk_man->HaveHDKey(ToKeyID(*pkhash), hdChainCurrent)) { ret.pushKV("hdchainid", hdChainCurrent.GetID().GetHex()); } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 0fe85bff7a632e..78a2dbc2bc0938 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -749,9 +749,9 @@ const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& des { LOCK(cs_KeyStore); - const PKHash *pkhash = std::get_if(&dest); - if (pkhash != nullptr && !ToKeyID(*pkhash).IsNull()) { - auto it = mapKeyMetadata.find(ToKeyID(*pkhash)); + CKeyID key_id = GetKeyForDestination(*this, dest); + if (!key_id.IsNull()) { + auto it = mapKeyMetadata.find(key_id); if (it != mapKeyMetadata.end()) { return &it->second; }