Merge #12977: Refactor g_wallet_init_interface to const reference

6ec78f1 wallet: Refactor g_wallet_init_interface to const reference (João Barbosa)
1936125 wallet: Make WalletInitInterface members const (João Barbosa)

Pull request description:

Tree-SHA512: c382156a38d4c6beaa6c48f911d7b314542b9500d88724b2b3029dae4491cb1e60e10628f6632d1366818ccf343f494650b3171593b5450149544ba198f49bb5

additional

Signed-off-by: pasta <pasta@dashboost.org>
This commit is contained in:
Wladimir J. van der Laan 2018-04-17 15:57:52 +02:00 committed by pasta
parent c0caa8ab32
commit f70e8bebcd
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
4 changed files with 68 additions and 70 deletions

View File

@ -99,25 +99,24 @@ std::unique_ptr<PeerLogicValidation> peerLogic;
class DummyWalletInit : public WalletInitInterface { class DummyWalletInit : public WalletInitInterface {
public: public:
std::string GetHelpString(bool showDebug) override {return std::string{};} std::string GetHelpString(bool showDebug) const override {return std::string{};}
bool ParameterInteraction() override {return true;} bool ParameterInteraction() const override {return true;}
void RegisterRPC(CRPCTable &) override {} void RegisterRPC(CRPCTable &) const override {}
bool Verify() override {return true;} bool Verify() const override {return true;}
bool Open() override {return true;} bool Open() const override {return true;}
void Start(CScheduler& scheduler) override {} void Start(CScheduler& scheduler) const override {}
void Flush() override {} void Flush() const override {}
void Stop() override {} void Stop() const override {}
void Close() override {} void Close() const override {}
// Dash Specific WalletInitInterface InitPrivateSendSettings // Dash Specific WalletInitInterface InitPrivateSendSettings
void AutoLockMasternodeCollaterals() override {} void AutoLockMasternodeCollaterals() const override {}
void InitPrivateSendSettings() override {} void InitPrivateSendSettings() const override {}
void InitKeePass() override {} void InitKeePass() const override {}
bool InitAutoBackup() override {return true;} bool InitAutoBackup() const override {return true;}
}; };
static DummyWalletInit g_dummy_wallet_init; const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
WalletInitInterface* const g_wallet_init_interface = &g_dummy_wallet_init;
#endif #endif
static CDSNotificationInterface* pdsNotificationInterface = nullptr; static CDSNotificationInterface* pdsNotificationInterface = nullptr;
@ -244,7 +243,7 @@ void PrepareShutdown()
std::string statusmessage; std::string statusmessage;
bool fRPCInWarmup = RPCIsInWarmup(&statusmessage); bool fRPCInWarmup = RPCIsInWarmup(&statusmessage);
g_wallet_init_interface->Flush(); g_wallet_init_interface.Flush();
StopMapPort(); StopMapPort();
// Because these depend on each-other, we make sure that neither can be // Because these depend on each-other, we make sure that neither can be
@ -324,7 +323,7 @@ void PrepareShutdown()
deterministicMNManager.reset(); deterministicMNManager.reset();
evoDb.reset(); evoDb.reset();
} }
g_wallet_init_interface->Stop(); g_wallet_init_interface.Stop();
#if ENABLE_ZMQ #if ENABLE_ZMQ
if (g_zmq_notification_interface) { if (g_zmq_notification_interface) {
@ -375,7 +374,7 @@ void Shutdown()
PrepareShutdown(); PrepareShutdown();
} }
// Shutdown part 2: delete wallet instance // Shutdown part 2: delete wallet instance
g_wallet_init_interface->Close(); g_wallet_init_interface.Close();
globalVerifyHandle.reset(); globalVerifyHandle.reset();
ECC_Stop(); ECC_Stop();
LogPrintf("%s: done\n", __func__); LogPrintf("%s: done\n", __func__);
@ -546,7 +545,7 @@ std::string HelpMessage(HelpMessageMode mode)
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.") + 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.") +
" " + _("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"));
strUsage += g_wallet_init_interface->GetHelpString(showDebug); strUsage += g_wallet_init_interface.GetHelpString(showDebug);
#if ENABLE_ZMQ #if ENABLE_ZMQ
strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
@ -859,7 +858,7 @@ void ThreadImport(std::vector<fs::path> vImportFiles)
activeMasternodeManager->Init(pindexTip); activeMasternodeManager->Init(pindexTip);
} }
g_wallet_init_interface->AutoLockMasternodeCollaterals(); g_wallet_init_interface.AutoLockMasternodeCollaterals();
if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { if (gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
LoadMempool(); LoadMempool();
@ -1335,7 +1334,7 @@ bool AppInitParameterInteraction()
return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString())); return InitError(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.NetworkIDString()));
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp);
if (!g_wallet_init_interface->ParameterInteraction()) return false; if (!g_wallet_init_interface.ParameterInteraction()) return false;
fIsBareMultisigStd = gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); fIsBareMultisigStd = gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
fAcceptDatacarrier = gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); fAcceptDatacarrier = gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER);
@ -1671,7 +1670,7 @@ bool AppInitMain()
* available in the GUI RPC console even if external calls are disabled. * available in the GUI RPC console even if external calls are disabled.
*/ */
RegisterAllCoreRPCCommands(tableRPC); RegisterAllCoreRPCCommands(tableRPC);
g_wallet_init_interface->RegisterRPC(tableRPC); g_wallet_init_interface.RegisterRPC(tableRPC);
#if ENABLE_ZMQ #if ENABLE_ZMQ
RegisterZMQRPCCommands(tableRPC); RegisterZMQRPCCommands(tableRPC);
#endif #endif
@ -1690,11 +1689,11 @@ bool AppInitMain()
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity
if(!g_wallet_init_interface->InitAutoBackup()) return false; if (!g_wallet_init_interface.InitAutoBackup()) return false;
if (!g_wallet_init_interface->Verify()) return false; if (!g_wallet_init_interface.Verify()) return false;
// Initialize KeePass Integration // Initialize KeePass Integration
g_wallet_init_interface->InitKeePass(); g_wallet_init_interface.InitKeePass();
// ********************************************************* 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
// until the very end ("start node") as the UTXO/block state // until the very end ("start node") as the UTXO/block state
@ -2071,7 +2070,7 @@ bool AppInitMain()
fFeeEstimatesInitialized = true; fFeeEstimatesInitialized = true;
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet
if (!g_wallet_init_interface->Open()) return false; if (!g_wallet_init_interface.Open()) return false;
// As InitLoadWallet can take several minutes, it's possible the user // As InitLoadWallet can take several minutes, it's possible the user
// requested to kill the GUI during the last operation. If so, exit. // requested to kill the GUI during the last operation. If so, exit.
@ -2134,7 +2133,7 @@ bool AppInitMain()
// ********************************************************* Step 10b: setup PrivateSend // ********************************************************* Step 10b: setup PrivateSend
g_wallet_init_interface->InitPrivateSendSettings(); g_wallet_init_interface.InitPrivateSendSettings();
CPrivateSend::InitStandardDenominations(); CPrivateSend::InitStandardDenominations();
// ********************************************************* Step 10b: Load cache data // ********************************************************* Step 10b: Load cache data
@ -2352,7 +2351,7 @@ bool AppInitMain()
SetRPCWarmupFinished(); SetRPCWarmupFinished();
uiInterface.InitMessage(_("Done loading")); uiInterface.InitMessage(_("Done loading"));
g_wallet_init_interface->Start(scheduler); g_wallet_init_interface.Start(scheduler);
return true; return true;
} }

