Skip to content

Commit 5fb5421

Browse files
committed
[wallet] Move wallet init functions into WalletInit class.
1 parent ffc6e48 commit 5fb5421

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/init.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void Shutdown()
190190
StopRPC();
191191
StopHTTPServer();
192192
#ifdef ENABLE_WALLET
193-
FlushWallets();
193+
WalletInit::Flush();
194194
#endif
195195
StopMapPort();
196196

@@ -250,7 +250,7 @@ void Shutdown()
250250
pblocktree.reset();
251251
}
252252
#ifdef ENABLE_WALLET
253-
StopWallets();
253+
WalletInit::Stop();
254254
#endif
255255

256256
#if ENABLE_ZMQ
@@ -272,7 +272,7 @@ void Shutdown()
272272
GetMainSignals().UnregisterBackgroundSignalScheduler();
273273
GetMainSignals().UnregisterWithMempoolSignals(mempool);
274274
#ifdef ENABLE_WALLET
275-
CloseWallets();
275+
WalletInit::Close();
276276
#endif
277277
globalVerifyHandle.reset();
278278
ECC_Stop();
@@ -416,7 +416,7 @@ std::string HelpMessage(HelpMessageMode mode)
416416
" " + _("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"));
417417

418418
#ifdef ENABLE_WALLET
419-
strUsage += GetWalletHelpString(showDebug);
419+
strUsage += WalletInit::GetHelpString(showDebug);
420420
#endif
421421

422422
#if ENABLE_ZMQ
@@ -1092,8 +1092,7 @@ bool AppInitParameterInteraction()
10921092
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp);
10931093

10941094
#ifdef ENABLE_WALLET
1095-
if (!WalletParameterInteraction())
1096-
return false;
1095+
if (!WalletInit::ParameterInteraction()) return false;
10971096
#endif
10981097

10991098
fIsBareMultisigStd = gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
@@ -1258,7 +1257,7 @@ bool AppInitMain()
12581257
*/
12591258
RegisterAllCoreRPCCommands(tableRPC);
12601259
#ifdef ENABLE_WALLET
1261-
RegisterWalletRPC(tableRPC);
1260+
WalletInit::RegisterRPC(tableRPC);
12621261
#endif
12631262

