From 1d11c7779384400831307d36e9c0249c129cf6b0 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Thu, 5 Aug 2021 20:11:46 +0530 Subject: [PATCH] bitcoin#14168: Remove ENABLE_WALLET from libbitcoin_server.a --- src/Makefile.am | 4 ++++ src/dummywallet.cpp | 47 +++++++++++++++++++++++++++++++++++++++ src/httprpc.cpp | 14 ++++++------ src/init.cpp | 39 -------------------------------- src/init.h | 3 --- src/wallet/init.cpp | 3 +++ src/walletinitinterface.h | 4 ++++ 7 files changed, 65 insertions(+), 49 deletions(-) create mode 100644 src/dummywallet.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 005bf76f5409cb..3be57a30e72315 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -402,6 +402,10 @@ libdash_server_a_SOURCES = \ versionbits.cpp \ $(BITCOIN_CORE_H) +if !ENABLE_WALLET +libdash_server_a_SOURCES += dummywallet.cpp +endif + if ENABLE_ZMQ libdash_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS) libdash_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp new file mode 100644 index 00000000000000..ee6a0b6de3c04d --- /dev/null +++ b/src/dummywallet.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include + +#include + +class DummyWalletInit : public WalletInitInterface { +public: + + bool HasWalletSupport() const override {return false;} + void AddWalletOptions() const override; + bool ParameterInteraction() const override {return true;} + void RegisterRPC(CRPCTable &) const override {} + bool Verify() const override {return true;} + bool Open() const override {LogPrintf("No wallet support compiled in!\n"); return true;} + void Start(CScheduler& scheduler) const override {} + void Flush() const override {} + void Stop() const override {} + void Close() const override {} + + // Dash Specific WalletInitInterface InitCoinJoinSettings + void AutoLockMasternodeCollaterals() const override {} + void InitCoinJoinSettings() const override {} + void InitKeePass() const override {} + bool InitAutoBackup() const override {return true;} +}; + +void DummyWalletInit::AddWalletOptions() const +{ + std::vector opts = {"-createwalletbackups=", "-disablewallet", "-instantsendnotify=", + "-keypool=", "-rescan=", "-salvagewallet", "-spendzeroconfchange", "-upgradewallet", + "-wallet=", "-walletbackupsdir=", "-walletbroadcast", "-walletdir=", + "-walletnotify=", "-zapwallettxes=", "-discardfee=", "-fallbackfee=", + "-mintxfee=", "-paytxfee=", "-txconfirmtarget=", "-hdseed=", "-mnemonic=", + "-mnemonicpassphrase=", "-usehd", "-keepass", "-keepassid=", "-keepasskey=", + "-keepassname=", "-keepassport=", "-enablecoinjoin", "-coinjoinamount=", + "-coinjoinautostart", "-coinjoindenomsgoal=", "-coinjoindenomshardcap=", "-coinjoinmultisession", + "-coinjoinrounds=", "-coinjoinsessions=", "-dblogsize=", "-flushwallet", "-privdb", + "-walletrejectlongchains"}; + gArgs.AddHiddenArgs(opts); +} + +const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); diff --git a/src/httprpc.cpp b/src/httprpc.cpp index e1e30de5536365..1b0d231b7aab5d 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -243,10 +244,9 @@ bool StartHTTPRPC() return false; RegisterHTTPHandler("/", true, HTTPReq_JSONRPC); -#ifdef ENABLE_WALLET - // ifdef can be removed once we switch to better endpoint support and API versioning - RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); -#endif + if (g_wallet_init_interface.HasWalletSupport()) { + RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); + } struct event_base* eventBase = EventBase(); assert(eventBase); httpRPCTimerInterface = MakeUnique(eventBase); @@ -263,9 +263,9 @@ void StopHTTPRPC() { LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n"); UnregisterHTTPHandler("/", true); -#ifdef ENABLE_WALLET - UnregisterHTTPHandler("/wallet/", false); -#endif + if (g_wallet_init_interface.HasWalletSupport()) { + UnregisterHTTPHandler("/wallet/", false); + } if (httpRPCTimerInterface) { RPCUnsetTimerInterface(httpRPCTimerInterface.get()); httpRPCTimerInterface.reset(); diff --git a/src/init.cpp b/src/init.cpp index e1b08bf252bc2b..cc1f7b2e14e8c1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -112,45 +112,6 @@ std::unique_ptr g_connman; std::unique_ptr peerLogic; std::unique_ptr g_banman; -#if !(ENABLE_WALLET) -class DummyWalletInit : public WalletInitInterface { -public: - - void AddWalletOptions() const override; - bool ParameterInteraction() const override {return true;} - void RegisterRPC(CRPCTable &) const override {} - bool Verify() const override {return true;} - bool Open() const override {LogPrintf("No wallet support compiled in!\n"); return true;} - void Start(CScheduler& scheduler) const override {} - void Flush() const override {} - void Stop() const override {} - void Close() const override {} - - // Dash Specific WalletInitInterface InitCoinJoinSettings - void AutoLockMasternodeCollaterals() const override {} - void InitCoinJoinSettings() const override {} - void InitKeePass() const override {} - bool InitAutoBackup() const override {return true;} -}; - -void DummyWalletInit::AddWalletOptions() const -{ - std::vector opts = {"-createwalletbackups=", "-disablewallet", "-instantsendnotify=", - "-keypool=", "-rescan=", "-salvagewallet", "-spendzeroconfchange", "-upgradewallet", - "-wallet=", "-walletbackupsdir=", "-walletbroadcast", "-walletdir=", - "-walletnotify=", "-zapwallettxes=", "-discardfee=", "-fallbackfee=", - "-mintxfee=", "-paytxfee=", "-txconfirmtarget=", "-hdseed=", "-mnemonic=", - "-mnemonicpassphrase=", "-usehd", "-keepass", "-keepassid=", "-keepasskey=", - "-keepassname=", "-keepassport=", "-enablecoinjoin", "-coinjoinamount=", - "-coinjoinautostart", "-coinjoindenomsgoal=", "-coinjoindenomshardcap=", "-coinjoinmultisession", - "-coinjoinrounds=", "-coinjoinsessions=", "-dblogsize=", "-flushwallet", "-privdb", - "-walletrejectlongchains"}; - gArgs.AddHiddenArgs(opts); -} - -const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); -#endif - static CDSNotificationInterface* pdsNotificationInterface = nullptr; #ifdef WIN32 diff --git a/src/init.h b/src/init.h index af11c36ae5ffd8..c87f6f60b76b55 100644 --- a/src/init.h +++ b/src/init.h @@ -13,9 +13,6 @@ class CScheduler; class CWallet; -class WalletInitInterface; -extern const WalletInitInterface& g_wallet_init_interface; - namespace boost { class thread_group; diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 1397b56679a63a..eec3396cfc6e2e 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -24,6 +24,9 @@ class WalletInit : public WalletInitInterface { public: + //! Was the wallet component compiled in. + bool HasWalletSupport() const override {return true;} + //! Return the wallets help message. void AddWalletOptions() const override; diff --git a/src/walletinitinterface.h b/src/walletinitinterface.h index daadeead9a7c6a..9dc76ccfb34814 100644 --- a/src/walletinitinterface.h +++ b/src/walletinitinterface.h @@ -12,6 +12,8 @@ class CRPCTable; class WalletInitInterface { public: + /** Is the wallet component enabled */ + virtual bool HasWalletSupport() const = 0; /** Get wallet help string */ virtual void AddWalletOptions() const = 0; /** Check wallet parameter interaction */ @@ -40,4 +42,6 @@ class WalletInitInterface { virtual ~WalletInitInterface() {} }; +extern const WalletInitInterface& g_wallet_init_interface; + #endif // BITCOIN_WALLETINITINTERFACE_H