diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -684,7 +684,7 @@ } } - const CKeyStore &keystore = tempKeystore; + const CBasicKeyStore &keystore = tempKeystore; // Sign what we can: for (size_t i = 0; i < mergedTx.vin.size(); i++) { diff --git a/src/keystore.h b/src/keystore.h --- a/src/keystore.h +++ b/src/keystore.h @@ -15,33 +15,8 @@ #include -/** A virtual base class for key stores */ -class CKeyStore : public SigningProvider { -protected: - mutable RecursiveMutex cs_KeyStore; - -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 std::set 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 std::set 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 { +class CBasicKeyStore : public SigningProvider { protected: mutable RecursiveMutex cs_KeyStore; @@ -59,32 +34,36 @@ EXCLUSIVE_LOCKS_REQUIRED(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 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 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 AddKeyPubKey(const CKey &key, const CPubKey &pubkey); + virtual bool AddKey(const CKey &key) { + return AddKeyPubKey(key, key.GetPubKey()); + } + virtual bool GetPubKey(const CKeyID &address, + CPubKey &vchPubKeyOut) const override; + virtual bool HaveKey(const CKeyID &address) const override; + virtual std::set GetKeys() const; + virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override; + virtual bool AddCScript(const CScript &redeemScript); + virtual bool HaveCScript(const CScriptID &hash) const override; + virtual std::set GetCScripts() const; + virtual bool GetCScript(const CScriptID &hash, + CScript &redeemScriptOut) const override; + + virtual bool AddWatchOnly(const CScript &dest); + virtual bool RemoveWatchOnly(const CScript &dest); + virtual bool HaveWatchOnly(const CScript &dest) const; + virtual bool HaveWatchOnly() const; }; /** * Return the CKeyID of the key involved in a script (if there is a unique one). */ -CKeyID GetKeyForDestination(const CKeyStore &store, const CTxDestination &dest); +CKeyID GetKeyForDestination(const CBasicKeyStore &store, + const CTxDestination &dest); /** - * Checks if a CKey is in the given CKeyStore compressed or otherwise + * Checks if a CKey is in the given CBasicKeystore compressed or otherwise */ -bool HaveKey(const CKeyStore &store, const CKey &key); +bool HaveKey(const CBasicKeyStore &store, const CKey &key); #endif // BITCOIN_KEYSTORE_H diff --git a/src/keystore.cpp b/src/keystore.cpp --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -161,7 +161,7 @@ return (!setWatchOnly.empty()); } -CKeyID GetKeyForDestination(const CKeyStore &store, +CKeyID GetKeyForDestination(const CBasicKeyStore &store, const CTxDestination &dest) { // Only supports destinations which map to single public keys, i.e. P2PKH. if (auto id = boost::get(&dest)) { @@ -170,7 +170,7 @@ return CKeyID(); } -bool HaveKey(const CKeyStore &store, const CKey &key) { +bool HaveKey(const CBasicKeyStore &store, const CKey &key) { CKey key2; key2.Set(key.begin(), key.end(), !key.IsCompressed()); return store.HaveKey(key.GetPubKey().GetID()) || diff --git a/src/outputtype.h b/src/outputtype.h --- a/src/outputtype.h +++ b/src/outputtype.h @@ -42,7 +42,7 @@ * script. This function will automatically add the script (and any other * necessary scripts) to the keystore. */ -CTxDestination AddAndGetDestinationForScript(CKeyStore &keystore, +CTxDestination AddAndGetDestinationForScript(CBasicKeyStore &keystore, const CScript &script, OutputType); #endif // BITCOIN_OUTPUTTYPE_H diff --git a/src/outputtype.cpp b/src/outputtype.cpp --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -46,7 +46,7 @@ return std::vector{std::move(keyid)}; } -CTxDestination AddAndGetDestinationForScript(CKeyStore &keystore, +CTxDestination AddAndGetDestinationForScript(CBasicKeyStore &keystore, const CScript &script, OutputType type) { // Add script to keystore diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -19,7 +19,7 @@ #include class CChainParams; -class CKeyStore; +class CBasicKeyStore; class CPubKey; class CScript; class UniValue; @@ -72,12 +72,13 @@ const std::string &args); CPubKey HexToPubKey(const std::string &hex_in); -CPubKey AddrToPubKey(const CChainParams &chainparams, CKeyStore *const keystore, +CPubKey AddrToPubKey(const CChainParams &chainparams, + CBasicKeyStore *const keystore, const std::string &addr_in); CTxDestination AddAndGetMultisigDestination(const int required, const std::vector &pubkeys, OutputType type, - CKeyStore &keystore, + CBasicKeyStore &keystore, CScript &script_out); UniValue DescribeAddress(const CTxDestination &dest); diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -156,8 +156,9 @@ return vchPubKey; } -// Retrieves a public key for an address from the given CKeyStore -CPubKey AddrToPubKey(const CChainParams &chainparams, CKeyStore *const keystore, +// Retrieves a public key for an address from the given CBasicKeyStore +CPubKey AddrToPubKey(const CChainParams &chainparams, + CBasicKeyStore *const keystore, const std::string &addr_in) { CTxDestination dest = DecodeDestination(addr_in, chainparams); if (!IsValidDestination(dest)) { @@ -187,7 +188,7 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vector &pubkeys, OutputType type, - CKeyStore &keystore, + CBasicKeyStore &keystore, CScript &script_out) { // Gather public keys if (required < 1) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -342,7 +342,7 @@ (50 + 21 + 22) * CENT); } -static void CreateCreditAndSpend(const CKeyStore &keystore, +static void CreateCreditAndSpend(const CBasicKeyStore &keystore, const CScript &outscript, CTransactionRef &output, CMutableTransaction &input,