Skip to content

Commit 29905c0

Browse files
committed
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.
1 parent 38b2a0a commit 29905c0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/wallet/rpcdump.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,19 +809,22 @@ RPCHelpMan dumpwallet()
809809
std::string strLabel;
810810
CKey key;
811811
if (spk_man.GetKey(keyid, key)) {
812+
CKeyMetadata metadata;
813+
const auto it{spk_man.mapKeyMetadata.find(keyid)};
814+
if (it != spk_man.mapKeyMetadata.end()) metadata = it->second;
812815
file << strprintf("%s %s ", EncodeSecret(key), strTime);
813816
if (GetWalletAddressesForKey(&spk_man, wallet, keyid, strAddr, strLabel)) {
814817
file << strprintf("label=%s", strLabel);
815818
} else if (keyid == seed_id) {
816819
file << "hdseed=1";
817820
} else if (mapKeyPool.count(keyid)) {
818821
file << "reserve=1";
819-
} else if (spk_man.mapKeyMetadata[keyid].hdKeypath == "s") {
822+
} else if (metadata.hdKeypath == "s") {
820823
file << "inactivehdseed=1";
821824
} else {
822825
file << "change=1";
823826
}
824-
file << strprintf(" # addr=%s%s\n", strAddr, (spk_man.mapKeyMetadata[keyid].has_key_origin ? " hdkeypath="+WriteHDKeypath(spk_man.mapKeyMetadata[keyid].key_origin.path) : ""));
827+
file << strprintf(" # addr=%s%s\n", strAddr, (metadata.has_key_origin ? " hdkeypath="+WriteHDKeypath(metadata.key_origin.path) : ""));
825828
}
826829
}
827830
file << "\n";

0 commit comments

Comments
 (0)