diff options
-rw-r--r-- | src/init.cpp | 21 | ||||
-rw-r--r-- | src/wallet/init.cpp | 22 | ||||
-rw-r--r-- | src/wallet/init.h | 44 |
3 files changed, 46 insertions, 41 deletions
diff --git a/src/init.cpp b/src/init.cpp index 5c5d1ee792..8397932951 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -190,7 +190,7 @@ void Shutdown() StopRPC(); StopHTTPServer(); #ifdef ENABLE_WALLET - FlushWallets(); + WalletInit::Flush(); #endif StopMapPort(); @@ -250,7 +250,7 @@ void Shutdown() pblocktree.reset(); } #ifdef ENABLE_WALLET - StopWallets(); + WalletInit::Stop(); #endif #if ENABLE_ZMQ @@ -272,7 +272,7 @@ void Shutdown() GetMainSignals().UnregisterBackgroundSignalScheduler(); GetMainSignals().UnregisterWithMempoolSignals(mempool); #ifdef ENABLE_WALLET - CloseWallets(); + WalletInit::Close(); #endif globalVerifyHandle.reset(); ECC_Stop(); @@ -416,7 +416,7 @@ std::string HelpMessage(HelpMessageMode mode) " " + _("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")); #ifdef ENABLE_WALLET - strUsage += GetWalletHelpString(showDebug); + strUsage += WalletInit::GetHelpString(showDebug); #endif #if ENABLE_ZMQ @@ -1092,8 +1092,7 @@ bool AppInitParameterInteraction() nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); #ifdef ENABLE_WALLET - if (!WalletParameterInteraction()) - return false; + if (!WalletInit::ParameterInteraction()) return false; #endif fIsBareMultisigStd = gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); @@ -1258,7 +1257,7 @@ bool AppInitMain() */ RegisterAllCoreRPCCommands(tableRPC); #ifdef ENABLE_WALLET - RegisterWalletRPC(tableRPC); + WalletInit::RegisterRPC(tableRPC); #endif /* Start the RPC server already. It will be started in "warmup" mode @@ -1277,8 +1276,7 @@ bool AppInitMain() // ********************************************************* Step 5: verify wallet database integrity #ifdef ENABLE_WALLET - if (!VerifyWallets()) - return false; + if (!WalletInit::Verify()) return false; #endif // ********************************************************* Step 6: network initialization // Note that we absolutely cannot open any actual connections @@ -1598,8 +1596,7 @@ bool AppInitMain() // ********************************************************* Step 8: load wallet #ifdef ENABLE_WALLET - if (!OpenWallets()) - return false; + if (!WalletInit::Open()) return false; #else LogPrintf("No wallet support compiled in!\n"); #endif @@ -1749,7 +1746,7 @@ bool AppInitMain() uiInterface.InitMessage(_("Done loading")); #ifdef ENABLE_WALLET - StartWallets(scheduler); + WalletInit::Start(scheduler); #endif return true; diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 74036f4f0f..c271774b6b 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -13,7 +13,7 @@ #include <wallet/wallet.h> #include <wallet/walletutil.h> -std::string GetWalletHelpString(bool showDebug) +std::string WalletInit::GetHelpString(bool showDebug) { std::string strUsage = HelpMessageGroup(_("Wallet options:")); 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) return strUsage; } -bool WalletParameterInteraction() +bool WalletInit::ParameterInteraction() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { for (const std::string& wallet : gArgs.GetArgs("-wallet")) { @@ -192,7 +192,7 @@ bool WalletParameterInteraction() return true; } -void RegisterWalletRPC(CRPCTable &t) +void WalletInit::RegisterRPC(CRPCTable &t) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { return; @@ -201,7 +201,7 @@ void RegisterWalletRPC(CRPCTable &t) RegisterWalletRPCCommands(t); } -bool VerifyWallets() +bool WalletInit::Verify() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { return true; @@ -272,7 +272,7 @@ bool VerifyWallets() return true; } -bool OpenWallets() +bool WalletInit::Open() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { LogPrintf("Wallet disabled!\n"); @@ -290,25 +290,29 @@ bool OpenWallets() return true; } -void StartWallets(CScheduler& scheduler) { +void WalletInit::Start(CScheduler& scheduler) +{ for (CWalletRef pwallet : vpwallets) { pwallet->postInitProcess(scheduler); } } -void FlushWallets() { +void WalletInit::Flush() +{ for (CWalletRef pwallet : vpwallets) { pwallet->Flush(false); } } -void StopWallets() { +void WalletInit::Stop() +{ for (CWalletRef pwallet : vpwallets) { pwallet->Flush(true); } } -void CloseWallets() { +void WalletInit::Close() +{ for (CWalletRef pwallet : vpwallets) { delete pwallet; } diff --git a/src/wallet/init.h b/src/wallet/init.h index 0b3ee2dda2..e6c9ffb05b 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -11,33 +11,37 @@ class CRPCTable; class CScheduler; -//! Return the wallets help message. -std::string GetWalletHelpString(bool showDebug); +class WalletInit { +public: -//! Wallets parameter interaction -bool WalletParameterInteraction(); + //! Return the wallets help message. + static std::string GetHelpString(bool showDebug); -//! Register wallet RPCs. -void RegisterWalletRPC(CRPCTable &tableRPC); + //! Wallets parameter interaction + static bool ParameterInteraction(); -//! Responsible for reading and validating the -wallet arguments and verifying the wallet database. -// This function will perform salvage on the wallet if requested, as long as only one wallet is -// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). -bool VerifyWallets(); + //! Register wallet RPCs. + static void RegisterRPC(CRPCTable &tableRPC); -//! Load wallet databases. -bool OpenWallets(); + //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. + // This function will perform salvage on the wallet if requested, as long as only one wallet is + // being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). + static bool Verify(); -//! Complete startup of wallets. -void StartWallets(CScheduler& scheduler); + //! Load wallet databases. + static bool Open(); -//! Flush all wallets in preparation for shutdown. -void FlushWallets(); + //! Complete startup of wallets. + static void Start(CScheduler& scheduler); -//! Stop all wallets. Wallets will be flushed first. -void StopWallets(); + //! Flush all wallets in preparation for shutdown. + static void Flush(); -//! Close all wallets. -void CloseWallets(); + //! Stop all wallets. Wallets will be flushed first. + static void Stop(); + + //! Close all wallets. + static void Close(); +}; #endif // BITCOIN_WALLET_INIT_H |