Skip to content

Commit 735d6b5

Browse files
committed
Merge #16227: Refactor CWallet's inheritance chain
93ce4a0 Move WatchOnly stuff from SigningProvider to CWallet (Andrew Chow) 8f5b81e Remove CCryptoKeyStore and move all of it's functionality into CWallet (Andrew Chow) 37a79a4 Move various SigningProviders to signingprovider.{cpp,h} (Andrew Chow) 16f8096 Move KeyOriginInfo to its own header file (Andrew Chow) d9becff scripted-diff: rename CBasicKeyStore to FillableSigningProvider (Andrew Chow) a913e3f Move HaveKey static function from keystore to rpcwallet where it is used (Andrew Chow) c7797ec Remove CKeyStore and squash into CBasicKeyStore (Andrew Chow) 1b699a5 Add HaveKey and HaveCScript to SigningProvider (Andrew Chow) Pull request description: This PR compresses the `CWallet` chain of inheritance from 5 classes to 3 classes. `CBasicKeyStore` is renamed to `FillableSigningProvider` and some parts of it (the watchonly parts) are moved into `CWallet`. `CKeyStore` and `CCrypoKeyStore` are completely removed. `CKeyStore`'s `Have*` functions are moved into `SigningProvider` and the `Add*` moved into `FillableSigningProvider`, thus allowing it to go away entirely. `CCryptoKeyStore`'s functionality is moved into `CWallet`. The new inheritance chain is: ``` SigningProvider -> FillableSigningProvider -> CWallet ``` `SigningProvider` now is the class the provides keys and scripts and indicates whether keys and scripts are present. `FillableSigningProvider` allows keys and scripts to be added to the signing provider via `Add*` functions. `CWallet` handles all of the watchonly stuff (`AddWatchOnly`, `HaveWatchOnly`, `RemoveWatchOnly` which were previously in `CKeyStore`) and key encryption (previously in `CCryptoKeyStore`). Implements the 2nd [prerequisite](https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Class-Structure-Changes#cwallet-subclass-stack) from the wallet restructure. ACKs for top commit: Sjors: re-ACK 93ce4a0; it keeps `EncryptSecret`, `DecryptSecret` and `DecryptKey` in `wallet/crypter.cpp`, but makes them not static. It improves alphabetical includes, reorders some function definitions, fixes commit message, brings back lost code comment. instagibbs: utACK bitcoin/bitcoin@93ce4a0 Tree-SHA512: 393dfd0623ad2dac38395eb89b862424318d6072f0b7083c92a0d207fd032c48b284f5f2cb13bc492f34557de350c5fee925da02e47daf011c5c6930a721b6d3
2 parents 28d1353 + 93ce4a0 commit 735d6b5

36 files changed

+599
-602
lines changed

doc/developer-notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ reported in the debug.log file.
375375

