Skip to content

Commit 9abdb7c

Browse files
committed
Merge #12836: Make WalletInitInterface and DummyWalletInit private, fix nullptr deref
d894894 wallet: Refactor to WalletInitInterface* const g_wallet_init_interface (João Barbosa) 39bc2fa wallet: Make WalletInitInterface and DummyWalletInit private (João Barbosa) Pull request description: Implementations of `WalletInitInterface` don't have to be public, so make them private. This makes the interface instantiation static. Also reduces `ENABLE_WALLET` usage and removes the unnecessary `src/wallet/init.h` header. Tree-SHA512: 203c49d8c85252d1bd0ff1d7ed8bcdc842d12d2d396e965cc70be5c8159a62e98ec23d32d2f3dc48a53e575844130d0a7dedac3cc2fe4621d31319b7a1c9ba89
2 parents 5f0c6a7 + d894894 commit 9abdb7c

File tree

10 files changed

+58
-87
lines changed

10 files changed

+58
-87
lines changed

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ BITCOIN_CORE_H = \
172172
wallet/db.h \
173173
wallet/feebumper.h \
174174
wallet/fees.h \
175-
wallet/init.h \
176175
wallet/rpcwallet.h \
177176
wallet/wallet.h \
178177
wallet/walletdb.h \

src/bitcoind.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
#include <httpserver.h>
1919
#include <httprpc.h>
2020
#include <utilstrencodings.h>
21-
#if ENABLE_WALLET
22-
#include <wallet/init.h>
23-
#endif
2421
#include <walletinitinterface.h>
2522

2623
#include <boost/thread.hpp>
@@ -63,12 +60,6 @@ bool AppInit(int argc, char* argv[])
6360
{
6461
bool fRet = false;
6562

66-
#if ENABLE_WALLET
67-
g_wallet_init_interface.reset(new WalletInit);
68-
#else
69-
g_wallet_init_interface.reset(new DummyWalletInit);
70-
#endif
71-
7263
//
7364
// Parameters
7465
//

src/init.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,25 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
7272

7373
std::unique_ptr<CConnman> g_connman;
7474
std::unique_ptr<PeerLogicValidation> peerLogic;
75-
std::unique_ptr<WalletInitInterface> g_wallet_init_interface;
75+
76+
#if !(ENABLE_WALLET)
77+
class DummyWalletInit : public WalletInitInterface {
78+
public:
79+
80+
std::string GetHelpString(bool showDebug) override {return std::string{};}
81+
bool ParameterInteraction() override {return true;}
82+
void RegisterRPC(CRPCTable &) override {}
83+
bool Verify() override {return true;}
84+
bool Open() override {return true;}
85+
void Start(CScheduler& scheduler) override {}
86+
void Flush() override {}
87+
void Stop() override {}
88+
void Close() override {}
89+
};
90+
91+
static DummyWalletInit g_dummy_wallet_init;
92+
WalletInitInterface* const g_wallet_init_interface = &g_dummy_wallet_init;
93+
#endif
7694

7795
#if ENABLE_ZMQ
7896
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
@@ -266,7 +284,6 @@ void Shutdown()
266284
GetMainSignals().UnregisterBackgroundSignalScheduler();
267285
GetMainSignals().UnregisterWithMempoolSignals(mempool);
268286
g_wallet_init_interface->Close();
269-
g_wallet_init_interface.reset();
270287
globalVerifyHandle.reset();
271288
ECC_Stop();
272289
LogPrintf("%s: done\n", __func__);

src/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CScheduler;
1313
class CWallet;
1414

1515
class WalletInitInterface;
16-
extern std::unique_ptr<WalletInitInterface> g_wallet_init_interface;
16+
extern WalletInitInterface* const g_wallet_init_interface;
1717

1818
namespace boost
1919
{

src/qt/bitcoin.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
#include <util.h>
3636
#include <warnings.h>
3737

38-
#ifdef ENABLE_WALLET
39-
#include <wallet/init.h>
40-
#endif
4138
#include <walletinitinterface.h>
4239

4340
#include <memory>
@@ -660,11 +657,6 @@ int main(int argc, char *argv[])
660657
// Start up the payment server early, too, so impatient users that click on
661658
// bitcoin: links repeatedly have their payment requests routed to this process:
662659
app.createPaymentServer();
663-
664-
// Hook up the wallet init interface
665-
g_wallet_init_interface.reset(new WalletInit);
666-
#else
667-
g_wallet_init_interface.reset(new DummyWalletInit);
668660
#endif
669661

670662
/// 9. Main GUI initialization

src/wallet/init.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,53 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
#include <wallet/init.h>
7-
86
#include <chainparams.h>
7+
#include <init.h>
98
#include <net.h>
109
#include <util.h>
1110
#include <utilmoneystr.h>
1211
#include <validation.h>
12+
#include <walletinitinterface.h>
1313
#include <wallet/rpcwallet.h>
1414
#include <wallet/wallet.h>
1515
#include <wallet/walletutil.h>
1616

17+
class WalletInit : public WalletInitInterface {
18+
public:
19+
20+
//! Return the wallets help message.
21+
std::string GetHelpString(bool showDebug) override;
22+
23+
//! Wallets parameter interaction
24+
bool ParameterInteraction() override;
25+
26+
//! Register wallet RPCs.
27+
void RegisterRPC(CRPCTable &tableRPC) override;
28+
29+
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
30+
// This function will perform salvage on the wallet if requested, as long as only one wallet is
31+
// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
32+
bool Verify() override;
33+
34+
//! Load wallet databases.
35+
bool Open() override;
36+
37+
//! Complete startup of wallets.
38+
void Start(CScheduler& scheduler) override;
39+
40+
//! Flush all wallets in preparation for shutdown.
41+
void Flush() override;
42+
43+
//! Stop all wallets. Wallets will be flushed first.
44+
void Stop() override;
45+
46+
//! Close all wallets.
47+
void Close() override;
48+
};
49+
50+
static WalletInit g_wallet_init;
51+
WalletInitInterface* const g_wallet_init_interface = &g_wallet_init;
52+
1753
std::string WalletInit::GetHelpString(bool showDebug)
1854
{
1955
std::string strUsage = HelpMessageGroup(_("Wallet options:"));

src/wallet/init.h

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

src/wallet/rpcdump.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <key_io.h>
77
#include <rpc/safemode.h>
88
#include <rpc/server.h>
9-
#include <wallet/init.h>
109
#include <validation.h>
1110
#include <script/script.h>
1211
#include <script/standard.h>

src/wallet/wallet.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <consensus/consensus.h>
1313
#include <consensus/validation.h>
1414
#include <fs.h>
15-
#include <wallet/init.h>
1615
#include <key.h>
1716
#include <key_io.h>
1817
#include <keystore.h>

src/walletinitinterface.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,4 @@ class WalletInitInterface {
3434
virtual ~WalletInitInterface() {}
3535
};
3636

37-
class DummyWalletInit : public WalletInitInterface {
38-
public:
39-
40-
std::string GetHelpString(bool showDebug) override {return std::string{};}
41-
bool ParameterInteraction() override {return true;}
42-
void RegisterRPC(CRPCTable &) override {}
43-
bool Verify() override {return true;}
44-
bool Open() override {return true;}
45-
void Start(CScheduler& scheduler) override {}
46-
void Flush() override {}
47-
void Stop() override {}
48-
void Close() override {}
49-
};
50-
5137
#endif // BITCOIN_WALLETINITINTERFACE_H

0 commit comments

Comments
 (0)