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.
11 #include <boost/foreach.hpp>
13 bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
16 if (!GetKey(address, key))
18 vchPubKeyOut = key.GetPubKey();
22 bool CKeyStore::AddKey(const CKey &key) {
23 return AddKeyPubKey(key, key.GetPubKey());
26 bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
29 mapKeys[pubkey.GetID()] = key;
33 bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
35 if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
36 return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
39 mapScripts[CScriptID(redeemScript)] = redeemScript;
43 bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
46 return mapScripts.count(hash) > 0;
49 bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
52 ScriptMap::const_iterator mi = mapScripts.find(hash);
53 if (mi != mapScripts.end())
55 redeemScriptOut = (*mi).second;
61 bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
64 setWatchOnly.insert(dest);
68 bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
71 setWatchOnly.erase(dest);
75 bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
78 return setWatchOnly.count(dest) > 0;
81 bool CBasicKeyStore::HaveWatchOnly() const
84 return (!setWatchOnly.empty());
87 bool CBasicKeyStore::AddSpendingKey(const libzcash::SpendingKey &sk)
89 LOCK(cs_SpendingKeyStore);
90 auto address = sk.address();
91 mapSpendingKeys[address] = sk;
92 mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(sk.viewing_key())));