12641263
/* Start the RPC server already. It will be started in "warmup" mode
@@ -1277,8 +1276,7 @@ bool AppInitMain()
12771276

12781277
// ********************************************************* Step 5: verify wallet database integrity
12791278
#ifdef ENABLE_WALLET
1280-
if (!VerifyWallets())
1281-
return false;
1279+
if (!WalletInit::Verify()) return false;
12821280
#endif
12831281
// ********************************************************* Step 6: network initialization
12841282
// Note that we absolutely cannot open any actual connections
@@ -1598,8 +1596,7 @@ bool AppInitMain()
15981596

15991597
// ********************************************************* Step 8: load wallet
16001598
#ifdef ENABLE_WALLET
1601-
if (!OpenWallets())
1602-
return false;
1599+
if (!WalletInit::Open()) return false;
16031600
#else
16041601
LogPrintf("No wallet support compiled in!\n");
16051602
#endif
@@ -1749,7 +1746,7 @@ bool AppInitMain()
17491746
uiInterface.InitMessage(_("Done loading"));
17501747

17511748
#ifdef ENABLE_WALLET
1752-
StartWallets(scheduler);
1749+
WalletInit::Start(scheduler);
17531750
#endif
17541751

17551752
return true;

src/wallet/init.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <wallet/wallet.h>
1414
#include <wallet/walletutil.h>
1515

16-
std::string GetWalletHelpString(bool showDebug)
16+
std::string WalletInit::GetHelpString(bool showDebug)
1717
{
1818
std::string strUsage = HelpMessageGroup(_("Wallet options:"));
1919
strUsage += HelpMessageOpt("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(OUTPUT_TYPE_DEFAULT)));
@@ -55,7 +55,7 @@ std::string GetWalletHelpString(bool showDebug)
5555
return strUsage;
5656
}
5757

58-
bool WalletParameterInteraction()
58+
bool WalletInit::ParameterInteraction()
5959
{
6060
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
6161
for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
@@ -192,7 +192,7 @@ bool WalletParameterInteraction()
192192
return true;
193193
}
194194

195-
void RegisterWalletRPC(CRPCTable &t)
195+
void WalletInit::RegisterRPC(CRPCTable &t)
196196
{
197197
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
198198
return;
@@ -201,7 +201,7 @@ void RegisterWalletRPC(CRPCTable &t)
201201
RegisterWalletRPCCommands(t);
202202
}
203203

204-
bool VerifyWallets()
204+
bool WalletInit::Verify()
205205
{
206206
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
207207
return true;
@@ -272,7 +272,7 @@ bool VerifyWallets()
272272
return true;
273273
}
274274

275-
bool OpenWallets()
275+
bool WalletInit::Open()
276276
{
277277
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
278278
LogPrintf("Wallet disabled!\n");
@@ -290,25 +290,29 @@ bool OpenWallets()
290290
return true;
291291
}
292292

293-
void StartWallets(CScheduler& scheduler) {
293+
void WalletInit::Start(CScheduler& scheduler)
294+
{
294295
for (CWalletRef pwallet : vpwallets) {
295296
pwallet->postInitProcess(scheduler);
296297
}
297298
}
298299

299-
void FlushWallets() {
300+
void WalletInit::Flush()
301+
{
300302
for (CWalletRef pwallet : vpwallets) {
301303
pwallet->Flush(false);
302304
}
303305
}
304306

305-
void StopWallets() {
307+
void WalletInit::Stop()
308+
{
306309
for (CWalletRef pwallet : vpwallets) {
307310
pwallet->Flush(true);
308311
}
309312
}
310313

311-
void CloseWallets() {
314+
void WalletInit::Close()
315+
{
312316
for (CWalletRef pwallet : vpwallets) {
313317
delete pwallet;
314318
}

src/wallet/init.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,37 @@
1111
class CRPCTable;
1212
class CScheduler;
1313

14-
//! Return the wallets help message.
15-
std::string GetWalletHelpString(bool showDebug);
14+
class WalletInit {
15+
public:
1616

17-
//! Wallets parameter interaction
18-
bool WalletParameterInteraction();
17+
//! Return the wallets help message.
18+
static std::string GetHelpString(bool showDebug);
1919

20-
//! Register wallet RPCs.
21-
void RegisterWalletRPC(CRPCTable &tableRPC);
20+
//! Wallets parameter interaction
21+
static bool ParameterInteraction();
2222

23-
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
24-
// This function will perform salvage on the wallet if requested, as long as only one wallet is
25-
// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
26-
bool VerifyWallets();
23+
//! Register wallet RPCs.
24+
static void RegisterRPC(CRPCTable &tableRPC);
2725

28-
//! Load wallet databases.
29-
bool OpenWallets();
26+
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
27+
// This function will perform salvage on the wallet if requested, as long as only one wallet is
28+
// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
29+
static bool Verify();
3030

31-
//! Complete startup of wallets.
32-
void StartWallets(CScheduler& scheduler);
31+
//! Load wallet databases.
32+
static bool Open();
3333

34-
//! Flush all wallets in preparation for shutdown.
35-
void FlushWallets();
34+
//! Complete startup of wallets.
35+
static void Start(CScheduler& scheduler);
3636

37-
//! Stop all wallets. Wallets will be flushed first.
38-
void StopWallets();
37+
//! Flush all wallets in preparation for shutdown.
38+
static void Flush();
3939

40-
//! Close all wallets.
41-
void CloseWallets();
40+
//! Stop all wallets. Wallets will be flushed first.
41+
static void Stop();
42+
43+
//! Close all wallets.
44+
static void Close();
45+
};
4246

4347
#endif // BITCOIN_WALLET_INIT_H

0 commit comments

Comments
 (0)