Merge #12762: Make CKeyStore an interface

f381299 Move CKeyStore::cs_KeyStore to CBasicKeyStore (João Barbosa)
25eb9f5 Inline CKeyStore::AddKey(const CKey &) in CBasicKeyStore (João Barbosa)

Pull request description:

  Made these simplifications while reviewing #12714. This aims to make `CKeyStore` a *pure* interface:
   - no variable members - the mutex is moved to `CBasicKeyStore` which is where it is used;
   - no method implementations - `AddKey(const CKey &)` is moved to `CBasicKeyStore` which is where it is needed.

Tree-SHA512: 84e44f4390c59600e5cefa599b5464e1771c31dd4abc678ef50db8e06ffac778d692860a352918444f8bcd66430634637b6277a818a658721ffc4f381c1c6a90
pull/12711/merge
Wladimir J. van der Laan 7 years ago
commit e49ba2e23b
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D

@ -219,7 +219,7 @@ inconsistencies reported in the debug.log file.
Re-architecting the core code so there are better-defined interfaces Re-architecting the core code so there are better-defined interfaces
between the various components is a goal, with any necessary locking between the various components is a goal, with any necessary locking
done by the components (e.g. see the self-contained CKeyStore class done by the components (e.g. see the self-contained CBasicKeyStore class
and its cs_KeyStore lock for example). and its cs_KeyStore lock for example).
Threads Threads

@ -7,10 +7,6 @@
#include <util.h> #include <util.h>
bool CKeyStore::AddKey(const CKey &key) {
return AddKeyPubKey(key, key.GetPubKey());
}
void CBasicKeyStore::ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey) void CBasicKeyStore::ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey)
{ {
AssertLockHeld(cs_KeyStore); AssertLockHeld(cs_KeyStore);

@ -18,13 +18,9 @@
/** A virtual base class for key stores */ /** A virtual base class for key stores */
class CKeyStore : public SigningProvider class CKeyStore : public SigningProvider
{ {
protected:
mutable CCriticalSection cs_KeyStore;
public: public:
//! Add a key to the store. //! Add a key to the store.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0; virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
virtual bool AddKey(const CKey &key);
//! Check whether a key corresponding to a given address is present in the store. //! Check whether a key corresponding to a given address is present in the store.
virtual bool HaveKey(const CKeyID &address) const =0; virtual bool HaveKey(const CKeyID &address) const =0;
@ -51,6 +47,8 @@ typedef std::set<CScript> WatchOnlySet;
class CBasicKeyStore : public CKeyStore class CBasicKeyStore : public CKeyStore
{ {
protected: protected:
mutable CCriticalSection cs_KeyStore;
KeyMap mapKeys; KeyMap mapKeys;
WatchKeyMap mapWatchKeys; WatchKeyMap mapWatchKeys;
ScriptMap mapScripts; ScriptMap mapScripts;
@ -60,6 +58,7 @@ protected:
public: public:
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override; bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
bool AddKey(const CKey &key) { return AddKeyPubKey(key, key.GetPubKey()); }
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override; bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
bool HaveKey(const CKeyID &address) const override; bool HaveKey(const CKeyID &address) const override;
std::set<CKeyID> GetKeys() const override; std::set<CKeyID> GetKeys() const override;

Loading…
Cancel
Save