Skip to content

Commit c7797ec

Browse files
committed
Remove CKeyStore and squash into CBasicKeyStore
1 parent 1b699a5 commit c7797ec

File tree

8 files changed

+31
-52
lines changed

8 files changed

+31
-52
lines changed

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
631631
}
632632
}
633633

634-
const CKeyStore& keystore = tempKeystore;
634+
const CBasicKeyStore& keystore = tempKeystore;
635635

636636
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
637637

src/keystore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool CBasicKeyStore::HaveWatchOnly() const
174174
return (!setWatchOnly.empty());
175175
}
176176

177-
CKeyID GetKeyForDestination(const CKeyStore& store, const CTxDestination& dest)
177+
CKeyID GetKeyForDestination(const CBasicKeyStore& store, const CTxDestination& dest)
178178
{
179179
// Only supports destinations which map to single public keys, i.e. P2PKH,
180180
// P2WPKH, and P2SH-P2WPKH.
@@ -197,7 +197,7 @@ CKeyID GetKeyForDestination(const CKeyStore& store, const CTxDestination& dest)
197197
return CKeyID();
198198
}
199199

200-
bool HaveKey(const CKeyStore& store, const CKey& key)
200+
bool HaveKey(const CBasicKeyStore& store, const CKey& key)
201201
{
202202
CKey key2;
203203
key2.Set(key.begin(), key.end(), !key.IsCompressed());

src/keystore.h

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,8 @@
1515

1616
#include <boost/signals2/signal.hpp>
1717

18-
/** A virtual base class for key stores */
19-
class CKeyStore : public SigningProvider
20-
{
21-
public:
22-
//! Add a key to the store.
23-
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey) =0;
24-
25-
//! Check whether a key corresponding to a given address is present in the store.
26-
virtual std::set<CKeyID> GetKeys() const =0;
27-
28-
//! Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
29-
virtual bool AddCScript(const CScript& redeemScript) =0;
30-
virtual std::set<CScriptID> GetCScripts() const =0;
31-
32-
//! Support for Watch-only addresses
33-
virtual bool AddWatchOnly(const CScript &dest) =0;
34-
virtual bool RemoveWatchOnly(const CScript &dest) =0;
35-
virtual bool HaveWatchOnly(const CScript &dest) const =0;
36-
virtual bool HaveWatchOnly() const =0;
37-
};
38-
3918
/** Basic key store, that keeps keys in an address->secret map */
40-
class CBasicKeyStore : public CKeyStore
19+
class CBasicKeyStore : public SigningProvider
4120
{
4221
protected:
4322
mutable CCriticalSection cs_KeyStore;
@@ -55,27 +34,27 @@ class CBasicKeyStore : public CKeyStore
5534
void ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_KeyStore);
5635

5736
public:
58-
bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey) override;
59-
bool AddKey(const CKey &key) { return AddKeyPubKey(key, key.GetPubKey()); }
60-
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
61-
bool HaveKey(const CKeyID &address) const override;
62-
std::set<CKeyID> GetKeys() const override;
63-
bool GetKey(const CKeyID &address, CKey &keyOut) const override;
64-
bool AddCScript(const CScript& redeemScript) override;
65-
bool HaveCScript(const CScriptID &hash) const override;
66-
std::set<CScriptID> GetCScripts() const override;
67-
bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
68-
69-
bool AddWatchOnly(const CScript &dest) override;
70-
bool RemoveWatchOnly(const CScript &dest) override;
71-
bool HaveWatchOnly(const CScript &dest) const override;
72-
bool HaveWatchOnly() const override;
37+
virtual bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey);
38+
virtual bool AddKey(const CKey &key) { return AddKeyPubKey(key, key.GetPubKey()); }
39+
virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
40+
virtual bool HaveKey(const CKeyID &address) const override;
41+
virtual std::set<CKeyID> GetKeys() const;
42+
virtual bool GetKey(const CKeyID &address, CKey &keyOut) const override;
43+
virtual bool AddCScript(const CScript& redeemScript);
44+
virtual bool HaveCScript(const CScriptID &hash) const override;
45+
virtual std::set<CScriptID> GetCScripts() const;
46+
virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const override;
47+
48+
virtual bool AddWatchOnly(const CScript &dest);
49+
virtual bool RemoveWatchOnly(const CScript &dest);
50+
virtual bool HaveWatchOnly(const CScript &dest) const;
51+
virtual bool HaveWatchOnly() const;
7352
};
7453