376376
Re-architecting the core code so there are better-defined interfaces
377377
between the various components is a goal, with any necessary locking
378-
done by the components (e.g. see the self-contained `CBasicKeyStore` class
378+
done by the components (e.g. see the self-contained `FillableSigningProvider` class
379379
and its `cs_KeyStore` lock for example).
380380

381381
Threads

src/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ BITCOIN_CORE_H = \
143143
interfaces/wallet.h \
144144
key.h \
145145
key_io.h \
146-
keystore.h \
147146
dbwrapper.h \
148147
limitedmap.h \
149148
logging.h \
@@ -182,8 +181,10 @@ BITCOIN_CORE_H = \
182181
rpc/util.h \
183182
scheduler.h \
184183
script/descriptor.h \
184+
script/keyorigin.h \
185185
script/sigcache.h \
186186
script/sign.h \
187+
script/signingprovider.h \
187188
script/standard.h \
188189
shutdown.h \
189190
streams.h \
@@ -449,7 +450,6 @@ libbitcoin_common_a_SOURCES = \
449450
core_write.cpp \
450451
key.cpp \
451452
key_io.cpp \
452-
keystore.cpp \
453453
merkleblock.cpp \
454454
netaddress.cpp \
455455
netbase.cpp \
@@ -463,6 +463,7 @@ libbitcoin_common_a_SOURCES = \
463463
scheduler.cpp \
464464
script/descriptor.cpp \
465465
script/sign.cpp \
466+
script/signingprovider.cpp \
466467
script/standard.cpp \
467468
versionbitsinfo.cpp \
468469
warnings.cpp \

src/bench/ccoins_caching.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <bench/bench.h>
66
#include <coins.h>
77
#include <policy/policy.h>
8-
#include <wallet/crypter.h>
8+
#include <script/signingprovider.h>
99

1010
#include <vector>
1111

@@ -17,7 +17,7 @@
1717
// paid to a TX_PUBKEYHASH.
1818
//
1919
static std::vector<CMutableTransaction>
20-
SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
20+
SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet)
2121
{
2222
std::vector<CMutableTransaction> dummyTransactions;
2323
dummyTransactions.resize(2);
@@ -55,7 +55,7 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
5555
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
5656
static void CCoinsCaching(benchmark::State& state)
5757
{
58-
CBasicKeyStore keystore;
58+
FillableSigningProvider keystore;
5959
CCoinsView coinsDummy;
6060
CCoinsViewCache coins(&coinsDummy);
6161
std::vector<CMutableTransaction> dummyTransactions = SetupDummyInputs(keystore, coins);

src/bitcoin-tx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include <consensus/consensus.h>
1212
#include <core_io.h>
1313
#include <key_io.h>
14-
#include <keystore.h>
1514
#include <policy/policy.h>
1615
#include <policy/rbf.h>
1716
#include <primitives/transaction.h>
1817
#include <script/script.h>
1918
#include <script/sign.h>
19+
#include <script/signingprovider.h>
2020
#include <univalue.h>
2121
#include <util/rbf.h>
2222
#include <util/system.h>
@@ -557,7 +557,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
557557

558558
if (!registers.count("privatekeys"))
559559
throw std::runtime_error("privatekeys register variable must be set.");
560-
CBasicKeyStore tempKeystore;
560+
FillableSigningProvider tempKeystore;
561561
UniValue keysObj = registers["privatekeys"];
562562

563563
for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
@@ -631,7 +631,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
631631
}
632632
}
633633

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

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

src/interfaces/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class WalletImpl : public Wallet
478478
}
479479
std::unique_ptr<Handler> handleStatusChanged(StatusChangedFn fn) override
480480
{
481-
return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CCryptoKeyStore*) { fn(); }));
481+
return MakeHandler(m_wallet->NotifyStatusChanged.connect([fn](CWallet*) { fn(); }));
482482
}
483483
std::unique_ptr<Handler> handleAddressBookChanged(AddressBookChangedFn fn) override
484484
{

src/keystore.h

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/outputtype.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
#include <outputtype.h>
77

8-
#include <keystore.h>
98
#include <pubkey.h>
109
#include <script/script.h>
10+
#include <script/sign.h>
11+
#include <script/signingprovider.h>
1112
#include <script/standard.h>
1213

1314
#include <assert.h>
@@ -73,7 +74,7 @@ std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
7374
}
7475
}
7576

76-
CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript& script, OutputType type)
77+
CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script, OutputType type)
7778
{
7879
// Add script to keystore
7980
keystore.AddCScript(script);
@@ -98,4 +99,3 @@ CTxDestination AddAndGetDestinationForScript(CKeyStore& keystore, const CScript&
9899
default: assert(false);
99100
}
100101
}
101-

src/outputtype.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define BITCOIN_OUTPUTTYPE_H
88

99
#include <attributes.h>
10-
#include <keystore.h>
10+
#include <script/signingprovider.h>
1111
#include <script/standard.h>
1212

1313
#include <string>
@@ -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(FillableSigningProvider& keystore, const CScript& script, OutputType);
4848

4949
#endif // BITCOIN_OUTPUTTYPE_H
5050

src/psbt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <primitives/transaction.h>
1313
#include <pubkey.h>
1414
#include <script/sign.h>
15+
#include <script/signingprovider.h>
1516

1617
// Magic bytes
1718
static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff};

src/rpc/misc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static UniValue createmultisig(const JSONRPCRequest& request)
115115
}
116116

117117
// Construct using pay-to-script-hash:
118-
CBasicKeyStore keystore;
118+
FillableSigningProvider keystore;
119119
CScript inner;
120120
const CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, output_type, keystore, inner);
121121

0 commit comments

Comments
 (0)