From ae640f05e8ac08e4616aa34e02e3a4b5d2ee25c3 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sat, 19 Jul 2014 19:11:01 +0400 Subject: [PATCH] Prevent import keys for watch-only addresses and vice versa. --- src/keystore.cpp | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/src/keystore.cpp b/src/keystore.cpp index 564c49c..089f2d5 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -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); -- 1.7.1