0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

Log when an import is being skipped because we already have it

Behavior Changes:
* Those pubkeys being imported with add_keypool set and are already in the wallet will no longer be added to the keypool
This commit is contained in:
Andrew Chow 2019-07-16 18:51:39 -04:00
parent ab28e31c95
commit fae7a5befd

View file

@ -1665,7 +1665,12 @@ bool CWallet::ImportScripts(const std::set<CScript> scripts)
{ {
WalletBatch batch(*database); WalletBatch batch(*database);
for (const auto& entry : scripts) { for (const auto& entry : scripts) {
if (!HaveCScript(CScriptID(entry)) && !AddCScriptWithDB(batch, entry)) { CScriptID id(entry);
if (HaveCScript(id)) {
WalletLogPrintf("Already have script %s, skipping\n", HexStr(entry));
continue;
}
if (!AddCScriptWithDB(batch, entry)) {
return false; return false;
} }
} }
@ -1680,9 +1685,14 @@ bool CWallet::ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const in
CPubKey pubkey = key.GetPubKey(); CPubKey pubkey = key.GetPubKey();
const CKeyID& id = entry.first; const CKeyID& id = entry.first;
assert(key.VerifyPubKey(pubkey)); assert(key.VerifyPubKey(pubkey));
// Skip if we already have the key
if (HaveKey(id)) {
WalletLogPrintf("Already have key with pubkey %s, skipping\n", HexStr(pubkey));
continue;
}
mapKeyMetadata[id].nCreateTime = timestamp; mapKeyMetadata[id].nCreateTime = timestamp;
// If the private key is not present in the wallet, insert it. // If the private key is not present in the wallet, insert it.
if (!HaveKey(id) && !AddKeyPubKeyWithDB(batch, key, pubkey)) { if (!AddKeyPubKeyWithDB(batch, key, pubkey)) {
return false; return false;
} }
UpdateTimeFirstKey(timestamp); UpdateTimeFirstKey(timestamp);
@ -1703,7 +1713,12 @@ bool CWallet::ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const st
} }
const CPubKey& pubkey = entry->second; const CPubKey& pubkey = entry->second;
CPubKey temp; CPubKey temp;
if (!GetPubKey(id, temp) && !AddWatchOnlyWithDB(batch, GetScriptForRawPubKey(pubkey), timestamp)) { if (GetPubKey(id, temp)) {
// Already have pubkey, skipping
WalletLogPrintf("Already have pubkey %s, skipping\n", HexStr(temp));
continue;
}
if (!AddWatchOnlyWithDB(batch, GetScriptForRawPubKey(pubkey), timestamp)) {
return false; return false;
} }
mapKeyMetadata[id].nCreateTime = timestamp; mapKeyMetadata[id].nCreateTime = timestamp;