@@ -1665,7 +1665,12 @@ bool CWallet::ImportScripts(const std::set<CScript> scripts)
1665
1665
{
1666
1666
WalletBatch batch (*database);
1667
1667
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)) {
1669
1674
return false ;
1670
1675
}
1671
1676
}
@@ -1680,9 +1685,14 @@ bool CWallet::ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const in
1680
1685
CPubKey pubkey = key.GetPubKey ();
1681
1686
const CKeyID& id = entry.first ;
1682
1687
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
+ }
1683
1693
mapKeyMetadata[id].nCreateTime = timestamp;
1684
1694
// 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)) {
1686
1696
return false ;
1687
1697
}
1688
1698
UpdateTimeFirstKey (timestamp);
@@ -1703,7 +1713,12 @@ bool CWallet::ImportPubKeys(const std::vector<CKeyID>& ordered_pubkeys, const st
1703
1713
}
1704
1714
const CPubKey& pubkey = entry->second ;
1705
1715
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)) {
1707
1722
return false ;
1708
1723
}
1709
1724
mapKeyMetadata[id].nCreateTime = timestamp;
0 commit comments