refactor: avoid multiple key->metadata lookups in dumpwallet RPC

This also enables working with a const ScriptPubKeyMan which was
previously not possible due to std::map::operator[] not being const.
This commit is contained in:
Sebastian Falbesoner 2021-08-26 14:39:46 +02:00
parent 38b2a0a3f9
commit 29905c092f

View file

@ -809,6 +809,9 @@ RPCHelpMan dumpwallet()
std::string strLabel;
CKey key;
if (spk_man.GetKey(keyid, key)) {
CKeyMetadata metadata;
const auto it{spk_man.mapKeyMetadata.find(keyid)};
if (it != spk_man.mapKeyMetadata.end()) metadata = it->second;
file << strprintf("%s %s ", EncodeSecret(key), strTime);
if (GetWalletAddressesForKey(&spk_man, wallet, keyid, strAddr, strLabel)) {
file << strprintf("label=%s", strLabel);
@ -816,12 +819,12 @@ RPCHelpMan dumpwallet()
file << "hdseed=1";
} else if (mapKeyPool.count(keyid)) {
file << "reserve=1";
} else if (spk_man.mapKeyMetadata[keyid].hdKeypath == "s") {
} else if (metadata.hdKeypath == "s") {
file << "inactivehdseed=1";
} else {
file << "change=1";
}
file << strprintf(" # addr=%s%s\n", strAddr, (spk_man.mapKeyMetadata[keyid].has_key_origin ? " hdkeypath="+WriteHDKeypath(spk_man.mapKeyMetadata[keyid].key_origin.path) : ""));
file << strprintf(" # addr=%s%s\n", strAddr, (metadata.has_key_origin ? " hdkeypath="+WriteHDKeypath(metadata.key_origin.path) : ""));
}
}
file << "\n";