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
This commit is contained in:
Wladimir J. van der Laan 2018-03-27 20:42:09 +02:00
commit e49ba2e23b
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
3 changed files with 4 additions and 9 deletions

View File

@ -219,7 +219,7 @@ inconsistencies reported in the debug.log file.
Re-architecting the core code so there are better-defined interfaces
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).
Threads

View File

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

View File

@ -18,13 +18,9 @@
/** A virtual base class for key stores */
class CKeyStore : public SigningProvider
{
protected:
mutable CCriticalSection cs_KeyStore;
public:
//! Add a key to the store.
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.
virtual bool HaveKey(const CKeyID &address) const =0;
@ -51,6 +47,8 @@ typedef std::set<CScript> WatchOnlySet;
class CBasicKeyStore : public CKeyStore
{
protected:
mutable CCriticalSection cs_KeyStore;
KeyMap mapKeys;
WatchKeyMap mapWatchKeys;
ScriptMap mapScripts;
@ -60,6 +58,7 @@ protected:
public:
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 HaveKey(const CKeyID &address) const override;
std::set<CKeyID> GetKeys() const override;