diff options
| author | Russell Yanofsky <[email protected]> | 2017-12-08 12:50:46 -0500 |
|---|---|---|
| committer | Russell Yanofsky <[email protected]> | 2017-12-08 12:50:46 -0500 |
| commit | 9c8eca7704e88b3f4ee38cf85bef0f1febc440e5 (patch) | |
| tree | 65a5fb461a02112b1e167e3ecfa522cffcdc4414 /src/rpc/misc.cpp | |
| parent | Merge #11847: Make boost::multi_index comparators const (diff) | |
| download | discoin-9c8eca7704e88b3f4ee38cf85bef0f1febc440e5.tar.xz discoin-9c8eca7704e88b3f4ee38cf85bef0f1febc440e5.zip | |
Split up key and script metadata for better type safety
Suggested by Matt Corallo <[email protected]>
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.
Diffstat (limited to 'src/rpc/misc.cpp')
| -rw-r--r-- | src/rpc/misc.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index c511aa0eb..327af2e23 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -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 (!meta) { + auto it = pwallet->m_script_metadata.find(CScriptID(scriptPubKey)); + if (it != pwallet->m_script_metadata.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) { + 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())); } } } |