mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
[wallet] Use global g_wallet_init_interface to init/destroy the wallet.
This commit creates a global g_wallet_init_interface, which is created in bitcoind and bitcoin-qt. g_wallet_init_interface is used to init and destroy the wallet. This removes the dependency from init.cpp on the wallet library.
This commit is contained in:
parent
caaf9722f3
commit
49baa4a462
@ -18,6 +18,10 @@
|
|||||||
#include <httpserver.h>
|
#include <httpserver.h>
|
||||||
#include <httprpc.h>
|
#include <httprpc.h>
|
||||||
#include <utilstrencodings.h>
|
#include <utilstrencodings.h>
|
||||||
|
#if ENABLE_WALLET
|
||||||
|
#include <wallet/init.h>
|
||||||
|
#include <walletinitinterface.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
|
|
||||||
@ -59,6 +63,10 @@ bool AppInit(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
bool fRet = false;
|
bool fRet = false;
|
||||||
|
|
||||||
|
#if ENABLE_WALLET
|
||||||
|
g_wallet_init_interface.reset(new WalletInit);
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Parameters
|
// Parameters
|
||||||
//
|
//
|
||||||
|
57
src/init.cpp
57
src/init.cpp
@ -43,10 +43,8 @@
|
|||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <utilmoneystr.h>
|
#include <utilmoneystr.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#ifdef ENABLE_WALLET
|
|
||||||
#include <wallet/init.h>
|
|
||||||
#endif
|
|
||||||
#include <warnings.h>
|
#include <warnings.h>
|
||||||
|
#include <walletinitinterface.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -74,6 +72,7 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
|||||||
|
|
||||||
std::unique_ptr<CConnman> g_connman;
|
std::unique_ptr<CConnman> g_connman;
|
||||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
std::unique_ptr<PeerLogicValidation> peerLogic;
|
||||||
|
std::unique_ptr<WalletInitInterface> g_wallet_init_interface;
|
||||||
|
|
||||||
#if ENABLE_ZMQ
|
#if ENABLE_ZMQ
|
||||||
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
|
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
|
||||||
@ -189,9 +188,9 @@ void Shutdown()
|
|||||||
StopREST();
|
StopREST();
|
||||||
StopRPC();
|
StopRPC();
|
||||||
StopHTTPServer();
|
StopHTTPServer();
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
WalletInit::Flush();
|
g_wallet_init_interface->Flush();
|
||||||
#endif
|
}
|
||||||
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
|
||||||
@ -249,9 +248,9 @@ void Shutdown()
|
|||||||
pcoinsdbview.reset();
|
pcoinsdbview.reset();
|
||||||
pblocktree.reset();
|
pblocktree.reset();
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
WalletInit::Stop();
|
g_wallet_init_interface->Stop();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#if ENABLE_ZMQ
|
#if ENABLE_ZMQ
|
||||||
if (pzmqNotificationInterface) {
|
if (pzmqNotificationInterface) {
|
||||||
@ -271,9 +270,10 @@ void Shutdown()
|
|||||||
UnregisterAllValidationInterfaces();
|
UnregisterAllValidationInterfaces();
|
||||||
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
||||||
GetMainSignals().UnregisterWithMempoolSignals(mempool);
|
GetMainSignals().UnregisterWithMempoolSignals(mempool);
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
WalletInit::Close();
|
g_wallet_init_interface->Close();
|
||||||
#endif
|
}
|
||||||
|
g_wallet_init_interface.reset();
|
||||||
globalVerifyHandle.reset();
|
globalVerifyHandle.reset();
|
||||||
ECC_Stop();
|
ECC_Stop();
|
||||||
LogPrintf("%s: done\n", __func__);
|
LogPrintf("%s: done\n", __func__);
|
||||||
@ -415,9 +415,9 @@ 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"));
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
strUsage += WalletInit::GetHelpString(showDebug);
|
strUsage += g_wallet_init_interface->GetHelpString(showDebug);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
#if ENABLE_ZMQ
|
#if ENABLE_ZMQ
|
||||||
strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
|
strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
|
||||||
@ -1091,9 +1091,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);
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface && !g_wallet_init_interface->ParameterInteraction()) return false;
|
||||||
if (!WalletInit::ParameterInteraction()) return false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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);
|
||||||
@ -1256,9 +1254,9 @@ 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);
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
WalletInit::RegisterRPC(tableRPC);
|
g_wallet_init_interface->RegisterRPC(tableRPC);
|
||||||
#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
|
||||||
* and not really process calls already (but it will signify connections
|
* and not really process calls already (but it will signify connections
|
||||||
@ -1275,9 +1273,8 @@ bool AppInitMain()
|
|||||||
int64_t nStart;
|
int64_t nStart;
|
||||||
|
|
||||||
// ********************************************************* Step 5: verify wallet database integrity
|
// ********************************************************* Step 5: verify wallet database integrity
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface && !g_wallet_init_interface->Verify()) return false;
|
||||||
if (!WalletInit::Verify()) return false;
|
|
||||||
#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
|
||||||
// until the very end ("start node") as the UTXO/block state
|
// until the very end ("start node") as the UTXO/block state
|
||||||
@ -1595,11 +1592,7 @@ bool AppInitMain()
|
|||||||
fFeeEstimatesInitialized = true;
|
fFeeEstimatesInitialized = true;
|
||||||
|
|
||||||
// ********************************************************* Step 8: load wallet
|
// ********************************************************* Step 8: load wallet
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface && !g_wallet_init_interface->Open()) return false;
|
||||||
if (!WalletInit::Open()) return false;
|
|
||||||
#else
|
|
||||||
LogPrintf("No wallet support compiled in!\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ********************************************************* Step 9: data directory maintenance
|
// ********************************************************* Step 9: data directory maintenance
|
||||||
|
|
||||||
@ -1745,9 +1738,9 @@ bool AppInitMain()
|
|||||||
SetRPCWarmupFinished();
|
SetRPCWarmupFinished();
|
||||||
uiInterface.InitMessage(_("Done loading"));
|
uiInterface.InitMessage(_("Done loading"));
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
if (g_wallet_init_interface) {
|
||||||
WalletInit::Start(scheduler);
|
g_wallet_init_interface->Start(scheduler);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,15 @@
|
|||||||
#ifndef BITCOIN_INIT_H
|
#ifndef BITCOIN_INIT_H
|
||||||
#define BITCOIN_INIT_H
|
#define BITCOIN_INIT_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
|
|
||||||
|
class WalletInitInterface;
|
||||||
|
extern std::unique_ptr<WalletInitInterface> g_wallet_init_interface;
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
class thread_group;
|
class thread_group;
|
||||||
|
@ -33,7 +33,9 @@
|
|||||||
#include <warnings.h>
|
#include <warnings.h>
|
||||||
|
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
|
#include <wallet/init.h>
|
||||||
#include <wallet/wallet.h>
|
#include <wallet/wallet.h>
|
||||||
|
#include <walletinitinterface.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -669,6 +671,9 @@ int main(int argc, char *argv[])
|
|||||||
// Start up the payment server early, too, so impatient users that click on
|
// Start up the payment server early, too, so impatient users that click on
|
||||||
// bitcoin: links repeatedly have their payment requests routed to this process:
|
// bitcoin: links repeatedly have their payment requests routed to this process:
|
||||||
app.createPaymentServer();
|
app.createPaymentServer();
|
||||||
|
|
||||||
|
// Hook up the wallet init interface
|
||||||
|
g_wallet_init_interface.reset(new WalletInit);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// 9. Main GUI initialization
|
/// 9. Main GUI initialization
|
||||||
|
@ -6,42 +6,43 @@
|
|||||||
#ifndef BITCOIN_WALLET_INIT_H
|
#ifndef BITCOIN_WALLET_INIT_H
|
||||||
#define BITCOIN_WALLET_INIT_H
|
#define BITCOIN_WALLET_INIT_H
|
||||||
|
|
||||||
|
#include <walletinitinterface.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class CRPCTable;
|
class CRPCTable;
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
|
|
||||||
class WalletInit {
|
class WalletInit : public WalletInitInterface {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! Return the wallets help message.
|
//! Return the wallets help message.
|
||||||
static std::string GetHelpString(bool showDebug);
|
std::string GetHelpString(bool showDebug) override;
|
||||||
|
|
||||||
//! Wallets parameter interaction
|
//! Wallets parameter interaction
|
||||||
static bool ParameterInteraction();
|
bool ParameterInteraction() override;
|
||||||
|
|
||||||
//! Register wallet RPCs.
|
//! Register wallet RPCs.
|
||||||
static void RegisterRPC(CRPCTable &tableRPC);
|
void RegisterRPC(CRPCTable &tableRPC) 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).
|
||||||
static bool Verify();
|
bool Verify() override;
|
||||||
|
|
||||||
//! Load wallet databases.
|
//! Load wallet databases.
|
||||||
static bool Open();
|
bool Open() override;
|
||||||
|
|
||||||
//! Complete startup of wallets.
|
//! Complete startup of wallets.
|
||||||
static void Start(CScheduler& scheduler);
|
void Start(CScheduler& scheduler) override;
|
||||||
|
|
||||||
//! Flush all wallets in preparation for shutdown.
|
//! Flush all wallets in preparation for shutdown.
|
||||||
static void Flush();
|
void Flush() override;
|
||||||
|
|
||||||
//! Stop all wallets. Wallets will be flushed first.
|
//! Stop all wallets. Wallets will be flushed first.
|
||||||
static void Stop();
|
void Stop() override;
|
||||||
|
|
||||||
//! Close all wallets.
|
//! Close all wallets.
|
||||||
static void Close();
|
void Close() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_WALLET_INIT_H
|
#endif // BITCOIN_WALLET_INIT_H
|
||||||
|
Loading…
Reference in New Issue
Block a user