Fabcoin Core  0.16.2
P2P Digital Currency
keystore.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 #ifndef FABCOIN_KEYSTORE_H
7 #define FABCOIN_KEYSTORE_H
8 
9 #include <key.h>
10 #include <pubkey.h>
11 #include <script/script.h>
12 #include <script/standard.h>
13 #include <sync.h>
14 
15 #include <boost/signals2/signal.hpp>
16 
18 class CKeyStore
19 {
20 protected:
22 
23 public:
24  virtual ~CKeyStore() {}
25 
27  virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
28  virtual bool AddKey(const CKey &key);
29 
31  virtual bool HaveKey(const CKeyID &address) const =0;
32  virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0;
33  virtual void GetKeys(std::set<CKeyID> &setAddress) const =0;
34  virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const =0;
35 
37  virtual bool AddCScript(const CScript& redeemScript) =0;
38  virtual bool HaveCScript(const CScriptID &hash) const =0;
39  virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const =0;
40 
42  virtual bool AddWatchOnly(const CScript &dest) =0;
43  virtual bool RemoveWatchOnly(const CScript &dest) =0;
44  virtual bool HaveWatchOnly(const CScript &dest) const =0;
45  virtual bool HaveWatchOnly() const =0;
46 };
47 
48 typedef std::map<CKeyID, CKey> KeyMap;
49 typedef std::map<CKeyID, CPubKey> WatchKeyMap;
50 typedef std::map<CScriptID, CScript > ScriptMap;
51 typedef std::set<CScript> WatchOnlySet;
52 
54 class CBasicKeyStore : public CKeyStore
55 {
56 protected:
61 
62 public:
63  bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
64  bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
65  bool HaveKey(const CKeyID &address) const override
66  {
67  bool result;
68  {
70  result = (mapKeys.count(address) > 0);
71  }
72  return result;
73  }
74  void GetKeys(std::set<CKeyID> &setAddress) const override
75  {
76  setAddress.clear();
77  {
79  KeyMap::const_iterator mi = mapKeys.begin();
80  while (mi != mapKeys.end())
81  {
82  setAddress.insert((*mi).first);
83  mi++;
84  }
85  }
86  }
87  bool GetKey(const CKeyID &address, CKey &keyOut) const override
88  {
89  {
91  KeyMap::const_iterator mi = mapKeys.find(address);
92  if (mi != mapKeys.end())
93  {
94  keyOut = mi->second;
95  return true;
96  }
97  }
98  return false;
99  }
100  virtual bool AddCScript(const CScript& redeemScript) override;
101  virtual bool HaveCScript(const CScriptID &hash) const override;
102  virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
103 
104  virtual bool AddWatchOnly(const CScript &dest) override;
105  virtual bool RemoveWatchOnly(const CScript &dest) override;
106  virtual bool HaveWatchOnly(const CScript &dest) const override;
107  virtual bool HaveWatchOnly() const override;
108 };
109 
110 typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
111 typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char> > > CryptedKeyMap;
112 
113 #endif // FABCOIN_KEYSTORE_H
CCriticalSection cs_KeyStore
Definition: keystore.h:21
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)=0
Add a key to the store.
void GetKeys(std::set< CKeyID > &setAddress) const override
Definition: keystore.h:74
std::map< CScriptID, CScript > ScriptMap
Definition: keystore.h:50
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
Definition: keystore.h:110
std::map< CKeyID, std::pair< CPubKey, std::vector< unsigned char > > > CryptedKeyMap
Definition: keystore.h:111
virtual bool AddWatchOnly(const CScript &dest)=0
Support for Watch-only addresses.
std::set< CScript > WatchOnlySet
Definition: keystore.h:51
virtual bool AddCScript(const CScript &redeemScript)=0
Support for BIP 0013 : see https://github.com/fabcoin/bips/blob/master/bip-0013.mediawiki.
virtual bool HaveCScript(const CScriptID &hash) const =0
WatchKeyMap mapWatchKeys
Definition: keystore.h:58
#define LOCK(cs)
Definition: sync.h:175
virtual bool HaveKey(const CKeyID &address) const =0
Check whether a key corresponding to a given address is present in the store.
An encapsulated public key.
Definition: pubkey.h:39
virtual bool RemoveWatchOnly(const CScript &dest)=0
ScriptMap mapScripts
Definition: keystore.h:59
std::map< CKeyID, CPubKey > WatchKeyMap
Definition: keystore.h:49
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const =0
WatchOnlySet setWatchOnly
Definition: keystore.h:60
bool GetKey(const CKeyID &address, CKey &keyOut) const override
Definition: keystore.h:87
virtual bool AddKey(const CKey &key)
Definition: keystore.cpp:12
virtual bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const =0
KeyMap mapKeys
Definition: keystore.h:57
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:417
virtual bool HaveWatchOnly() const =0
A virtual base class for key stores.
Definition: keystore.h:18
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
virtual ~CKeyStore()
Definition: keystore.h:24
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:28
virtual void GetKeys(std::set< CKeyID > &setAddress) const =0
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
An encapsulated private key.
Definition: key.h:35
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
Definition: keystore.h:65
std::map< CKeyID, CKey > KeyMap
Definition: keystore.h:48
Basic key store, that keeps keys in an address->secret map.
Definition: keystore.h:54
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:91
virtual bool GetCScript(const CScriptID &hash, CScript &redeemScriptOut) const =0