View File

@ -13,7 +13,7 @@ class CScheduler;
class CWallet; class CWallet;
class WalletInitInterface; class WalletInitInterface;
extern WalletInitInterface* const g_wallet_init_interface; extern const WalletInitInterface& g_wallet_init_interface;
namespace boost namespace boost
{ {

View File

@ -23,45 +23,44 @@ class WalletInit : public WalletInitInterface {
public: public:
//! Return the wallets help message. //! Return the wallets help message.
std::string GetHelpString(bool showDebug) override; std::string GetHelpString(bool showDebug) const override;
//! Wallets parameter interaction //! Wallets parameter interaction
bool ParameterInteraction() override; bool ParameterInteraction() const override;
//! Register wallet RPCs. //! Register wallet RPCs.
void RegisterRPC(CRPCTable &tableRPC) override; void RegisterRPC(CRPCTable &tableRPC) const override;
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database. //! 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 // 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). // being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
bool Verify() override; bool Verify() const override;
//! Load wallet databases. //! Load wallet databases.
bool Open() override; bool Open() const override;
//! Complete startup of wallets. //! Complete startup of wallets.
void Start(CScheduler& scheduler) override; void Start(CScheduler& scheduler) const override;
//! Flush all wallets in preparation for shutdown. //! Flush all wallets in preparation for shutdown.
void Flush() override; void Flush() const override;
//! Stop all wallets. Wallets will be flushed first. //! Stop all wallets. Wallets will be flushed first.
void Stop() override; void Stop() const override;
//! Close all wallets. //! Close all wallets.
void Close() override; void Close() const override;
// Dash Specific Wallet Init // Dash Specific Wallet Init
void AutoLockMasternodeCollaterals() override; void AutoLockMasternodeCollaterals() const override;
void InitPrivateSendSettings() override; void InitPrivateSendSettings() const override;
void InitKeePass() override; void InitKeePass() const override;
bool InitAutoBackup() override; bool InitAutoBackup() const override;
}; };
static WalletInit g_wallet_init; const WalletInitInterface& g_wallet_init_interface = WalletInit();
WalletInitInterface* const g_wallet_init_interface = &g_wallet_init;
std::string WalletInit::GetHelpString(bool showDebug) std::string WalletInit::GetHelpString(bool showDebug) const
{ {
std::string strUsage = HelpMessageGroup(_("Wallet options:")); std::string strUsage = HelpMessageGroup(_("Wallet options:"));
strUsage += HelpMessageOpt("-createwalletbackups=<n>", strprintf(_("Number of automatic wallet backups (default: %u)"), nWalletBackups)); strUsage += HelpMessageOpt("-createwalletbackups=<n>", strprintf(_("Number of automatic wallet backups (default: %u)"), nWalletBackups));
@ -127,7 +126,7 @@ std::string WalletInit::GetHelpString(bool showDebug)
return strUsage; return strUsage;
} }
bool WalletInit::ParameterInteraction() bool WalletInit::ParameterInteraction() const
{ {
if (gArgs.IsArgSet("-masternodeblsprivkey") && gArgs.SoftSetBoolArg("-disablewallet", true)) { if (gArgs.IsArgSet("-masternodeblsprivkey") && gArgs.SoftSetBoolArg("-disablewallet", true)) {
LogPrintf("%s: parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1\n", __func__); LogPrintf("%s: parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1\n", __func__);
@ -285,7 +284,7 @@ bool WalletInit::ParameterInteraction()
return true; return true;
} }
void WalletInit::RegisterRPC(CRPCTable &t) void WalletInit::RegisterRPC(CRPCTable &t) const
{ {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
return; return;
@ -294,7 +293,7 @@ void WalletInit::RegisterRPC(CRPCTable &t)
RegisterWalletRPCCommands(t); RegisterWalletRPCCommands(t);
} }
bool WalletInit::Verify() bool WalletInit::Verify() const
{ {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
return true; return true;
@ -343,7 +342,7 @@ bool WalletInit::Verify()
return true; return true;
} }
bool WalletInit::Open() bool WalletInit::Open() const
{ {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
LogPrintf("Wallet disabled!\n"); LogPrintf("Wallet disabled!\n");
@ -359,7 +358,7 @@ bool WalletInit::Open()
return true; return true;
} }
void WalletInit::Start(CScheduler& scheduler) void WalletInit::Start(CScheduler& scheduler) const
{ {
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
pwallet->postInitProcess(); pwallet->postInitProcess();
@ -373,7 +372,7 @@ void WalletInit::Start(CScheduler& scheduler)
} }
} }
void WalletInit::Flush() void WalletInit::Flush() const
{ {
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
if (CPrivateSendClientOptions::IsEnabled()) { if (CPrivateSendClientOptions::IsEnabled()) {
@ -386,14 +385,14 @@ void WalletInit::Flush()
} }
} }
void WalletInit::Stop() void WalletInit::Stop() const
{ {
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
pwallet->Flush(true); pwallet->Flush(true);
} }
} }
void WalletInit::Close() void WalletInit::Close() const
{ {
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
RemoveWallet(pwallet); RemoveWallet(pwallet);
@ -401,7 +400,7 @@ void WalletInit::Close()
} }
} }
void WalletInit::AutoLockMasternodeCollaterals() void WalletInit::AutoLockMasternodeCollaterals() const
{ {
// we can't do this before DIP3 is fully initialized // we can't do this before DIP3 is fully initialized
for (CWallet* pwallet : GetWallets()) { for (CWallet* pwallet : GetWallets()) {
@ -409,7 +408,7 @@ void WalletInit::AutoLockMasternodeCollaterals()
} }
} }
void WalletInit::InitPrivateSendSettings() void WalletInit::InitPrivateSendSettings() const
{ {
CPrivateSendClientOptions::SetEnabled(HasWallets() ? gArgs.GetBoolArg("-enableprivatesend", true) : false); CPrivateSendClientOptions::SetEnabled(HasWallets() ? gArgs.GetBoolArg("-enableprivatesend", true) : false);
if (!CPrivateSendClientOptions::IsEnabled()) { if (!CPrivateSendClientOptions::IsEnabled()) {
@ -431,12 +430,12 @@ void WalletInit::InitPrivateSendSettings()
CPrivateSendClientOptions::GetDenomsHardCap()); CPrivateSendClientOptions::GetDenomsHardCap());
} }
void WalletInit::InitKeePass() void WalletInit::InitKeePass() const
{ {
keePassInt.init(); keePassInt.init();
} }
bool WalletInit::InitAutoBackup() bool WalletInit::InitAutoBackup() const
{ {
return CWallet::InitAutoBackup(); return CWallet::InitAutoBackup();
} }

