1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
12 #include <boost/foreach.hpp>
14 bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
17 if (!GetKey(address, key))
19 vchPubKeyOut = key.GetPubKey();
23 bool CKeyStore::AddKey(const CKey &key) {
24 return AddKeyPubKey(key, key.GetPubKey());
27 bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
30 mapKeys[pubkey.GetID()] = key;
34 bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
36 if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
37 return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
40 mapScripts[CScriptID(redeemScript)] = redeemScript;
44 bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
47 return mapScripts.count(hash) > 0;
50 bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
53 ScriptMap::const_iterator mi = mapScripts.find(hash);
54 if (mi != mapScripts.end())
56 redeemScriptOut = (*mi).second;
62 bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
65 setWatchOnly.insert(dest);
69 bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
72 setWatchOnly.erase(dest);
76 bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
79 return setWatchOnly.count(dest) > 0;
82 bool CBasicKeyStore::HaveWatchOnly() const
85 return (!setWatchOnly.empty());