]> Git Repo - VerusCoin.git/blob - src/keystore.cpp
Merge pull request #5505
[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 "crypter.h"
9 #include "key.h"
10 #include "script/script.h"
11 #include "script/standard.h"
12 #include "util.h"
13
14 #include <boost/foreach.hpp>
15
16 bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
17 {
18     CKey key;
19     if (!GetKey(address, key))
20         return false;
21     vchPubKeyOut = key.GetPubKey();
22     return true;
23 }
24
25 bool CKeyStore::AddKey(const CKey &key) {
26     return AddKeyPubKey(key, key.GetPubKey());
27 }
28
29 bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
30 {
31     LOCK(cs_KeyStore);
32     mapKeys[pubkey.GetID()] = key;
33     return true;
34 }
35
36 bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
37 {
38     if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
39         return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
40
41     LOCK(cs_KeyStore);
42     mapScripts[CScriptID(redeemScript)] = redeemScript;
43     return true;
44 }
45
46 bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
47 {
48     LOCK(cs_KeyStore);
49     return mapScripts.count(hash) > 0;
50 }
51
52 bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
53 {
54     LOCK(cs_KeyStore);
55     ScriptMap::const_iterator mi = mapScripts.find(hash);
56     if (mi != mapScripts.end())
57     {
58         redeemScriptOut = (*mi).second;
59         return true;
60     }
61     return false;
62 }
63
64 bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
65 {
66     LOCK(cs_KeyStore);
67     setWatchOnly.insert(dest);
68     return true;
69 }
70
71 bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
72 {
73     LOCK(cs_KeyStore);
74     setWatchOnly.erase(dest);
75     return true;
76 }
77
78 bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
79 {
80     LOCK(cs_KeyStore);
81     return setWatchOnly.count(dest) > 0;
82 }
83
84 bool CBasicKeyStore::HaveWatchOnly() const
85 {
86     LOCK(cs_KeyStore);
87     return (!setWatchOnly.empty());
88 }
This page took 0.028655 seconds and 4 git commands to generate.