View File

@ -13,29 +13,29 @@ class CRPCTable;
class WalletInitInterface { class WalletInitInterface {
public: public:
/** Get wallet help string */ /** Get wallet help string */
virtual std::string GetHelpString(bool showDebug) = 0; virtual std::string GetHelpString(bool showDebug) const = 0;
/** Check wallet parameter interaction */ /** Check wallet parameter interaction */
virtual bool ParameterInteraction() = 0; virtual bool ParameterInteraction() const = 0;
/** Register wallet RPC*/ /** Register wallet RPC*/
virtual void RegisterRPC(CRPCTable &) = 0; virtual void RegisterRPC(CRPCTable &) const = 0;
/** Verify wallets */ /** Verify wallets */
virtual bool Verify() = 0; virtual bool Verify() const = 0;
/** Open wallets*/ /** Open wallets*/
virtual bool Open() = 0; virtual bool Open() const = 0;
/** Start wallets*/ /** Start wallets*/
virtual void Start(CScheduler& scheduler) = 0; virtual void Start(CScheduler& scheduler) const = 0;
/** Flush Wallets*/ /** Flush Wallets*/
virtual void Flush() = 0; virtual void Flush() const = 0;
/** Stop Wallets*/ /** Stop Wallets*/
virtual void Stop() = 0; virtual void Stop() const = 0;
/** Close wallets */ /** Close wallets */
virtual void Close() = 0; virtual void Close() const = 0;
// Dash Specific WalletInitInterface // Dash Specific WalletInitInterface
virtual void AutoLockMasternodeCollaterals() = 0; virtual void AutoLockMasternodeCollaterals() const = 0;
virtual void InitPrivateSendSettings() = 0; virtual void InitPrivateSendSettings() const = 0;
virtual void InitKeePass() = 0; virtual void InitKeePass() const = 0;
virtual bool InitAutoBackup() = 0; virtual bool InitAutoBackup() const = 0;
virtual ~WalletInitInterface() {} virtual ~WalletInitInterface() {}
}; };