message: 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.
diff: @@ -685,6 +685,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);
  @@ -692,12 +695,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";
  