]> Git Repo - VerusCoin.git/blob - src/keystore.cpp
Make GetSerializeSize a wrapper on top of CSizeComputer
[VerusCoin.git] / src / keystore.cpp
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.
5
6 #include "keystore.h"
7
8 #include "key.h"
9 #include "util.h"
10
11 #include <boost/foreach.hpp>
12
13 bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
14 {
15     CKey key;
16     if (!GetKey(address, key))
17         return false;
18     vchPubKeyOut = key.GetPubKey();
19     return true;
20 }
21
22 bool CKeyStore::AddKey(const CKey &key) {
23     return AddKeyPubKey(key, key.GetPubKey());
24 }
25
26 bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
27 {
28     LOCK(cs_KeyStore);
29     mapKeys[pubkey.GetID()] = key;
30     return true;
31 }
32
33 bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
34 {
35     if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
36         return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
37
38     LOCK(cs_KeyStore);
39     mapScripts[CScriptID(redeemScript)] = redeemScript;
40     return true;
41 }
42
43 bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
44 {
45     LOCK(cs_KeyStore);
46     return mapScripts.count(hash) > 0;
47 }
48
49 bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
50 {
51     LOCK(cs_KeyStore);
52     ScriptMap::const_iterator mi = mapScripts.find(hash);
53     if (mi != mapScripts.end())
54     {
55         redeemScriptOut = (*mi).second;
56         return true;
57     }
58     return false;
59 }
60
61 bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
62 {
63     LOCK(cs_KeyStore);
64     setWatchOnly.insert(dest);
65     return true;
66 }
67
68 bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
69 {
70     LOCK(cs_KeyStore);
71     setWatchOnly.erase(dest);
72     return true;
73 }
74
75 bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
76 {
77     LOCK(cs_KeyStore);
78     return setWatchOnly.count(dest) > 0;
79 }
80
81 bool CBasicKeyStore::HaveWatchOnly() const
82 {
83     LOCK(cs_KeyStore);
84     return (!setWatchOnly.empty());
85 }
86
87 bool CBasicKeyStore::AddSpendingKey(const libzcash::SpendingKey &sk)
88 {
89     LOCK(cs_SpendingKeyStore);
90     auto address = sk.address();
91     mapSpendingKeys[address] = sk;
92     mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(sk.receiving_key())));
93     return true;
94 }
95
96 bool CBasicKeyStore::AddViewingKey(const libzcash::ViewingKey &vk)
97 {
98     LOCK(cs_SpendingKeyStore);
99     auto address = vk.address();
100     mapViewingKeys[address] = vk;
101     mapNoteDecryptors.insert(std::make_pair(address, ZCNoteDecryption(vk.sk_enc)));
102     return true;
103 }
104
105 bool CBasicKeyStore::RemoveViewingKey(const libzcash::ViewingKey &vk)
106 {
107     LOCK(cs_SpendingKeyStore);
108     mapViewingKeys.erase(vk.address());
109     return true;
110 }
111
112 bool CBasicKeyStore::HaveViewingKey(const libzcash::PaymentAddress &address) const
113 {
114     LOCK(cs_SpendingKeyStore);
115     return mapViewingKeys.count(address) > 0;
116 }
117
118 bool CBasicKeyStore::GetViewingKey(const libzcash::PaymentAddress &address,
119                                    libzcash::ViewingKey &vkOut) const
120 {
121     LOCK(cs_SpendingKeyStore);
122     ViewingKeyMap::const_iterator mi = mapViewingKeys.find(address);
123     if (mi != mapViewingKeys.end()) {
124         vkOut = mi->second;
125         return true;
126     }
127     return false;
128 }
This page took 0.030818 seconds and 4 git commands to generate.