Prevent import keys for watch-only addresses and vice versa.
authorCryptoManiac <balthazar@yandex.ru>
Sat, 19 Jul 2014 15:11:01 +0000 (19:11 +0400)
committerCryptoManiac <balthazar@yandex.ru>
Sat, 19 Jul 2014 15:11:01 +0000 (19:11 +0400)
src/keystore.cpp

index 564c49c..089f2d5 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "keystore.h"
 #include "script.h"
+#include "base58.h"
 
 extern bool fWalletUnlockMintOnly;
 
@@ -65,6 +66,12 @@ bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut)
 bool CBasicKeyStore::AddWatchOnly(const CTxDestination &dest)
 {
     LOCK(cs_KeyStore);
+    CKeyID keyID;
+    CBitcoinAddress(dest).GetKeyID(keyID);
+
+    if (HaveKey(keyID))
+        return false;
+
     setWatchOnly.insert(dest);
     return true;
 }
@@ -137,6 +144,11 @@ bool CCryptoKeyStore::AddKey(const CKey& key)
 {
     {
         LOCK(cs_KeyStore);
+
+        CTxDestination address = key.GetPubKey().GetID();
+        if (HaveWatchOnly(address))
+            return false;
+
         if (!IsCrypted())
             return CBasicKeyStore::AddKey(key);