Skip to content

Commit 6ec78f1

Browse files
committed
wallet: Refactor g_wallet_init_interface to const reference
1 parent 1936125 commit 6ec78f1

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/init.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class DummyWalletInit : public WalletInitInterface {
8787
void Close() const override {}
8888
};
8989

90-
static DummyWalletInit g_dummy_wallet_init;
91-
WalletInitInterface* const g_wallet_init_interface = &g_dummy_wallet_init;
90+
const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
9291
#endif
9392

9493
#if ENABLE_ZMQ
@@ -204,7 +203,7 @@ void Shutdown()
204203
StopREST();
205204
StopRPC();
206205
StopHTTPServer();
207-
g_wallet_init_interface->Flush();
206+
g_wallet_init_interface.Flush();
208207
StopMapPort();
209208

210209
// Because these depend on each-other, we make sure that neither can be
@@ -262,7 +261,7 @@ void Shutdown()
262261
pcoinsdbview.reset();
263262
pblocktree.reset();
264263
}
265-
g_wallet_init_interface->Stop();
264+
g_wallet_init_interface.Stop();
266265

267266
#if ENABLE_ZMQ
268267
if (pzmqNotificationInterface) {
@@ -282,7 +281,7 @@ void Shutdown()
282281
UnregisterAllValidationInterfaces();
283282
GetMainSignals().UnregisterBackgroundSignalScheduler();
284283
GetMainSignals().UnregisterWithMempoolSignals(mempool);
285-
g_wallet_init_interface->Close();
284+
g_wallet_init_interface.Close();
286285
globalVerifyHandle.reset();
287286
ECC_Stop();
288287
LogPrintf("%s: done\n", __func__);
@@ -425,7 +424,7 @@ std::string HelpMessage(HelpMessageMode mode)
425424
strUsage += HelpMessageOpt("-whitelist=<IP address or network>", _("Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) or CIDR notated network (e.g. 1.2.3.0/24). Can be specified multiple times.") +
426425
" " + _("Whitelisted peers cannot be DoS banned and their transactions are always relayed, even if they are already in the mempool, useful e.g. for a gateway"));
427426

428-
strUsage += g_wallet_init_interface->GetHelpString(showDebug);
427+
strUsage += g_wallet_init_interface.GetHelpString(showDebug);
429428

430429
#if ENABLE_ZMQ
431430
strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
@@ -1093,7 +1092,7 @@ bool AppInitParameterInteraction()
10931092
return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
10941093
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp);
10951094

1096-
if (!g_wallet_init_interface->ParameterInteraction()) return false;
1095+
if (!g_wallet_init_interface.ParameterInteraction()) return false;
10971096

10981097
fIsBareMultisigStd = gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
10991098
fAcceptDatacarrier = gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
@@ -1259,7 +1258,7 @@ bool AppInitMain()
12591258
* available in the GUI RPC console even if external calls are disabled.
12601259
*/
12611260
RegisterAllCoreRPCCommands(tableRPC);
1262-
g_wallet_init_interface->RegisterRPC(tableRPC);
1261+
g_wallet_init_interface.RegisterRPC(tableRPC);
12631262

12641263
/* Start the RPC server already. It will be started in "warmup" mode
12651264
* and not really process calls already (but it will signify connections
@@ -1276,7 +1275,7 @@ bool AppInitMain()
12761275
int64_t nStart;
12771276

12781277
// ********************************************************* Step 5: verify wallet database integrity
1279-
if (!g_wallet_init_interface->Verify()) return false;
1278+
if (!g_wallet_init_interface.Verify()) return false;
12801279

12811280
// ********************************************************* Step 6: network initialization
12821281
// Note that we absolutely cannot open any actual connections
@@ -1595,7 +1594,7 @@ bool AppInitMain()
15951594
fFeeEstimatesInitialized = true;
15961595

15971596
// ********************************************************* Step 8: load wallet
1598-
if (!g_wallet_init_interface->Open()) return false;
1597+
if (!g_wallet_init_interface.Open()) return false;
15991598

16001599
// ********************************************************* Step 9: data directory maintenance
16011600

@@ -1741,7 +1740,7 @@ bool AppInitMain()
17411740
SetRPCWarmupFinished();
17421741
uiInterface.InitMessage(_("Done loading"));
17431742

1744-
g_wallet_init_interface->Start(scheduler);
1743+
g_wallet_init_interface.Start(scheduler);
17451744

17461745
return true;
17471746
}

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 WalletInitInterface* const g_wallet_init_interface;
16+
extern const WalletInitInterface& g_wallet_init_interface;
1717

1818
namespace boost
1919
{

src/wallet/init.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class WalletInit : public WalletInitInterface {
4747
void Close() const override;
4848
};
4949

50-
static WalletInit g_wallet_init;
51-
WalletInitInterface* const g_wallet_init_interface = &g_wallet_init;
50+
const WalletInitInterface& g_wallet_init_interface = WalletInit();
5251

5352
std::string WalletInit::GetHelpString(bool showDebug) const
5453
{

0 commit comments

Comments
 (0)