#include "keystore.h"
#include "script.h"
+#include "base58.h"
extern bool fWalletUnlockMintOnly;
bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
{
+ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
+ return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
+
{
LOCK(cs_KeyStore);
mapScripts[redeemScript.GetID()] = redeemScript;
return false;
}
-bool CBasicKeyStore::AddWatchOnly(const CTxDestination &dest)
+bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
{
LOCK(cs_KeyStore);
+
+ CTxDestination address;
+ if (ExtractDestination(dest, address)) {
+ CKeyID keyID;
+ CBitcoinAddress(address).GetKeyID(keyID);
+ if (HaveKey(keyID))
+ return false;
+ }
+
setWatchOnly.insert(dest);
return true;
}
-bool CBasicKeyStore::HaveWatchOnly(const CTxDestination &dest) const
+
+bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
+{
+ LOCK(cs_KeyStore);
+ setWatchOnly.erase(dest);
+ return true;
+}
+
+bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
{
LOCK(cs_KeyStore);
return setWatchOnly.count(dest) > 0;
}
+bool CBasicKeyStore::HaveWatchOnly() const
+{
+ LOCK(cs_KeyStore);
+ return (!setWatchOnly.empty());
+}
+
bool CCryptoKeyStore::SetCrypted()
{
{
{
{
LOCK(cs_KeyStore);
+
+ CScript script;
+ script.SetDestination(key.GetPubKey().GetID());
+
+ if (HaveWatchOnly(script))
+ return false;
+
if (!IsCrypted())
return CBasicKeyStore::AddKey(key);