Have importwallet use ImportPrivKeys and ImportScripts
Behavior changes: * An "Importing ..." line is logged for every key, even ones that are skipped
This commit is contained in:
parent
78941da5ba
commit
40ad2f6a58
1 changed files with 9 additions and 14 deletions
|
@ -656,18 +656,18 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
CPubKey pubkey = key.GetPubKey();
|
CPubKey pubkey = key.GetPubKey();
|
||||||
assert(key.VerifyPubKey(pubkey));
|
assert(key.VerifyPubKey(pubkey));
|
||||||
CKeyID keyid = pubkey.GetID();
|
CKeyID keyid = pubkey.GetID();
|
||||||
if (pwallet->HaveKey(keyid)) {
|
|
||||||
pwallet->WalletLogPrintf("Skipping import of %s (key already present)\n", EncodeDestination(PKHash(keyid)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
pwallet->WalletLogPrintf("Importing %s...\n", EncodeDestination(PKHash(keyid)));
|
pwallet->WalletLogPrintf("Importing %s...\n", EncodeDestination(PKHash(keyid)));
|
||||||
if (!pwallet->AddKeyPubKey(key, pubkey)) {
|
|
||||||
|
if (!pwallet->ImportPrivKeys({{keyid, key}}, time)) {
|
||||||
|
pwallet->WalletLogPrintf("Error importing key for %s\n", EncodeDestination(PKHash(keyid)));
|
||||||
fGood = false;
|
fGood = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pwallet->mapKeyMetadata[keyid].nCreateTime = time;
|
|
||||||
if (has_label)
|
if (has_label)
|
||||||
pwallet->SetAddressBook(PKHash(keyid), label, "receive");
|
pwallet->SetAddressBook(PKHash(keyid), label, "receive");
|
||||||
|
|
||||||
nTimeBegin = std::min(nTimeBegin, time);
|
nTimeBegin = std::min(nTimeBegin, time);
|
||||||
progress++;
|
progress++;
|
||||||
}
|
}
|
||||||
|
@ -675,24 +675,19 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
pwallet->chain().showProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
pwallet->chain().showProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
||||||
const CScript& script = script_pair.first;
|
const CScript& script = script_pair.first;
|
||||||
int64_t time = script_pair.second;
|
int64_t time = script_pair.second;
|
||||||
CScriptID id(script);
|
|
||||||
if (pwallet->HaveCScript(id)) {
|
if (!pwallet->ImportScripts({script}, time)) {
|
||||||
pwallet->WalletLogPrintf("Skipping import of %s (script already present)\n", HexStr(script));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!pwallet->AddCScript(script)) {
|
|
||||||
pwallet->WalletLogPrintf("Error importing script %s\n", HexStr(script));
|
pwallet->WalletLogPrintf("Error importing script %s\n", HexStr(script));
|
||||||
fGood = false;
|
fGood = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
pwallet->m_script_metadata[id].nCreateTime = time;
|
|
||||||
nTimeBegin = std::min(nTimeBegin, time);
|
nTimeBegin = std::min(nTimeBegin, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
}
|
}
|
||||||
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
||||||
pwallet->UpdateTimeFirstKey(nTimeBegin);
|
|
||||||
}
|
}
|
||||||
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
||||||
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */);
|
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */);
|
||||||
|
|
Loading…
Add table
Reference in a new issue