diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -46,7 +46,6 @@ #ifdef ENABLE_WALLET #include "wallet/init.h" #include "wallet/rpcdump.h" -#include "wallet/wallet.h" #endif #include "warnings.h" @@ -191,9 +190,7 @@ StopRPC(); StopHTTPServer(); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->Flush(false); - } + FlushWallets(); #endif StopMapPort(); @@ -250,9 +247,7 @@ pblocktree.reset(); } #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->Flush(true); - } + StopWallets(); #endif #if ENABLE_ZMQ @@ -273,10 +268,7 @@ UnregisterAllValidationInterfaces(); GetMainSignals().UnregisterBackgroundSignalScheduler(); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - delete pwallet; - } - vpwallets.clear(); + CloseWallets(); #endif globalVerifyHandle.reset(); ECC_Stop(); @@ -1580,7 +1572,7 @@ RegisterAllRPCCommands(config, rpcServer, tableRPC); #ifdef ENABLE_WALLET - RegisterWalletRPCCommands(tableRPC); + RegisterWalletRPC(tableRPC); RegisterDumpRPCCommands(tableRPC); #endif @@ -1817,7 +1809,7 @@ // Step 5: verify wallet database integrity #ifdef ENABLE_WALLET - if (!WalletVerify(chainparams)) { + if (!VerifyWallets(chainparams)) { return false; } #endif @@ -2205,7 +2197,7 @@ // Step 8: load wallet #ifdef ENABLE_WALLET - if (!InitLoadWallet(chainparams)) { + if (!OpenWallets(chainparams)) { return false; } #else @@ -2348,9 +2340,7 @@ uiInterface.InitMessage(_("Done loading")); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->postInitProcess(scheduler); - } + StartWallets(scheduler); #endif return !fRequestShutdown; diff --git a/src/wallet/init.h b/src/wallet/init.h --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -11,6 +11,9 @@ #include +class CRPCTable; +class CScheduler; + /** * Return the wallets help message. */ @@ -21,20 +24,37 @@ */ bool WalletParameterInteraction(); +/** + * Register wallet RPCs. + */ +void RegisterWalletRPC(CRPCTable &tableRPC); + /** * 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 (CWallet::ParameterInteraction forbids -salvagewallet, + * being loaded (WalletParameterInteraction forbids -salvagewallet, * -zapwallettxes or -upgradewallet with multiwallet). */ -bool WalletVerify(const CChainParams &chainParams); +bool VerifyWallets(const CChainParams &chainParams); /** * Load wallet databases. */ -bool InitLoadWallet(const CChainParams &chainParams); +bool OpenWallets(const CChainParams &chainParams); + +//! Complete startup of wallets. +void StartWallets(CScheduler &scheduler); + +//! Flush all wallets in preparation for shutdown. +void FlushWallets(); + +//! Stop all wallets. Wallets will be flushed first. +void StopWallets(); + +//! Close all wallets. +void CloseWallets(); #endif // BITCOIN_WALLET_INIT_H diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -11,6 +11,7 @@ #include "util.h" #include "utilmoneystr.h" #include "validation.h" +#include "wallet/rpcwallet.h" #include "wallet/wallet.h" std::string GetWalletHelpString(bool showDebug) { @@ -249,7 +250,15 @@ return true; } -bool WalletVerify(const CChainParams &chainParams) { +void RegisterWalletRPC(CRPCTable &t) { + if (gArgs.GetBoolArg("-disablewallet", false)) { + return; + } + + RegisterWalletRPCCommands(t); +} + +bool VerifyWallets(const CChainParams &chainParams) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { return true; } @@ -320,7 +329,7 @@ return true; } -bool InitLoadWallet(const CChainParams &chainParams) { +bool OpenWallets(const CChainParams &chainParams) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { LogPrintf("Wallet disabled!\n"); return true; @@ -337,3 +346,28 @@ return true; } + +void StartWallets(CScheduler &scheduler) { + for (CWalletRef pwallet : vpwallets) { + pwallet->postInitProcess(scheduler); + } +} + +void FlushWallets() { + for (CWalletRef pwallet : vpwallets) { + pwallet->Flush(false); + } +} + +void StopWallets() { + for (CWalletRef pwallet : vpwallets) { + pwallet->Flush(true); + } +} + +void CloseWallets() { + for (CWalletRef pwallet : vpwallets) { + delete pwallet; + } + vpwallets.clear(); +} diff --git a/src/wallet/rpcwallet.h b/src/wallet/rpcwallet.h --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -5,7 +5,10 @@ #ifndef BITCOIN_WALLET_RPCWALLET_H #define BITCOIN_WALLET_RPCWALLET_H +#include + class CRPCTable; +class CWallet; class JSONRPCRequest; class CWallet; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3695,10 +3695,6 @@ // clang-format on void RegisterWalletRPCCommands(CRPCTable &t) { - if (gArgs.GetBoolArg("-disablewallet", false)) { - return; - } - for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); }