mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
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:
parent
38b2a0a3f9
commit
29905c092f
1 changed files with 5 additions and 2 deletions
|
@ -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";
|
||||
|
|
Loading…
Add table
Reference in a new issue