mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-06 10:42:46 +01:00
Split up key and script metadata for better type safety
Suggested by Matt Corallo <git@bluematt.me> https://github.com/bitcoin/bitcoin/pull/11403#discussion_r155599383 Combining the maps was probably never a good arrangement but is more problematic now in presence of WitnessV0ScriptHash and WitnessV0KeyHash types.
This commit is contained in:
@@ -187,17 +187,24 @@ UniValue validateaddress(const JSONRPCRequest& request)
|
||||
ret.push_back(Pair("account", pwallet->mapAddressBook[dest].name));
|
||||
}
|
||||
if (pwallet) {
|
||||
const auto& meta = pwallet->mapKeyMetadata;
|
||||
const CKeyID *keyID = boost::get<CKeyID>(&dest);
|
||||
auto it = keyID ? meta.find(*keyID) : meta.end();
|
||||
if (it == meta.end()) {
|
||||
it = meta.find(CScriptID(scriptPubKey));
|
||||
const CKeyMetadata* meta = nullptr;
|
||||
if (const CKeyID* key_id = boost::get<CKeyID>(&dest)) {
|
||||
auto it = pwallet->mapKeyMetadata.find(*key_id);
|
||||
if (it != pwallet->mapKeyMetadata.end()) {
|
||||
meta = &it->second;
|
||||
}
|
||||
}
|
||||
if (it != meta.end()) {
|
||||
ret.push_back(Pair("timestamp", it->second.nCreateTime));
|
||||
if (!it->second.hdKeypath.empty()) {
|
||||
ret.push_back(Pair("hdkeypath", it->second.hdKeypath));
|
||||
ret.push_back(Pair("hdmasterkeyid", it->second.hdMasterKeyID.GetHex()));
|
||||
if (!meta) {
|
||||
auto it = pwallet->m_script_metadata.find(CScriptID(scriptPubKey));
|
||||
if (it != pwallet->m_script_metadata.end()) {
|
||||
meta = &it->second;
|
||||
}
|
||||
}
|
||||
if (meta) {
|
||||
ret.push_back(Pair("timestamp", meta->nCreateTime));
|
||||
if (!meta->hdKeypath.empty()) {
|
||||
ret.push_back(Pair("hdkeypath", meta->hdKeypath));
|
||||
ret.push_back(Pair("hdmasterkeyid", meta->hdMasterKeyID.GetHex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user