7554
/** Return the CKeyID of the key involved in a script (if there is a unique one). */
76-
CKeyID GetKeyForDestination(const CKeyStore& store, const CTxDestination& dest);
55+
CKeyID GetKeyForDestination(const CBasicKeyStore& store, const CTxDestination& dest);
7756

78-
/** Checks if a CKey is in the given CKeyStore compressed or otherwise*/
79-
bool HaveKey(const CKeyStore& store, const CKey& key);
57+
/** Checks if a CKey is in the given CBasicKeyStore compressed or otherwise*/
58+
bool HaveKey(const CBasicKeyStore& store, const CKey& key);
8059

8160
#endif // BITCOIN_KEYSTORE_H

src/outputtype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
7373
}
7474
}
7575

76-
CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript& script, OutputType type)
76+
CTxDestination AddAndGetDestinationForScript(CBasicKeyStore& keystore, const CScript& script, OutputType type)
7777
{
7878
// Add script to keystore
7979
keystore.AddCScript(script);

src/outputtype.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
4444
* This function will automatically add the script (and any other
4545
* necessary scripts) to the keystore.
4646
*/
47-
CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript& script, OutputType);
47+
CTxDestination AddAndGetDestinationForScript(CBasicKeyStore& keystore, const CScript& script, OutputType);
4848

4949
#endif // BITCOIN_OUTPUTTYPE_H
5050

src/rpc/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ CPubKey HexToPubKey(const std::string& hex_in)
131131
return vchPubKey;
132132
}
133133

134-
// Retrieves a public key for an address from the given CKeyStore
135-
CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in)
134+
// Retrieves a public key for an address from the given CBasicKeyStore
135+
CPubKey AddrToPubKey(CBasicKeyStore* const keystore, const std::string& addr_in)
136136
{
137137
CTxDestination dest = DecodeDestination(addr_in);
138138
if (!IsValidDestination(dest)) {
@@ -153,7 +153,7 @@ CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in)
153153
}
154154

155155
// Creates a multisig address from a given list of public keys, number of signatures required, and the address type
156-
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, CKeyStore& keystore, CScript& script_out)
156+
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, CBasicKeyStore& keystore, CScript& script_out)
157157
{
158158
// Gather public keys
159159
if (required < 1) {

src/rpc/util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <boost/variant.hpp>
2121

22-
class CKeyStore;
22+
class CBasicKeyStore;
2323
class CPubKey;
2424
class CScript;
2525
struct InitInterfaces;
@@ -72,8 +72,8 @@ extern std::string HelpExampleCli(const std::string& methodname, const std::stri
7272
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
7373

7474
CPubKey HexToPubKey(const std::string& hex_in);
75-
CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in);
76-
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, CKeyStore& keystore, CScript& script_out);
75+
CPubKey AddrToPubKey(CBasicKeyStore* const keystore, const std::string& addr_in);
76+
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, CBasicKeyStore& keystore, CScript& script_out);
7777

7878
UniValue DescribeAddress(const CTxDestination& dest);
7979

src/test/transaction_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(test_Get)
346346
BOOST_CHECK_EQUAL(coins.GetValueIn(CTransaction(t1)), (50+21+22)*CENT);
347347
}
348348

349-
static void CreateCreditAndSpend(const CKeyStore& keystore, const CScript& outscript, CTransactionRef& output, CMutableTransaction& input, bool success = true)
349+
static void CreateCreditAndSpend(const CBasicKeyStore& keystore, const CScript& outscript, CTransactionRef& output, CMutableTransaction& input, bool success = true)
350350
{
351351
CMutableTransaction outputm;
352352
outputm.nVersion = 1;

0 commit comments

Comments
 (0)