]> Git Repo - VerusCoin.git/blame - src/keystore.cpp
Merge pull request #5898
[VerusCoin.git] / src / keystore.cpp
CommitLineData
b2120e22 1// Copyright (c) 2009-2010 Satoshi Nakamoto
f914f1a7 2// Copyright (c) 2009-2014 The Bitcoin Core developers
2b173d3b 3// Distributed under the MIT software license, see the accompanying
3a25a2b9 4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
e89b9f6a 5
ed6d0b5f 6#include "keystore.h"
51ed9ec9 7
51ed9ec9 8#include "key.h"
ad49c256 9#include "util.h"
e89b9f6a 10
51ed9ec9
BD
11#include <boost/foreach.hpp>
12
10254401 13bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
03fbd790
PW
14{
15 CKey key;
2ffba736 16 if (!GetKey(address, key))
03fbd790
PW
17 return false;
18 vchPubKeyOut = key.GetPubKey();
19 return true;
20}
21
dfa23b94
PW
22bool CKeyStore::AddKey(const CKey &key) {
23 return AddKeyPubKey(key, key.GetPubKey());
24}
25
26bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
e89b9f6a 27{
dfa23b94
PW
28 LOCK(cs_KeyStore);
29 mapKeys[pubkey.GetID()] = key;
acd65016
PW
30 return true;
31}
32
922e8e29 33bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
e679ec96 34{
787ee0c9 35 if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
5262fde0 36 return error("CBasicKeyStore::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
787ee0c9 37
dfa23b94 38 LOCK(cs_KeyStore);
066e2a14 39 mapScripts[CScriptID(redeemScript)] = redeemScript;
e679ec96
GA
40 return true;
41}
42
10254401 43bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const
e679ec96 44{
dfa23b94
PW
45 LOCK(cs_KeyStore);
46 return mapScripts.count(hash) > 0;
e679ec96
GA
47}
48
10254401 49bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const
e679ec96 50{
dfa23b94
PW
51 LOCK(cs_KeyStore);
52 ScriptMap::const_iterator mi = mapScripts.find(hash);
53 if (mi != mapScripts.end())
e679ec96 54 {
dfa23b94
PW
55 redeemScriptOut = (*mi).second;
56 return true;
e679ec96
GA
57 }
58 return false;
59}
60
d5087d1b 61bool CBasicKeyStore::AddWatchOnly(const CScript &dest)
c8988460
PW
62{
63 LOCK(cs_KeyStore);
64 setWatchOnly.insert(dest);
65 return true;
66}
67
ccca27a7
CL
68bool CBasicKeyStore::RemoveWatchOnly(const CScript &dest)
69{
70 LOCK(cs_KeyStore);
71 setWatchOnly.erase(dest);
72 return true;
73}
74
d5087d1b 75bool CBasicKeyStore::HaveWatchOnly(const CScript &dest) const
c8988460
PW
76{
77 LOCK(cs_KeyStore);
78 return setWatchOnly.count(dest) > 0;
79}
939ed973
CL
80
81bool CBasicKeyStore::HaveWatchOnly() const
82{
83 LOCK(cs_KeyStore);
84 return (!setWatchOnly.empty());
85}
This page took 0.155932 seconds and 4 git commands to generate.