mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
672beb2179
d0b9405f964670d6eaa8529f65fa7993b2a406c8 Refactors `keystore.h` type aliases. (251) Pull request description: This pull request frees `keystore.h` from type alias declarations that have been declared at file scope level. `keystore.h` has various type aliases that have been declared ~3 - 6 years ago at file scope level, which can either be encapsulated or removed. Where type alias declarations are encapsulated at the appropriate scope and access level, C++11's `using` notation is used in favor of the `typedef` notation. Tree-SHA512: 1395cdc63e0c7ff5a1b1721675ad4416f71f507e999bd4ba019f03457cbfc08877848f10a8db7f5ccd2cd5ca3f5a291c986616f7703172fb6d79fba7447ffba8
81 lines
3.0 KiB
C++
81 lines
3.0 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_KEYSTORE_H
|
|
#define BITCOIN_KEYSTORE_H
|
|
|
|
#include <hdchain.h>
|
|
#include <key.h>
|
|
#include <pubkey.h>
|
|
#include <script/script.h>
|
|
#include <script/sign.h>
|
|
#include <script/standard.h>
|
|
#include <sync.h>
|
|
|
|
#include <boost/signals2/signal.hpp>
|
|
|
|
/** A virtual base class for key stores */
|
|
class CKeyStore : public SigningProvider
|
|
{
|
|
public:
|
|
//! Add a key to the store.
|
|
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
|
|
|
|
//! Check whether a key corresponding to a given address is present in the store.
|
|
virtual bool HaveKey(const CKeyID &address) const =0;
|
|
virtual std::set<CKeyID> GetKeys() const =0;
|
|
|
|
//! Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
|
|
virtual bool AddCScript(const CScript& redeemScript) =0;
|
|
virtual bool HaveCScript(const CScriptID &hash) const =0;
|
|
virtual std::set<CScriptID> GetCScripts() const =0;
|
|
|
|
//! Support for Watch-only addresses
|
|
virtual bool AddWatchOnly(const CScript &dest) =0;
|
|
virtual bool RemoveWatchOnly(const CScript &dest) =0;
|
|
virtual bool HaveWatchOnly(const CScript &dest) const =0;
|
|
virtual bool HaveWatchOnly() const =0;
|
|
};
|
|
|
|
/** Basic key store, that keeps keys in an address->secret map */
|
|
class CBasicKeyStore : public CKeyStore
|
|
{
|
|
protected:
|
|
mutable CCriticalSection cs_KeyStore;
|
|
|
|
using KeyMap = std::map<CKeyID, CKey>;
|
|
using WatchKeyMap = std::map<CKeyID, CPubKey>;
|
|
using ScriptMap = std::map<CScriptID, CScript>;
|
|
using WatchOnlySet = std::set<CScript>;
|
|
|
|
KeyMap mapKeys GUARDED_BY(cs_KeyStore);
|
|
WatchKeyMap mapWatchKeys GUARDED_BY(cs_KeyStore);
|
|
ScriptMap mapScripts GUARDED_BY(cs_KeyStore);
|
|
WatchOnlySet setWatchOnly GUARDED_BY(cs_KeyStore);
|
|
/* the HD chain data model*/
|
|
CHDChain hdChain GUARDED_BY(cs_KeyStore);
|
|
|
|
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;
|
|
bool GetKey(const CKeyID &address, CKey &keyOut) const override;
|
|
bool AddCScript(const CScript& redeemScript) override;
|
|
bool HaveCScript(const CScriptID &hash) const override;
|
|
std::set<CScriptID> GetCScripts() const override;
|
|
bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
|
|
|
|
bool AddWatchOnly(const CScript &dest) override;
|
|
bool RemoveWatchOnly(const CScript &dest) override;
|
|
bool HaveWatchOnly(const CScript &dest) const override;
|
|
bool HaveWatchOnly() const override;
|
|
|
|
virtual bool GetHDChain(CHDChain& hdChainRet) const;
|
|
};
|
|
|
|
#endif // BITCOIN_KEYSTORE_H
|