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