Skip to content

Commit 40ad2f6

Browse files
committed
Have importwallet use ImportPrivKeys and ImportScripts
Behavior changes: * An "Importing ..." line is logged for every key, even ones that are skipped
1 parent 78941da commit 40ad2f6

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/wallet/rpcdump.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -656,43 +656,38 @@ UniValue importwallet(const JSONRPCRequest& request)
656656
CPubKey pubkey = key.GetPubKey();
657657
assert(key.VerifyPubKey(pubkey));
658658
CKeyID keyid = pubkey.GetID();
659-
if (pwallet->HaveKey(keyid)) {
660-
pwallet->WalletLogPrintf("Skipping import of %s (key already present)\n", EncodeDestination(PKHash(keyid)));
661-
continue;
662-
}
659+
663660
pwallet->WalletLogPrintf("Importing %s...\n", EncodeDestination(PKHash(keyid)));
664-
if (!pwallet->AddKeyPubKey(key, pubkey)) {
661+
662+
if (!pwallet->ImportPrivKeys({{keyid, key}}, time)) {
663+
pwallet->WalletLogPrintf("Error importing key for %s\n", EncodeDestination(PKHash(keyid)));
665664
fGood = false;
666665
continue;
667666
}
668-
pwallet->mapKeyMetadata[keyid].nCreateTime = time;
667+
669668
if (has_label)
670669
pwallet->SetAddressBook(PKHash(keyid), label, "receive");
670+
671671
nTimeBegin = std::min(nTimeBegin, time);
672672
progress++;
673673
}
674674
for (const auto& script_pair : scripts) {
675675
pwallet->chain().showProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
676676
const CScript& script = script_pair.first;
677677
int64_t time = script_pair.second;
678-
CScriptID id(script);
679-
if (pwallet->HaveCScript(id)) {
680-
pwallet->WalletLogPrintf("Skipping import of %s (script already present)\n", HexStr(script));
681-
continue;
682-
}
683-
if(!pwallet->AddCScript(script)) {
678+
679+
if (!pwallet->ImportScripts({script}, time)) {
684680
pwallet->WalletLogPrintf("Error importing script %s\n", HexStr(script));
685681
fGood = false;
686682
continue;
687683
}
688684
if (time > 0) {
689-
pwallet->m_script_metadata[id].nCreateTime = time;
690685
nTimeBegin = std::min(nTimeBegin, time);
691686
}
687+
692688
progress++;
693689
}
694690
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
695-
pwallet->UpdateTimeFirstKey(nTimeBegin);
696691
}
697692
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
698693
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */);

0 commit comments

Comments
 (0)