From 3076556cd0317f7a05fd6836133dd6c051c4b53f Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 7 Sep 2018 12:35:42 -0400 Subject: [build] Move dummy wallet into its own .cpp file. Removes the ifdef ENABLE_WALLET from init.cpp. --- src/Makefile.am | 4 ++++ src/dummywallet.cpp | 32 ++++++++++++++++++++++++++++++++ src/init.cpp | 27 --------------------------- 3 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 src/dummywallet.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 3701ee8f3c..74855dd7a5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -260,6 +260,10 @@ libbitcoin_server_a_SOURCES = \ versionbits.cpp \ $(BITCOIN_CORE_H) +if !ENABLE_WALLET +libbitcoin_server_a_SOURCES += dummywallet.cpp +endif + if ENABLE_ZMQ libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS) libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp new file mode 100644 index 0000000000..164a4cbfd0 --- /dev/null +++ b/src/dummywallet.cpp @@ -0,0 +1,32 @@ +// 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 + +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 {} +}; + +void DummyWalletInit::AddWalletOptions() const +{ + std::vector opts = {"-addresstype", "-changetype", "-disablewallet", "-discardfee=", "-fallbackfee=", + "-keypool=", "-mintxfee=", "-paytxfee=", "-rescan", "-salvagewallet", "-spendzeroconfchange", "-txconfirmtarget=", + "-upgradewallet", "-wallet=", "-walletbroadcast", "-walletdir=", "-walletnotify=", "-walletrbf", "-zapwallettxes=", + "-dblogsize=", "-flushwallet", "-privdb", "-walletrejectlongchains"}; + gArgs.AddHiddenArgs(opts); +} + +const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); diff --git a/src/init.cpp b/src/init.cpp index 388e46eb6e..56789385d5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -74,33 +74,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; std::unique_ptr g_connman; std::unique_ptr peerLogic; -#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 {} -}; - -void DummyWalletInit::AddWalletOptions() const -{ - std::vector opts = {"-addresstype", "-changetype", "-disablewallet", "-discardfee=", "-fallbackfee=", - "-keypool=", "-mintxfee=", "-paytxfee=", "-rescan", "-salvagewallet", "-spendzeroconfchange", "-txconfirmtarget=", - "-upgradewallet", "-wallet=", "-walletbroadcast", "-walletdir=", "-walletnotify=", "-walletrbf", "-zapwallettxes=", - "-dblogsize=", "-flushwallet", "-privdb", "-walletrejectlongchains"}; - gArgs.AddHiddenArgs(opts); -} - -const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); -#endif - #ifdef WIN32 // Win32 LevelDB doesn't use filedescriptors, and the ones used for // accessing block files don't count towards the fd_set size limit -- cgit v1.2.3 From 7d038dcb41d93ea0b7401140998225adaab8c065 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 7 Sep 2018 12:36:53 -0400 Subject: [build] remove ENABLE_WALLET ifdef from httprpc.cpp --- src/dummywallet.cpp | 1 + src/httprpc.cpp | 14 +++++++------- src/init.h | 3 --- src/wallet/init.cpp | 3 +++ src/walletinitinterface.h | 4 ++++ 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp index 164a4cbfd0..5b33daf85d 100644 --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -9,6 +9,7 @@ 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 {} diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 38f6e79643..43d8c4cbbf 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -240,10 +241,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); @@ -260,9 +260,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.h b/src/init.h index 0c85d3c9dc..c58ba5cfd3 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 b36287ff50..a299a4ee44 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -19,6 +19,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 e955816162..6f12551273 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 */ @@ -34,4 +36,6 @@ public: virtual ~WalletInitInterface() {} }; +extern const WalletInitInterface& g_wallet_init_interface; + #endif // BITCOIN_WALLETINITINTERFACE_H -- cgit v1.2.3