@@ -1665,7 +1665,12 @@ bool CWallet::ImportScripts(const std::set<CScript> scripts)
16651665{
16661666 WalletBatch batch (*database);
16671667 for (const auto & entry : scripts) {
1668- if (!HaveCScript (CScriptID (entry)) && !AddCScriptWithDB (batch, entry)) {
1668+ CScriptID id (entry);
1669+ if (HaveCScript (id)) {
1670+ WalletLogPrintf (" Already have script %s, skipping\n " , HexStr (entry));
1671+ continue ;
1672+ }
1673+ if (!AddCScriptWithDB (batch, entry)) {
16691674 return false ;
16701675 }
16711676 }
@@ -1680,9 +1685,14 @@ bool CWallet::ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const in
16801685 CPubKey pubkey = key.GetPubKey ();
16811686 const CKeyID& id = entry.first ;
16821687 assert (key.VerifyPubKey (pubkey));
1688+ // Skip if we already have the key
1689+ if (HaveKey (id)) {
1690+ WalletLogPrintf (" Already have key with pubkey %s, skipping\n " , HexStr (pubkey));
1691+ continue ;
1692+ }
16831693 mapKeyMetadata[id].nCreateTime = timestamp;
16841694 // If the private key is not present in the wallet, insert it.
1685- if (!HaveKey (id) && ! AddKeyPubKeyWithDB (batch, key, pubkey)) {
1695+ if (!AddKeyPubKeyWithDB (batch, key, pubkey)) {
16861696 return false ;
16871697 }
16881698 UpdateTimeFirstKey (timestamp);
@@ -1703,7 +1713,12 @@ bool CWallet::ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const st
17031713 }
17041714 const CPubKey& pubkey = entry->second ;
17051715 CPubKey temp;
1706- if (!GetPubKey (id, temp) && !AddWatchOnlyWithDB (batch, GetScriptForRawPubKey (pubkey), timestamp)) {
1716+ if (GetPubKey (id, temp)) {
1717+ // Already have pubkey, skipping
1718+ WalletLogPrintf (" Already have pubkey %s, skipping\n " , HexStr (temp));
1719+ continue ;
1720+ }
1721+ if (!AddWatchOnlyWithDB (batch, GetScriptForRawPubKey (pubkey), timestamp)) {
17071722 return false ;
17081723 }
17091724 mapKeyMetadata[id].nCreateTime = timestamp;
0 commit comments