1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
10 #include "script/script.h"
13 #include <boost/foreach.hpp>
15 bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
18 if (!GetKey(address, key))
20 vchPubKeyOut = key.GetPubKey();
24 bool CKeyStore::AddKey(const CKey &key) {
25 return AddKeyPubKey(key, key.GetPubKey());
28 bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
31 mapKeys[pubkey.GetID()] = key;
35 bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
37 if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
38 return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
41 mapScripts[redeemScript.GetID()] = redeemScript;
45 bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
48 return mapScripts.count(hash) > 0;
51 bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
54 ScriptMap::const_iterator mi = mapScripts.find(hash);
55 if (mi != mapScripts.end())
57 redeemScriptOut = (*mi).second;
63 bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
66 setWatchOnly.insert(dest);
70 bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
73 return setWatchOnly.count(dest) > 0;
76 bool CBasicKeyStore::HaveWatchOnly() const
79 return (!setWatchOnly.empty());