diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4233,15 +4233,7 @@ ScriptPubKeyMan *spk_man = pwallet->GetScriptPubKeyMan(); if (spk_man) { - CKeyID key_id = GetKeyForDestination(*provider, dest); - const CKeyMetadata *meta = nullptr; - if (!key_id.IsNull()) { - meta = spk_man->GetMetadata(key_id); - } - if (!meta) { - meta = spk_man->GetMetadata(CScriptID(scriptPubKey)); - } - if (meta) { + if (const CKeyMetadata *meta = spk_man->GetMetadata(dest)) { ret.pushKV("timestamp", meta->nCreateTime); if (meta->has_key_origin) { ret.pushKV("hdkeypath", WriteHDKeypath(meta->key_origin.path)); diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -206,7 +206,8 @@ virtual int64_t GetTimeFirstKey() const { return 0; } - virtual const CKeyMetadata *GetMetadata(uint160 id) const { + //! Return address metadata + virtual const CKeyMetadata *GetMetadata(const CTxDestination &dest) const { return nullptr; } }; @@ -341,7 +342,7 @@ int64_t GetTimeFirstKey() const override; - const CKeyMetadata *GetMetadata(uint160 id) const override; + const CKeyMetadata *GetMetadata(const CTxDestination &dest) const override; bool CanGetAddresses(bool internal = false) override; diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -431,17 +431,24 @@ 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; }